标签:lvs-net
Lvs-net实验
环境:
server:centos6.7;外网IP:172.16.34.1;内网IP:192.168.74.129
RS1:centos7.2;内网IP:192.168.74.2;安装nginx服务,监听在80端口
RS2:centos7.2;内网IP:192.168.74.3;安装httpd服务,监听在8080端口
客户机:centos6.7,IP:172.16.34.3
对配置好IP地址的RS进行验证
[root@localhost html]# curlhttp://192.168.74.2 RS1:192.168.74.2
[root@localhost html]# curlhttp://192.168.74.3:8080 RS2:192.168.74.3
定义集群服务:
[root@localhost html]# ipvsadm -A -t 172.16.34.1:80 -s rr
查看定义的集群服务
[root@localhost html]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.16.34.1:80 rr
添加RS
[root@localhost html]# ipvsadm -a -t172.16.34.1:80 -r 192.168.74.2:80 -m(-w可添加权重,次数使用rr算法,权重无意义) [root@localhost html]# ipvsadm -a -t172.16.34.1:80 -r 192.168.74.3:8080 -m
再次查看
[root@localhost html]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.16.34.1:80 rr -> 192.168.74.2:80 Masq 1 0 0 -> 192.168.74.3:8080 Masq 1 0 0
打开server的核心转发功能
[root@localhost html]# echo 1 >/proc/sys/net/ipv4/ip_forward
在客户机上进行验证
[root@pxe126 ~]# curl http://172.16.34.1 RS2:192.168.74.3 [root@pxe126 ~]# curl http://172.16.34.1 RS1:192.168.74.2 [root@pxe126 ~]# curl http://172.16.34.1 RS2:192.168.74.3 [root@pxe126 ~]# curl http://172.16.34.1 RS1:192.168.74.2
修改算法为wrr
添加权重
[root@localhosthtml]# ipvsadm -e -t 172.16.34.1:80 -r 192.168.74.3:8080 -m -w2 [root@localhosthtml]# ipvsadm -e -t 172.16.34.1:80 -r 192.168.74.2:80 -m -w1
修改该算法
[root@localhosthtml]# ipvsadm -E -t 172.16.34.1:80 -s wrr
验证
[root@localhost html]# ipvsadm -l -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.16.34.1:80 wrr -> 192.168.74.2:80 Masq 1 0 0 -> 192.168.74.3:8080 Masq 2 0 0
[root@pxe126 ~]# for i in {1..10};do curlhttp://172.16.34.1;done RS1:192.168.74.2 RS2:192.168.74.3 RS2:192.168.74.3 RS1:192.168.74.2 RS2:192.168.74.3 RS2:192.168.74.3 RS1:192.168.74.2 RS2:192.168.74.3 RS2:192.168.74.3 RS1:192.168.74.2
显示统计数据
[root@localhost html]# ipvsadm -Ln --stats IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes -> RemoteAddress:Port TCP 172.16.34.1:80 32 187 116 15106 13674 -> 192.168.74.2:80 13 77 48 6228 5616 -> 192.168.74.3:8080 19 110 68 8878 8058
显示速率
[root@localhost html]# ipvsadm -Ln --rate IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS -> RemoteAddress:Port TCP 172.16.34.1:80 0 0 0 0 0 -> 192.168.74.2:80 0 0 0 0 0 -> 192.168.74.3:8080 0 0 0 0 0
标签:lvs-net
原文地址:http://mylinuxlearn.blog.51cto.com/9740653/1833500