LVS NAT模型演示

LVS NAT模型演示

LVS NAT模型演示

这里我们刻意将两个RS的web页面文件,提供为不同的内容(实际应用中,每个RS页面的内容要完全相同)

基本配置

[root@web1 ~]# route add default gw 192.168.110.130  --> web1服务器中,默认网关要指向DIP
[root@web2 ~]# route add default gw 192.168.110.130  --> web2服务器中,默认网关要指向DIP
[root@Directory ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1   //开启路由转发功能
[root@Directory ~]# sysctl -p  //以上修改立即生效

directory配置

[root@Directory ~]# ipvsadm -A -t 10.1.249.43:80:80 -s rr  -->添加一个集群服务,调度算法为rr
[root@Directory ~]# ipvsadm -L -n  -->查看添加的集群服务
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.249.43:80 rr  --> 成功添加   调度算法为rr

[root@Directory ~]# ipvsadm -a -t 10.1.249.43:80 -r 192.168.110.129 -m -->向集群中添加RS
[root@Directory ~]# ipvsadm -a -t 10.1.249.43:80 -r 192.168.110.128 -m -->将web1和web2添加到集群中
[root@Directory ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.249.43:80 rr
  -> 192.168.110.128:80           Masq    1      0          0     -->成功添加    
  -> 192.168.110.129:80           Masq    1      0          0     --> 权重默认为1  masq-->masquerade-->地址伪装

测试:浏览器内输入10.1.249.43(VIP的地址)

刷新

LVS NAT模型演示

默认每刷新一次,会出现不同的页面

因为我们此时的算法为rr 即在web1和web2之间轮询

命令查看状态

[root@Directory ~]# ipvsadm -L -nc
TCP 00:17  TIME_WAIT   10.1.250.160:55181 10.1.249.43:80     192.168.110.128:80  -->明显看出在轮询
TCP 01:55  TIME_WAIT   10.1.250.160:55253 10.1.249.43:80     192.168.110.129:80
TCP 01:55  TIME_WAIT   10.1.250.160:55254 10.1.249.43:80     192.168.110.128:80
TCP 01:55  TIME_WAIT   10.1.250.160:55251 10.1.249.43:80     192.168.110.129:80
...



[root@Directory ~]# ipvsadm -L -n --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  10.1.249.43:80                     18       88       87    12095     8353
  -> 192.168.110.128:80                  9       43       42     5768     4048  --> 匹配到的报文数几乎一样
  -> 192.168.110.129:80                  9       45       45     6327     4305

修改调度算法为wrr测试

[root@Directory ~]# ipvsadm -Z 统计数据清零
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  10.1.249.43:80                      0        0        0        0        0  --> 全部清零
  -> 192.168.110.128:80                  0        0        0        0        0
  -> 192.168.110.129:80                  0        0        0        0        0


[root@Directory ~]# ipvsadm -E -t 10.1.249.43:80 -s wrr  --> 修改调度算法
[root@Directory ~]# ipvsadm -e -t 10.1.249.43:80 -r 192.168.110.129 -m -w 3  --> 将web1的权重修改为3
[root@Directory ~]# ipvsadm -L -n     
-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.249.43:80 wrr
  -> 192.168.110.128:80           Masq    1      0          1          
  -> 192.168.110.129:80           Masq    3      0          0   --> 此时web1的权重为3

测试访问 一定要访问VIP的地址 此时,平均出现3次web1会出现1次web2

统计数据查看

[root@Directory ~]# ipvsadm -L -n --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  10.1.249.43:80                     24      120      117    16393     9859
  -> 192.168.110.128:80                  6       30       30     4218     2958
  -> 192.168.110.129:80                 18       90       87    12175     6901   --> 数据几乎为上面的3倍

查看访问日志

此时查看web1或者web2中httpd的访问日志时,一定是CIP
[root@web2 ~]# tail /var/log/httpd/access_log --> 查看web2的httpd的访问日志
10.1.250.160 - - [03/Sep/2016:15:23:43 +0800] "GET / HTTP/1.1" 200 14 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
10.1.250.160 - - [03/Sep/2016:15:23:43 +0800] "GET / HTTP/1.1" 200 14 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
10.1.250.160 - - [03/Sep/2016:15:23:44 +0800] "GET / HTTP/1.1" 200 14 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
=== 10.1.250.160为我们测试访问的客户端地址 ===

原创文章,作者:sixijie,如若转载,请注明出处:http://www.178linux.com/55735

(0)
sixijiesixijie
上一篇 2016-10-29 21:58
下一篇 2016-10-29 22:59

相关推荐

  • 文本处理工具

    cat:查看文本文件  tac:竖行相反  rav:行内相反 -n:显示时加行号(空行也加行号) -b:            (空行不加) more:分页查看文件 -d:显示翻页及退出提示 less:一页一页查看文件或STDIN输出 head:前 -n#:前#行内容 tail:…

    Linux干货 2016-08-08
  • DNS高级应用之子域授权&区域转发

    一、环境准备:    1、准备三台测试服务器,划分如下:    主DNS服务器:eth0:192.168.10.203;负责mylinux.com域解析;确保可以正常解析      子域DNS服务器:eth0:192.168.10.120; 负责子域ops.mylinux.com解析; &…

    Linux干货 2015-06-01
  • 逻辑卷管理

    1.相关命令:lsblk、fdisk、gdisk、parted、mkfs、mke2fs、blkid、e2label、findfs、tune2fs、dumpe2fs、fsck、e2fsck、mount、swapon、swapoff、mkisofs、wodim、free、df、du、dd。 2.列出块设备:lsblk    &nbs…

    Linux干货 2016-09-01
  • Linux的磁盘管理:

    Linux的磁盘管理: Linux的核心:一切介文件:     open,read,write,close 块设备:block,存取单位‘块’,磁盘 字符设备:char 存取单位‘字符’,键盘 设备文件:关联至一个设备驱动程序,进而能够跟与之对应硬件设备进行通信: 设备号码:   &nbs…

    Linux干货 2016-07-22
  • openssl&openssh

    安全和加密 不加密流量的易受攻击性       密码/数据嗅探       数据操作       验证操作       相当于邮寄明信片 不安全的传统协议       telnet、FTP、POP3等等;不安全…

    Linux干货 2016-09-26
  • centos6开机启动流程以及系统服务配置管理

    内容:   CentOS6 的启动流程   服务管理(chkconfig)   手动制定系统开机服务脚本 一、centos6系统启动流程 综述过程: POST–>BIOS(Boot Sequence)–>MBR(grub,446)–>Kernel–>init…

    Linux干货 2016-09-08