服务 -web服务器及ssh

2023-11-15

web服务器:

文件共享:
nfs samba:一般用于局域网中
ftp http:一般用于公网

tcp 80

httpd:

apache:
1、完全开源
2、跨平台
3、支持多种编程语言
4、采用模块化的设计
5、安全稳定

IE:www.taobao.com——>IP:port[path]——>apache——>client
    www.taobao.com——>apache——>php-cgi(模块)——>解析——>apache——>client


LAMP:Linux+apache+mysql+php
LNMP:Linux+ngix+mysql+php

httpd:rhel6.5 自带的

123、软三步曲
# rpm -q httpd
httpd-2.2.15-29.el6_4.x86_64
httpd-manual.noarch 帮助手册
中文的手册:
http://www.jinbuguo.com/apache/menu22/index.html

/var/www/html 静态页面的数据根目录
/var/log/httpd 日志文件目录
/var/run/httpd 进程目录
/usr/sbin/httpd 二进制命令
/usr/sbin/apachectl 官方的二进制命令
/etc/httpd 服务主目录
/etc/httpd/conf 配置文件的主目录
/etc/httpd/conf.d 子配置文件主目录
/etc/httpd/conf.d/README 说明书
/etc/httpd/conf.d/welcome.conf 欢迎页
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/logs 日志文件目录
/etc/httpd/modules 模块目录
/etc/httpd/run 进程目录
/etc/logrotate.d/httpd  日志轮转文件
/etc/rc.d/init.d/htcacheclean 官方的启动脚本
/etc/rc.d/init.d/httpd  红帽的启动脚本

4、了解配置文件

ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 60
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 15

