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

相关推荐

  • 关于大型网站技术演进的思考(四):存储的瓶颈(4)

    原文出处: 夏天的森林    如果数据库需要进行水平拆分,这其实是一件很开心的事情,因为它代表公司的业务正在迅猛的增长,对于开发人员而言那就是有不尽的项目可以做,虽然会感觉很忙,但是人过的充实,心里也踏实。 数据库水平拆分简单说来就是先将原数据库里的一张表在做垂直拆分出来放置在单独的数据库和单独的表里后更进一步的把本来是一个整体…

    2015-03-11
  • keepalived+nginx 模型示例

    原理为: 调度器 利用 keepalived 保持高可用性,实现对系统的监控和VIP 的floating NGINX 利用upstream模块进行调度 关键点: keepalived 对NGINX 状态的监控: //利用配置文件中设定的脚本对调度器的nginx 进程的监控 实验步骤: 基于上一篇LVS-DR架构来做,具体LVS-DR架构请参考上一篇 先设置主…

    2017-05-13
  • sed命令的入门与进阶

    sed:Stream EDitor     什么是sed呢?sed被称为linux文本处理三剑客之一,另外两个就是大名鼎鼎的grep和awk。sed是非交互性的流编辑器,在处理文本时一次只读取一行文本,然后基于所给定的编辑脚本对模式空间中的内容做编辑处理并把处理后的结果输出至标准输出。接着处理下一行文本,这样不断重复,直到文件的末尾。se…

    2017-03-16
  • 第七周作业

    1、创建一个10G分区,并格式为ext4文件系统;   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;   (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~]# fdis…

    Linux干货 2017-07-04
  • mysql备份与恢复

    1、mysqldump进行mysqll数据库的备份与还原 命令说明: Schema和数据存储一起、巨大的SQL语句、单个巨大的备份文件 mysqldump: 客户端,通过mysql协议连接至mysqld; mysqldump [options] [db_name [tbl_name …]] shell> mysqldump [options] db…

    Linux干货 2017-03-27
  • Linux系统进程管理

    本章学习内容     ——进程概念     ——进程创建、切换和撤销     ——进程调度     ——进程分类     ——进程状态 &n…

    Linux干货 2016-09-13