|
实验环境:centos 7
实验程序:httpd、ipvsadm
实验目的:在单台主机上用lvs做httpd基于端口的调度
IP | 端口 | 主页 |
| 10.1.12.13 | 80 | This is www1 |
| 10.1.12.13 | 81 | This is www2 |
| 10.1.12.13 | 82 | This is www3 |
| 一、安装httpd并配置三个虚拟主机
[iyunv@s2 conf.d]# vi vhost.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| <VirtualHost *:80>
ServerName www.blackCao.com
DocumentRoot "/vhost/www1"
<Directory "/vhost/www1">
Options none
AllowOverride none
Require all granted
</Directory>
CustomLog logs/www1_access.log combined
ErrorLog logs/www1_erroe.log
</VirtualHost>
#
#
<VirtualHost *:81>
ServerName www.blackCao.com
DocumentRoot "/vhost/www2"
<Directory "/vhost/www2">
Options none
AllowOverride none
Require all granted
</Directory>
CustomLog logs/www2_access.log combined
ErrorLog logs/www2_erroe.log
</VirtualHost>
#
#
<VirtualHost *:82>
ServerName www.blackCao.com
DocumentRoot "/vhost/www3"
<Directory "/vhost/www3">
Options none
AllowOverride none
Require all granted
</Directory>
CustomLog logs/www3_access.log combined
ErrorLog logs/www3_erroe.log
</VirtualHost>
|
[iyunv@s2 conf.d]# vi ../conf/httpd.conf
1
2
3
| Listen 81
Listen 82
Listen 80
|
二、安装ipvsadm并配置
1
| [iyunv@s2 ~]# yum install -y ipvsadm
|
1
2
3
4
5
6
7
8
9
10
| [iyunv@s2 ~]# ipvsadm -A -t 10.1.12.13:80 -s rr
[iyunv@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:80 -m
[iyunv@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:81 -m
[iyunv@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:82 -m
[iyunv@s2 ~]# ipvsadm -L -n
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.1.12.13:80 rr
-> 10.1.12.13:80 Masq 1 0 0
-> 10.1.12.13:81 Masq 1 0 0
-> 10.1.12.13:82 Masq 1 0 0
|
三、测试
启动http服务并查看端口监听状态,在别的虚拟主机上使用curl命令测试,是否为三个主页文件轮询调度。在浏览器上测试一般会有缓存,所以还是别踩坑了
|
|
|
|
|
|
|