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

相关推荐

  • 浏览和管理log文件

    浏览和管理log文件 log文件是一种包含系统消息的文件,包括内核、服务和应用运行在其上。不同的日志文件对应不同的日志信息。例如,默认的系统log文件,一个log文件对应安全消息,一个log文件对应计划任务。当要对一个系统问题排错例如加载内核驱动或者当寻找对系统的非授权登录攻击,日志文件是很有帮助的。一些log文件被一个称之为rsyslogd的守护进程控制。…

    Linux干货 2017-05-15
  • lamp架构实现论坛架构及压力测试

    练习:分别使用CentOS 7和CentOS 6实现以下任务 (1) 配置四个基于名称的虚拟主机;   (a) discuzX   (b) wordpress   (c) drupal   (d) phpMyAdmin,此虚拟主机仅支持https协议; (2) 对phpMyAdmin首页做压力测试   分别给…

    Linux干货 2016-10-17
  • linux文件、目录基本操作命令及bash特性介绍

    1、文件层级FHS介绍: Filesystem Hierarchy Standard(文件系统层次化标准)的缩写,多数Linux版本采用这种文件组织形式,类似于Windows操作系统中c盘的文件目录,FHS采用树形结构组织文件。 FHS定义了系统中每个区域的用途、所需要的最小构成的文件和目录,同时还给出了例外处理与矛盾处理。 /:linux文件系统根目录 /…

    2017-09-17
  • 13 文件查找与压缩

    locate find 压缩命令 file-roller、compress/uncompress(.Z)、gzip/gunzip(.gz)、bzip2/bunzip2(.bz2)、xz/unxz(.xz) zip/unzip、tar locate 数据源 1)查询系统上预建的文件索引数据库      2)依赖于事先构建…

    Linux干货 2016-08-18
  • shell与kernel的理解

    Shell 的英文释义是外壳,与kernel 内核名词遥相呼应,一外一内,一壳一核。内核就像瑞士银行的金库,存放着客户的黄金等众多的(硬件)资产,闲杂人等(包括客户)当然是严格禁止入内的,而作为客户要存取金库中的资产则需要通过专门的特定管理人员代为操作完成,并把存取(操作)的结果呈现给客户。在Linux操作系统中,shell的职能就类似于金库的操作人员,客户…

    Linux干货 2016-02-14
  • shell 脚本编程基础

    Shell脚本简介: Shell脚本是一种特殊的程序,它是用户与linux系统内核之间的一个接口,shell是一个工具程序,在用户登录后系统启动。它解释并运行由命令行或脚本文件输入的命令,从而实现用户与内核间的交互。 Shell脚本:也就是用各类命令预先放入到一个文件中,方便一次性执行的一个程序文件,主要是方便管理员进行设置或者管理用的,是利用shell的功…

    Linux干货 2016-08-21