lvs-nat集群

lvs-nat算法
    nat模型樣式
    vs服務器:公網地址 172.18.250.253
        私網地址 192.168.57.129 (DIP)
    各私網服務器網關指向服務器DIP
    各私網服務器做集群:web (telnet,ssh)
    私網服務器使用httpd實現
    rs私網服務器1 centos7 ip:192.168.57.132
    rs私網服務器2 centos6 ip:192.168.57.128

設置網卡屬性:
    rs1[root@CentOS7 ~]#nmtui 開啟圖形界面編輯IP地址
        Addresses:192.168.57.132/24
        Gateway:192.168.57.129
        DNS servers:172.18.0.1
    rs1[root@CentOS7 ~]#systemctl restart network.service

    rs2[root@CentOS6 ~]#setup 開啟圖形界面編輯IP地址
        Static IP: 192.168.57.128
        Netmask: 255.255.255.0
        gateway IP: 192.168.57.129
        DNS servers:172.18.0.1
    rs2[root@CentOS6 ~]#service network restart

    vs[root@CentOS7 ~]#yum -y install ipvsadm 

    rs1[root@CentOS7 ~]# yum -y install httpd telnet-server tftp-server
    rs1[root@CentOS7 ~]#vim /var/www/html/index.html
        <h1>RS1:192.168.57.132</h1>
    rs1[root@CentOS7 ~]# systemctl start httpd.service
    rs1[root@CentOS6 ~]#ss -tnl

    rs2[root@CentOS6 ~]#yum -y install httpd telnet-server tftp-server
    rs2[root@CentOS6 ~]#vim /var/www/html/index.html
        <h1>RS2:192.168.57.128</h1>
    rs2[root@CentOS6 ~]#service httpd start
    rs2[root@CentOS6 ~]#ss -tnl

vs訪問rs:
    vs[root@CentOS7 ~]#curl http://192.168.57.132
        <h1>RS1:192.168.57.132</h1>
    vs[root@CentOS7 ~]#curl http://192.168.57.128
        <h1>RS2:192.168.57.128</h1>
定義集群服務:
    vs[root@CentOS7 ~]#ipvsadm -Ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port  Forward Weight ActiveConn InActConn
    vs[root@CentOS7 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
    vs[root@CentOS7 ~]#ipvsadm -A -t 172.18.250.253:80 -s rr
    vs[root@CentOS7 ~]#ipvsadm -Ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port  Forward Weight ActiveConn InActConn
        TCP  172.18.250.253:80 rr
    vs[root@CentOS7 ~]#ipvsadm -a -t 172.18.250.253:80 -r 192.168.57.132 -m 
    vs[root@CentOS7 ~]#ipvsadm -a -t 172.18.250.253:80 -r 192.168.57.128 -m 
    vs[root@CentOS7 ~]#ipvsadm -Ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port  Forward Weight ActiveConn InActConn
        TCP  172.18.250.253:80 rr
          -> 192.168.57.128:80  Masq  1  0  0         
          -> 192.168.57.132:80  Masq  1  0  0
    ~]#for i in {1..10};do curl http://172.18.252.253;done
        <h1>RS1:192.168.57.132</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS1:192.168.57.132</h1>
        <h1>RS2:192.168.57.128</h1>

修改權重:
    vs[root@CentOS7 ~]# ipvsadm -e -t 172.18.252.253:80 -r 192.168.57.132 -m -w 2
    vs[root@CentOS7 ~]# ipvsadm -E -t 172.18.252.253:80 -s wrr
    vs[root@CentOS7 ~]# ipvsadm -Ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port  Forward Weight ActiveConn InActConn
        TCP  172.18.250.253:80 wrr
          -> 192.168.57.128:80  Masq  1  0  5         
          -> 192.168.57.132:80  Masq  2  0  5
    ~]#for i in {1..10};do curl http://172.18.250.253; done
        <h1>RS1:192.168.57.132</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS1:192.168.57.132</h1>
        <h1>RS1:192.168.57.132</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS1:192.168.57.132</h1>
        <h1>RS1:192.168.57.132</h1>
