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

相关推荐

  • 计算机的组成及其功能

    计算机由运算器,控制器、存储器及输入、输出装置五部分组成。 第一,运算器(Arithmetical and Logical Unit),也称作算术逻辑单元,主要是对数据进行各种运算。 第二,控制器(Control Unit)是计算机的控制中心,协调各计算机各部分按照预先的目标和步骤有序的工作。控制器从存储器中逐条取出指令,分析每条指令规定的操作和所需数据的存…

    Linux干货 2016-09-17
  • 二、(2)bash的工作特性之:命令执行状态返回值及命令行展开

    bash 工作特性 命令执行状态 命令行展开

    2018-01-10
  • linux命令速记技巧

    linux命令速记技巧 linux命令有一定的命名规则,一个正常的coder在编码的过程中都会考虑命名的语义化,开发者对函数的命名一定也尽量遵循这个规律.了解目录所对应的英文全称有助于自己的记忆,理解记忆获得知识的留存率要远大于死记硬背.如果英文基础太差,小编建议先学好英文基本功再来学习这些命令. 命令的中文对照 命令 英文全称 中文释义 ls list 列…

    Linux干货 2017-03-25
  • Linux中查看文本工具

    一、文件查看 文件查看命令:cat,tac,rev,我们重点详解cat命令 cat命令连接文件并打印到标准输出设备上,cat经常用来显示文件的内容,类似于下的type命令 我们可以理解cat命令是复制标准输入到标准输出 cat命令选项: cat [OPTION]… [FILE]… -E:显示行结束符$   &nbs…

    Linux干货 2016-08-07
  • bash变量和逻辑运行

    bash 特性及bash脚本编程初步       终端,附着在终端的接口程序:      GUI:KDE,GNome,Xfce      CLI: /etc/shells              b…

    Linux干货 2016-12-23
  • ☞LVS

    LVS 概述 LVS工作类型 LVS NAT LVS DR(默认) Direct Routing带来的问题 限制响应模型的内核参数 LVS TUN LVS FULLNAT scheduling-method 静态调度算法 动态调度算法 CentOS 7 中的ipvs组件 安装ipvsadm程序 主要文件 ipvsadm命令 配置集群服务 NAT方法示例 DR…

    Linux干货 2016-10-26