标签:lvs-net
实验环境: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并配置三个虚拟主机
[root@s2 conf.d]# vi vhost.conf
<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>
[root@s2 conf.d]# vi ../conf/httpd.conf
Listen 81 Listen 82 Listen 80
二、安装ipvsadm并配置
[root@s2 ~]# yum install -y ipvsadm
[root@s2 ~]# ipvsadm -A -t 10.1.12.13:80 -s rr [root@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:80 -m [root@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:81 -m [root@s2 ~]# ipvsadm -a -t 10.1.12.13:80 -r 10.1.12.13:82 -m [root@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命令测试,是否为三个主页文件轮询调度。在浏览器上测试一般会有缓存,所以还是别踩坑了
本文出自 “传说中的猪” 博客,请务必保留此出处http://cszdz.blog.51cto.com/11892760/1879672
标签:lvs-net
原文地址:http://cszdz.blog.51cto.com/11892760/1879672