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 自带的
1、
2、
3、软三步曲
# 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>
作业1:
1、通过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/24和172.16.250.2使用ssh远程登录
2、不允许10.1.1.2访问
3、控制该服务最多只能3个连接,每个源ip只能1个连接
4、控制只能在9:00-18:00才能远程登录
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..
服务 -web服务器及ssh
最新推荐文章于 2024-08-10 14:00:53 发布