標籤: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進行驗證
[[email protected] html]# curlhttp://192.168.74.2RS1:192.168.74.2
[[email protected] html]# curlhttp://192.168.74.3:8080RS2:192.168.74.3
定義叢集服務:
[[email protected] html]# ipvsadm -A -t 172.16.34.1:80 -s rr
查看定義的叢集服務
[[email protected] html]# ipvsadm -L -nIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 172.16.34.1:80 rr
添加RS
[[email protected] html]# ipvsadm -a -t172.16.34.1:80 -r 192.168.74.2:80 -m(-w可添加權重,次數使用rr演算法,權重無意義)[[email protected] html]# ipvsadm -a -t172.16.34.1:80 -r 192.168.74.3:8080 -m
再次查看
[[email protected] html]# ipvsadm -L -nIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 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的核心轉寄功能
[[email protected] html]# echo 1 >/proc/sys/net/ipv4/ip_forward
在客戶機上進行驗證
[[email protected] ~]# curl http://172.16.34.1RS2:192.168.74.3[[email protected] ~]# curl http://172.16.34.1RS1:192.168.74.2[[email protected] ~]# curl http://172.16.34.1RS2:192.168.74.3[[email protected] ~]# curl http://172.16.34.1RS1:192.168.74.2
修改演算法為wrr
添加權重
[[email protected]]# ipvsadm -e -t 172.16.34.1:80 -r 192.168.74.3:8080 -m -w2[[email protected]]# ipvsadm -e -t 172.16.34.1:80 -r 192.168.74.2:80 -m -w1
修改該演算法
[[email protected]]# ipvsadm -E -t 172.16.34.1:80 -s wrr
驗證
[[email protected] html]# ipvsadm -l -nIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 172.16.34.1:80 wrr -> 192.168.74.2:80 Masq 1 0 0 -> 192.168.74.3:8080 Masq 2 0 0
[[email protected] ~]# for i in {1..10};do curlhttp://172.16.34.1;doneRS1:192.168.74.2RS2:192.168.74.3RS2:192.168.74.3RS1:192.168.74.2RS2:192.168.74.3RS2:192.168.74.3RS1:192.168.74.2RS2:192.168.74.3RS2:192.168.74.3RS1:192.168.74.2
顯示統計資料
[[email protected] html]# ipvsadm -Ln --statsIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes -> RemoteAddress:PortTCP 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
顯示速率
[[email protected] html]# ipvsadm -Ln --rateIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS -> RemoteAddress:PortTCP 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實驗