Listen 80 默认端口
Include conf.d/*.conf 加载外部子目录
User apache  服务运行时的属主
Group apache  属组
ServerAdmin root@localhost  管理员邮箱

DocumentRoot "/var/www/html" 默认数据根目录
<Directory />  开始给“/”授权
    Options FollowSymLinks 支持软链接
    AllowOverride None 不支持.htaccess文件控制
</Directory>

<Directory "/var/www/html">
Options Indexes FollowSymLinks  支持索引和软链接
AllowOverride None
Order allow,deny 排序,先允许后拒绝
Allow from all 允许所有人访问
</Directory>

Alias /icons/ "/var/www/icons/"  定义别名

<Directory "/var/www/icons">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>


#<VirtualHost *:80>   定义虚拟主机
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

5、根据需求通过修改配置文件来完成服务的搭建
需求1:共享/data/下的所有文件
方法1:
mkdir /data
touch /data/file{1..5}

ln -s /data /var/www/html/notes

测试:
http://localhost/notes

方法2:通过别名方式共享
Alias /test/ "/data"
<Directory "/data">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

注意:别名后面的斜杠会影响访问,如果有,那么访问时必须加上

测试:
http://localhost/test/

需求2:访问一个静态网页文件
echo this is test page > /var/www/html/index.html

说明:
如果默认数据根目录里既有网页文件也有数据文件,优先去找网页文件;如果没有网页文件也不会看到数据文件,将welcome.conf注释掉就可以

需求3:自定义数据根目录
DocumentRoot "/webroot"
<Directory /webroot>
    Options FollowSymLinks Indexes
    AllowOverride None
</Directory>

课堂练习:
使用3种方式,发布你系统的/etc目录

需求4:基于用户名密码的访问控制
思路:
1、先去创建一个密码文件
2、配置文件里指定该密码文件

步骤:
1# htpasswd -cm /etc/httpd/conf/htpassword user1
New password: 
Re-type new password: 
Adding password for user user1
[root@node1 webroot]# cat /etc/httpd/conf/htpassword 
user1:$apr1$JBb9P6vF$Ozv.3JG4HL295yJaIL3iX1
[root@node1 webroot]# id user1
id: user1: No such user
[root@node1 webroot]# htpasswd -mb /etc/httpd/conf/htpassword user2 123
Adding password for user user2

2、
<Directory /webroot>  针对哪个数据目录做限制
    Options FollowSymLinks Indexes
    AllowOverride None
    AuthType Basic  开启基本认证
    AuthName "input your username&password:" 提示信息
    AuthBasicProvider file
    AuthUserFile /etc/httpd/conf/htpassword 指定密码文件
    Require user user1  允许用户
</Directory>

允许admin组里的所有成员访问该目录:
1、创建一个组文件(保存的是组成员及组名)
2、创建一个密码文件
3、修改配置文件

DocumentRoot "/webroot"
<Directory /webroot>
    Options FollowSymLinks Indexes
    AllowOverride None
    AuthType Basic
    AuthName "input your username&password:"
    AuthBasicProvider file
    AuthGroupFile /etc/httpd/conf/groups
    AuthUserFile /etc/httpd/conf/htpassword
    Require group admin
    #Require user user1 user2
    #Require valid-user
</Directory>

需求5:只允许10.1.1.2主机访问(网络的访问控制)
单独使用:
Allow from address
Deny from 205.252.46.165 
Deny from host.example.com
Deny from 192.101.205
Deny from cyberthugs.com moreidiots.com
组合使用:
Order deny,allow  先拒绝再允许;如果deny和allow冲突以allow为准
Deny from all
Allow from dev.example.com

Order allow,deny 先允许后拒绝;如果allow和deny冲突以deny为准

需求6:一台服务器上需要搭建多个web,怎么办?
方法1:
DocumentRoot /webroot

web1:/webroot/bbs/index.html
web2:/webroot/taobao/index.html

http://10.1.1.1/taobao

www.bbs.com ——>bbs web
www.taobao.org ——> taobao web

方法2:虚拟主机
基于IP的虚拟主机
10.1.1.1 ——>this is bbs page!
192.168.0.1——>this is taobao page!
步骤:
1、配置网卡2个ip
省略
2、创建虚拟主机
<VirtualHost 10.1.1.1:80>
    ServerAdmin root@.example.com
    DocumentRoot /www/bbs
   #ServerName dummy-host.example.com
    ErrorLog logs/bbs.example.com-error_log
    CustomLog logs/bbs.example.com-access_log common
</VirtualHost>
<VirtualHost 192.168.0.1:80>
    ServerAdmin root@.example.com
    DocumentRoot /www/taobao
    #ServerName dummy-host.example.com
    ErrorLog logs/taobao.example.com-error_log
    CustomLog logs/taobao.example.com-access_log common
</VirtualHost>

3、创建相应的数据目录及首页文件
# mkdir /www/{bbs,taobao} -p
[root@node1 conf]# cd /www/
[root@node1 www]# ll
total 8
drwxr-xr-x 2 root root 4096 Apr 28 15:21 bbs
drwxr-xr-x 2 root root 4096 Apr 28 15:21 taobao
[root@node1 www]# echo this is bbs page!> bbs/index.html
[root@node1 www]# echo this is taobao page!> taobao/index.html
4、重启服务
service httpd restart
5、测试验证
http://10.1.1.1
http://192.168.0.1

基于端口的虚拟主机
http://10.1.1.1:80——>this is 80 page!
http://10.1.1.1:8080——>this is 8080 page!

/webserver/80
/webserver/8080

<VirtualHost *:80>
    ServerAdmin root@.example.com
    DocumentRoot /webserver/80
   #ServerName dummy-host.example.com
    ErrorLog logs/80.example.com-error_log
    CustomLog logs/80.example.com-access_log common
</VirtualHost>
<VirtualHost *:8080>
    ServerAdmin root@.example.com
    DocumentRoot /webserver/8080
    #ServerName dummy-host.example.com
    ErrorLog logs/8080.example.com-error_log
    CustomLog logs/8080.example.com-access_log common
</VirtualHost>


基于域名的虚拟主机
www.bbs.com——>this is bbs webserver!
www.abc.net——>this is abc webserver!

环境:
webserver:vm1 10.1.1.1
dns:vm2 10.1.1.2
1、搭建dns服务器(vm2)
# cat bbs.com.zone 
$TTL 1D
@   IN SOA bbs.com. rname.invalid. (
                    0   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
@   NS  dns1.bbs.com.
dns1    A   10.1.1.2
www A   10.1.1.1

# cat abc.net.zone 
$TTL 1D
@   IN SOA abc.net. rname.invalid. (
                    0   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
@   NS  dns1.abc.net.
dns1    A   10.1.1.2
www A   10.1.1.1

2、发布虚拟主机(vm1)

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin root@.example.com
    DocumentRoot /webserver/bbs
    ServerName www.bbs.com
    ErrorLog logs/bbs.example.com-error_log
    CustomLog logs/bbs.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin root@.example.com
    DocumentRoot /webserver/abc
    ServerName www.abc.net
    ErrorLog logs/abc.example.com-error_log
    CustomLog logs/abc.example.com-access_log common
</VirtualHost>




作业11、通过2种方式发布你的系统/home目录
2、根据如下需求搭建web服务
http://ip/bbs——>this is bbs test page
http://ip/test——>this is test page
3、更改默认的数据根目录为/webserver
4、只允许sysadmin组里的user1用户去访问你的默认数据根目录,密码为123;同时拒绝10.1.1.0/24网段的所有人访问,除了10.1.1.254和你自己的ip

作业2:
搭建web服务器,要求如下:
1、访问不同的域名来访问不同的网页
http://www.zhangsan.net——>welcome to myweb!!!
http://www.test.org——>this is test page!
2、拒绝10.1.1.0/24网段和example.com这个域的所有主机访问www.zhangsan.net网站,但是允许harry用户访问
3、www.test.org网站的数据根目录为/web/www

扩展:
搭建qq农场,自己去找源码包


ssh服务: linux下远程管理工具 tcp 22号 
openssl(加密工具)
openssh-server

基于密钥对的加密方式:
dsa 对称的公钥加密算法,安全性相对较低,数据传输速度相对较快;使用同一个密钥进行加密和解密
rsa 非对称加密算法(ssh默认算法),安全性较高,数据传输速度相对较慢;用公钥加密和私钥解密,...

从客户端来讲,两种认证方式:
1、基于口令密码的认证(密码)
1> server端通过非对称加密方式产生一个公钥
2> client发起请求,server将公钥暴露给客户端
3> client获取公钥后,会产生一个由256位随机数组成的一个会话密钥(临时,口令)
4> client端通过公钥将会话口令进行加密发送给server端
5> server端拿者私钥进行解密,获取到会话密钥(口令)
6> client端和server端数据传输通过该口令进行对称加密

demo:
# ssh serverip ——> 提示输入server端的root密码
redhat$ ssh serverip ——>提示输入server端的redhat密码
# ssh -lusername serverip ——>提示输入server端指定的用户密码
# ssh -p port serverip ——>指定端口号登录
-l:
-p:


2、基于密钥对的认证(密钥认证)
1> client端需要产生一对密钥(公钥和私钥)
2> client端将自己的公钥远程传递到server端
3> client ——>ssh server——>server
   server找到client端的公钥匹配验证,一致,询问加密
   client拿着自己的私钥进行解密——>server确认登录



server:openssh-server

# rpm -qa|grep ^openssh
openssh-server-5.3p1-94.el6.x86_64  服务端
openssh-clients-5.3p1-94.el6.x86_64 客户端工具
openssh-5.3p1-94.el6.x86_64   工具包
openssh-askpass-5.3p1-94.el6.x86_64 基于gnome桌面的工具包


/etc/pam.d/ssh-keycat  
/etc/pam.d/sshd 认证文件
/etc/rc.d/init.d/sshd  启动脚本
/etc/ssh/sshd_config 主配置文件
/usr/sbin/sshd  二进制的命令


# rpm -ql openssh-clients
/etc/ssh/ssh_config  客户端配置文件
/usr/bin/.ssh.hmac
/usr/bin/scp 
/usr/bin/sftp
/usr/bin/slogin
/usr/bin/ssh
/usr/bin/ssh-add
/usr/bin/ssh-agent
/usr/bin/ssh-copy-id
/usr/bin/ssh-keyscan


了解配置文件:

demo1:更改服务的端口为10022
vim /etc/ssh/sshd_config
..
port 10022

demo2:不允许root用户登录

vim /etc/ssh/sshd_config
..
PermitRootLogin no

demo3:禁止使用空密码登录

PermitEmptyPasswords yes  代表允许空密码登录;no代表不允许


demo4:免密码登录
client:10.1.1.2
server:10.1.1.1
client:
1>生成一对密钥
# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0d:4f:84:3b:bb:b8:50:a2:03:49:fe:91:71:a0:73:ba root@node2.uplook.com
The key's randomart image is:
+--[ RSA 2048]----+
|   .     ..      |
|  . .   ..       |
| + o .  ...      |
|o.+ +   o=       |
|oo o. . Soo      |
| .o..o  .        |
| Eo..  . .       |
|   . .. .        |
|      ..         |
+-----------------+

2>将公钥远程传递给server端
# ssh-copy-id -i id_rsa.pub 10.1.1.1
The authenticity of host '10.1.1.1 (10.1.1.1)' can't be established.
RSA key fingerprint is eb:c0:3b:54:06:88:8b:ad:db:a0:a6:8c:74:56:b3:52.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.1.1.1' (RSA) to the list of known hosts.
root@10.1.1.1's password: 
Now try logging into the machine, with "ssh '10.1.1.1'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

或者
# scp -P10022 id_rsa.pub 10.1.1.1:/root/.ssh/authorized_keys
root@10.1.1.1's password: 

3>测试验证


作业3:
将ssh服务托管给xinetd服务管理
要求:
1、只允许10.1.1.0/24172.16.250.2使用ssh远程登录
2、不允许10.1.1.2访问
3、控制该服务最多只能3个连接,每个源ip只能1个连接
4、控制只能在900-1800才能远程登录
5、指定日志到/var/log/xinetd_ssh.log里
6、更改ssh服务的默认端口为10000


扩展:
自己参照man文档研究以下ssh服务的其他安全参数控制

总结:
基础服务:
文件共享:nfs、samba、ftp、http、tftp
nfs、samba——》client mount使用
ftp、http lftp ftp...

dns 

telnet ssh
client_》 telnet ssh

dhcp tftp
pxe:dhcp+tftp+nfs|ftp|http+dns..











本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

服务 -web服务器及ssh 的相关文章

  • element ui 多张图片上传、回显、删除

    element ui 多张图片上传 回显 删除 前端文件上传 1 展示部分
  • 计算机为什么负数不用减一,计算机的加减乘除(原码反码补码)

    计算机对数的操作 以二进制为基 因为电子原件只能表达0 1 开或关这两种状态 如果学过模电和数电 对此的理解会更深 比如说十进制9 在计算机里不可能单独记个9 而是记录成0000 1001 第一位符号位 0表示正数 但是 9 在计算机里记得
  • TensorRT部署神经网络

    TensorRT部署神经网络 大佬的讲解记录一下 基础知识 TensorRT使用例子 TensorRT加速模型 示例代码 这个脚本向你展示了如何使用 torch2trt 加速 pytorch 推理 截止目前为止 torch2trt 的适配能
  • swagger2 注解说明

    Api 用在请求的类上 表示对类的说明 tags 说明该类的作用 可以在UI界面上看到的注解 value 该参数没什么意义 在UI界面上也看到 所以不需要配置 ApiOperation 用在请求的方法上 说明方法的用途 作用 value 说
  • 如何用硬币模拟1/3的概率,以及任意概率?

    突然想起一个挺有意思的事 如何用硬币模拟1 3的概率 甚至任意概率 之前和朋友偶然间谈到如何用硬币模拟任何概率 当时以为是不可能的 因为硬币有两面 模拟的结果底数一定是2 n 今天又回顾了某个经典的条件概率问题 突然想到用硬币模拟任意概率是
  • IT职业发展路线

    网上找的

随机推荐

  • 第九课移动与相机

    讲的是shift 物体的移动轴 则摄像机与物体一起运动 设置了个聚光灯 本来要把聚光灯和摄像机锁定 但是不知为何 视频教程上的lock选项 在UE4编辑器没有 应该是版本不同的缘故
  • JS中document.createElement()用法及注意事项

    今天处理了一个日期选择器的ie和ff的兼容问题 本来这种情况就很难找错误 找了好久才把错误定位到js中创建元素的方法document createElement 这个方法在ie下支持这样创建元素 var inputObj document
  • Windows下开启Astra 摄像头的三种方式

    Windows下开启Astra摄像头有三种方式 第一种 使用官方提供的Orbbec Viewer软件 在此可以修改设备分辨率并且支持多台设备同时使用 非常方便 具体效果如下 该程序直接去奥比中光官网下载即可 官网也有具体的使用的手册 答主在
  • gcc compiler error messages

    Summarizing the gcc errors I encountered to be continued 1 dereferencing pointer to incomplete type You have written som
  • IP包流量分析程序

    使用套接字编程实现捕获一段时间内以本机为源地址或目的地址的IP数据包 不包括以广播形式发出的数据包 统计IP数据包的信息 列出本机与其他主机之间不同协议类型IP数据包的数量 及流量 以源地址 目的地址 协议类型 数据包数量 流量的格式输出统
  • failed to load response data出现的问题

    分片上传的时候 状态码请求是200的状态 但是 出现了 failed to load response data 没有response的返回 原因是 我分片的 每片大小太大了 分成了10M 所以出现了这个问题 const chunkSize
  • 【2-3】《Java基础语法》——二进制、变量、数据类型、标识符、数据类型转换、特殊变量定义、方法、运算符、变量作用域、编程规范、转义字符

    文章目录 基础语法 一 二进制 1 补码 2 二进制与十进制的转换 二 变量概述 三 数据类型 1 分类 2 范围 四 标识符 1 命名规则 2 Java中的关键字 3 定义变量 4 变量练习 五 数据类型转换 六 特殊变量定义 1 flo
  • nn.Module模块

    1 模块化接口nn torch nn是pytorch中专门为神经网络设计的模块化接口 nn构建于autograd之上 可以用来定义和运行神经网络 2 nn Module nn Module是nn中十分重要的类 包含网络各层的定义及forwa
  • 大神之路-起始篇

    欢迎关注 WeiyiGeek 公众号 点击 下方卡片 即可关注我哟 设为 星标 每天带你 基础入门 到 进阶实践 再到 放弃学习 涉及 网络安全运维 应用开发 物联网IOT 学习路径 个人感悟 等知识 花开堪折直须折 莫待无花空折枝 作者主
  • rocketMQ启动报错,JavaHotSpot(TM) 64-Bit Server VM warning错误: 找不到或无法加载主类 Files\jdk1.8.0_161\\jre\lib\ext

    Java HotSpot TM 64 Bit Server VM warning Using the DefNew young collector with the CMS collector is deprecated and will
  • foreach用法_R语言--并行计算包(parallel、foreach)

    R语言是单核计算语言 在数据建模或计算过程中 常常出现相同或相似任务的重复计算 一般操作是for循环处理或采用apply族函数处理 为了更快完成计算 采用并行计算是更优的选择 本文采用R语言中的parallel包与foreach包实现并行计
  • ueditor-后台配置项返回格式出错,上传功能将不能正常使用!

    一 服务器环境 php centos apache 二 症状 ueditor编辑界面可以显示 但单图片上传按钮点击没反应 多图片上传显示 后台配置项返回格式出错 上传功能将不能正常使用 三 分析 1 打开浏览器调试模式 显示 后台配置项返回
  • Zookeeper——zookeeper基础

    在深入了解ZooKeeper的运作之前 让我们来看看ZooKeeper的基本概念 我们将在本章中讨论以下主题 Architecture 架构 Hierarchical namespace 层次命名空间 Session 会话 Watches
  • 剑指 Offer 06. 从尾到头打印链表

    从尾到头打印链表 蠢想法 解题思路 的节点顺序已经反转过来了 栈 package swordPointingToTheOffer import java util Stack 引用栈 public class six 初始化 Stack
  • MessageBoxA的用法

    一 函数原型 int fastcall MessageBox const char Text const char Caption int Flags 0x0 Flags表示对话框的按钮组合 取值有 MessageBox Flags def
  • 虚拟地址内存空间

    bss段详解 详细讲解
  • 一个简单的HttpClient使用案例

    HttpClient 是什么 HttpClient 是Apache Jakarta Common 下的子项目 可以用来提供高效的 最新的 功能丰富的支持 HTTP 协议的客户端编程工具包 并且它支持 HTTP 协议最新的版本和建议 该如何使
  • Web3-js的学习(5)-实现合约事件监听

    合约事件监听 latest 监听最新出块事件 pending 监听发布未进块事件 代码很简单 var Web3 require web3 var web3 new Web3 new Web3 providers HttpProvider h
  • 解决在Intellij IDEA中无法创建Servlet类的问题/New中没有Servlet类/创建不了Servlet类

    新手在学习Servlet相关知识的时候 一些课程往往会告知新手去使用IDEA自带的模板来创建Servlet 这样减少了注解等麻烦 降低了工作量 然而 如下图所示 很多人发现在自己的new一栏不存在Servlet类 如下图 网上的解决办法很多
  • 服务 -web服务器及ssh

    web服务器 文件共享 nfs samba 一般用于局域网中 ftp http 一般用于公网 tcp 80 httpd apache 1 完全开源 2 跨平台 3 支持多种编程语言 4 采用模块化的设计 5 安全稳定 IE www taob