telnet:
    添加用戶:
    rs1[root@CentOS7 ~]# for i in {1..3}; do useradd user$i;echo "mageedu" | passwd --stdin user$i; done
    rs1[root@CentOS7 ~]# systemctl start telnet.socket
    rs1[root@CentOS7 ~]# ss -tnl
        LISTEN 0 128 :::23 :::*

    rs2[root@CentOS6 ~]# for i in {1..3}; do useradd user$i;echo "mageedu" | passwd --stdin user$i; done
    rs2[root@CentOS6 html]#chkconfig telnet on
    rs2[root@CentOS6 html]#service xinetd restart
        Stopping xinetd:   [FAILED]
        Starting xinetd:   [  OK  ]
    rs2[root@CentOS6 html]#ss -tnl
        LISTEN 0 64 :::23 :::* 

    vs[root@CentOS7 ~]# ipvsadm -A -t 172.18.250.253:23 -s lc
    vs[root@CentOS7 ~]# ipvsadm -a -t 172.18.250.253:23 -r 192.168.57.132:23 -m -w 1
    vs[root@CentOS7 ~]# ipvsadm -a -t 172.18.250.253:23 -r 192.168.57.128:23 -m -w 3 
    vs[root@CentOS7 ~]# ipvsadm -ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port Forward Weight ActiveConn InActConn
        TCP  172.18.252.253:23 lc
          -> 192.168.57.128:23 Masq 3 0 0         
          -> 192.168.57.132:23 Masq 1 0 0 

    ~]#telnet 172.18.252.253
        login: user1
        Password: mageedu
    [user1@CentOS6 ~]$ ip a
        inet 192.168.57.128/24
    [user2@CentOS7 ~]$ ip a
        inet 192.168.57.132/24
    [user3@CentOS6 ~]$ ip a
        inet 192.168.57.128/24

    vs[root@CentOS7 ~]# ipvsadm -E -t 172.18.252.253:23 -s wlc
    vs[root@CentOS7 ~]# ipvsadm -ln
        IP Virtual Server version 1.2.1 (size=4096)
        Prot LocalAddress:Port Scheduler Flags
          -> RemoteAddress:Port Forward Weight ActiveConn InActConn
        TCP  172.18.252.253:23 wlc
          -> 192.168.57.128:23 Masq 3 0 1         
          -> 192.168.57.132:23 Masq 1 0 0
把wrr修改為sh算法:
    [root@CentOS7 ~]# ipvsadm -E -t 172.18.250.253:80 -s sh
    [root@CentOS7 ~]# ipvsadm -ln        
        TCP  172.18.252.253:80 sh
          -> 192.168.57.128:80 Masq 1 0 0         
          -> 192.168.57.132:80 Masq 2 0 0
    [root@CentOS7 ~]#for i in {1..10};do curl http://172.18.252.253;done
        <h1>RS2:192.168.57.128</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS2:192.168.57.128</h1>
        <h1>RS2:192.168.57.128</h1>

rs2宕機:
    vs[root@CentOS7 ~]# ipvsadm -E -t 172.18.250.253:80 -s rr
    rs2[root@CentOS6 ~]#service httpd stop
        Stopping httpd:  [  OK  ]
     ~]#for i in {1..10};do curl http://172.18.252.253;done
        curl: (7) Failed connect to 172.18.252.253:80; Connection refused
        <h1>RS1:192.168.57.132</h1>
        curl: (7) Failed connect to 172.18.252.253:80; Connection refused
        <h1>RS1:192.168.57.132</h1>
        curl: (7) Failed connect to 172.18.252.253:80; Connection refused
        <h1>RS1:192.168.57.132</h1>

原創文章,作者:CL80516000,如若轉載,請注明出處:http://www.www58058.com/75646

(0)
CL80516000CL80516000
上一篇 2017-05-14 23:30
下一篇 2017-05-15

相關推薦

欧美性久久久久