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

相关推荐

  • Linux终端类型

      终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。   在Linux系统的设备特殊文件目录/dev/下,终端特殊设备文件一般有以下几种:   1、串行端口终端 /dev/ttySn     串行端口终端是使用计算机串行端口连接的终端设备。计算机把每个串行端口都看作是一个…

    Linux干货 2016-10-14
  • linux基础学习之AWK

    内容: 1、awk输出(print、printf) 2、awk变量(内建变量和定义变量) 3、awk数组 4、awk重定向输出 5、awk操作符 6、awk常见模式类型 7、awk控制及循环语句 8、awk内置函数 awk:(其名称得自于它的创始人 Alfred Aho 、Peter Weinberger 和 Brian Kernighan 姓氏的首个字母)…

    Linux干货 2016-09-22
  • SSH——安全的通信

    SSH ·ssh:secure shell, protocol, 22/tcp,  安全的远程登录 ·OpenSSH:ssh协议的开源实现 ·dropbear:另一个开源实现 ·SSH协议版本:          v1:基于CRC-32做MAC,不安全;man-in-m…

    Linux干货 2016-09-25
  • 马哥教育网络19期+第十二周课程练习

    1、请描述一次完整的http请求处理过程; a.向根域名服务器请求解析域名,然后根服务器返回相应的IP信息; b.用户的Web浏览器向服务器端的80端口通过三次握手建立TCP连接; c.建立完TCP连接后发送HTTP请求,请求的格式包括请求方法、URL和协议版本号,方法有GET、HEAD、POST、PUT、DELETE、OPTIONS、TRACE,如: &n…

    Linux干货 2016-08-22
  • 考试题目

    1、  简述TCP三次握手四次挥手过程及各过程中客户端和服务器端的状态。 TCP三次握手,四次断开通过以下图示说明: 2、说说进程和线程的区别 (1)一个线程只能输入某一个进程,一个进程可以有多个线程。一个程序至少有一个进程,一个进程至少有一个线程。 (2)进程有独立的地址空间,线程没有独立的地址空间,进程内的多个线程共享进程的地址空间。 (3)线…

    Linux干货 2016-06-19
  • bash脚本循环语句用法练习

    bash脚本循环语句用法练习 1、使用循环语句写一个脚本,实现打印出来国际象棋的棋盘 #方法1:使用until循环语句实现 [root@liang7 bin]# cat chess-until.sh  #!/bin/bash #Author:liang #Version:1.0 #Description:Print&n…

    Linux干货 2016-08-24