Description: The client only requires the ability to access VIP can be.
A ready environment
1, open routing forwarding
[root@xuegod63 ~]# vim /etc/sysctl.conf
改:net.ipv4.ip_forward = 0
Is: is named net.ipv4.ip_forward and =. 1
Let configuration to take effect:
[root@xuegod63 ~]# sysctl -p
2, configure the network environment:
Add a network card (requires two network cards), configured to the following network environment:
eth0 192.168.1.63 mode: analog public network bridge
eth1 192.168.2.63 mode: the analog network within vmnet4
Second mounting: LVS management tools: ipvsadmin
1 [root@xuegod63]# yum install ipvsadm
2 Use ipvsadm command to set the rules:
[root@xuegod63 ~]# ipvsadm -A -t 192.168.1.63:80 -s rr
[root@xuegod63 ~]# ipvsadm -a -t 192.168.1.63:80 -r 192.168.2.64 -m
[root@xuegod63 ~]# ipvsadm -a -t 192.168.1.63:80 -r 192.168.2.62 -m
3 View:
Ipvsadm commands, tools for configuring and viewing kernel IPVS table and algorithm, similar iptables
[root@xuegod63 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.63:80 rr
-> 192.168.2.62:80 Masq 1 0 0
-> 192.168.2.64:80 Masq 1 0 0
4 保存配置或规则
[root@xuegod63 ~]# ipvsadm --save > /etc/sysconfig/ipvsadm
或ipvsadm -S 保存以上的配置
Saving IPVS table to /etc/sysconfig/ipvsadm: [确定]
三 配置真实服务器
RealServer:在xuegod62和xuegod64上面配置:
准备:
1、配置IP:REAL SERVER自己的网络相关信息配置成如下:
xuegod62: eth0: vmnet4 : 192.168.2.62 网关: 192.168.2.63
xuegod64: eth0: vmnet4 : 192.168.2.64 网关: 192.168.2.63
2、配置xuegod64为realserver, 并启web服务
[root@xuegod64 ~]# yum install -y httpd
[root@xuegod64 ~]# systemctl restart httpd
[root@xuegod64 ~]# echo "192.168.2.64" > /var/www/html/index.html #(实验期间,各个服务器的页面不同)
3、配置xuegod62为realserver, 并启web服务
[root@xuegod62 ~]# yum install -y httpd
[root@xuegod62 ~]# systemctl restart httpd
[root@xuegod62 ~]# echo "192.168.2.62" > /var/www/html/index.html #(实验期间,各个服务器的页面不同)
四 测试:
在xuegod63上测试:
[root@xuegod63 ~]# yum install elinks
测试realserver :
[root@xuegod63 ~]# elinks 192.168.2.64
[root@xuegod63 ~]# elinks 192.168.2.64 --dump
192.168.2.64
[root@xuegod63 ~]# elinks 192.168.2.62 --dump
192.168.2.62
测试VIP:
[root@xuegod63 ~]# elinks 192.168.1.63 --dump
192.168.2.62
访问: 在物理上打开浏览器访问: 每按F5刷新一次,就会变换一个页面。
四 扩展ipvsadm 更多参数说明
-L -n ==> 查看规则,显示内核虚拟服务器表
-L -n -c ==> 查看客户端连接分发器和real server 的情况
例1:
[root@xuegod63 ~]# ipvsadm -L -n -c
IPVS connection entries
pro expire state source virtual destination
TCP 01:33 TIME_WAIT 192.168.1.100:49698 192.168.1.70:80 192.168.2.62:80
TCP 01:26 TIME_WAIT 192.168.1.100:49690 192.168.1.70:80 192.168.2.64:80
TCP 01:57 TIME_WAIT 192.168.1.100:49739 192.168.1.70:80 192.168.2.62:80
选项:
-L -n --stats ==> 查看分发情况
-L -n --rate ==> 查看速率
-Z --zero 虚拟服务表计数器清零(清空当前的连接数量等)
例2:
[root@xuegod63 ~]# ipvsadm -Z
[root@xuegod63 ~]# ipvsadm -L -n --stats
IP Virtual Server version 1.2.1 (size=4096)
选项:
-Z --clear 清空IPVS的数据、等信息
Example 3:
[root@xuegod63 ~]# ipvsadm -C
Options:
-C Clear all the rules
LVS rule configuration file: / etc / sysconfig / the ipvsadm