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.178linux.com/75646

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

相关推荐

  • 权限管理与ACL

    一、文件属性 1.文件属性:    文件属性操作     chown : change owner  ,设置文件所有者     chgrp : change group  ,设置文件的属组    文件属主修改: chow…

    Linux干货 2016-08-05
  • 第二周

    3、(1)、  :  ~]# mkdir -p /tmp/{a_c,a_d,b_c,b_d}                  or     ~]# …

    Linux干货 2016-08-22
  • tomcat基础-如何给Tomcat前端加反向代理服务器

    Tomcat可以做为反向代理服务器的组件有很多,例如使用nginx,如果使用nginx,Tomcat就只能使用http连接器,另外一种是apache。如果是使用httpd,Tomcat两种连接器都能发挥作用,例如可以使用http连接器,也可以使用ajp连接器,

    Linux干货 2018-03-19
  • test

    test

    Linux干货 2017-02-14
  • 进程及任务管理

    进程概念 内核的功用:进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等 Process: 运行中的程序的一个副本,是被载入内存的一个指令集合     进程ID(Process ID,PID)号码被用来标记各个进程     UID、GID、和SELi…

    Linux干货 2016-09-09
  • rsyslog+mysql+loganalyzer日志服务器搭建

    rsyslog+mysql+loganalyzer日志服务器搭建 环境 服务器端:192.168.25.129,centos7 客户机端:192.168.25.130,centos7 rsyslog+Mysql服务器端的配置: 准备好msql server或mariadb server ]# yum -y install&nbs…

    Linux干货 2016-11-07