LVS-NAT 模型实现WEB负载均衡
主机规划:
| 主机名 | 主机地址 | 角色 | OS |
| :-------- | --------| -------- | :–: |
| Director | 192.168.1.9/192.168.20.2 | Director | CentOS 6.8|
| RS1 | 192.168.20.7 | Real Server1| CentOS 7.2|
| RS2 | 192.168.20.8 | Real Server2| CentOS 7.2|
Notice:
注意:我这里node1和node2的网关均是192.168.20.2,所有主机selinux和iptables均关闭。

RS1
配置web服务
1 2 3 4 5 6 7
| [root@rs1 ~] [root@rs1 ~] [root@rs1 ~] [root@rs1 ~] LISTEN 0 128 :::80 :::* users:(("httpd",pid=6562,fd=4),("httpd",pid=6561,fd=4),("httpd",pid=6560,fd=4),("httpd",pid=6559,fd=4),("httpd",pid=6558,fd=4),("httpd",pid=6557,fd=4)) [root@rs1 ~] <h1>Test Page On node1.maricle.com.cn</h1>
|
RS2
配置web服务
1 2 3 4 5
| [root@rs2 ~] [root@rs2 ~] [root@rs2 ~] [root@rs2 ~] LISTEN 0 128 :::80 :::* users:(("httpd",pid=6562,fd=4),("httpd",pid=6561,fd=4),("httpd",pid=6560,fd=4),("httpd",pid=6559,fd=4),("httpd",pid=6558,fd=4),("httpd",pid=6557,fd=4))
|
Director Server中安装ipvsadm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| [root@Director ~] inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host inet 192.168.1.9/24 brd 192.168.1.255 scope global eth0 inet6 fe80::20c:29ff:fe33:9a8e/64 scope link tentative dadfailed inet 192.168.20.2/24 brd 192.168.20.255 scope global eth1 inet6 fe80::20c:29ff:fe33:9a98/64 scope link [root@Director ~]
[root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS2.maricle.com.cn</h1> [root@Director ~] [root@Director ~] net.ipv4.ip_forward = 1 [root@Director ~]
[root@Director ~] [root@Director ~] [root@Director ~] [root@Director ~] [root@Director ~] [root@Director ~] [root@Director ~] IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.9:80 rr -> 192.168.20.7:80 Masq 1 0 0 -> 192.168.20.8:80 Masq 1 0 0
[root@Director ~] <h1>Test Page On RS2.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS2.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS2.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] [root@Director ~] IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.9:80 rr -> 192.168.20.7:80 Masq 1 0 12 -> 192.168.20.8:80 Masq 1 0 13 [root@Director ~]
[root@Director ~] [root@Director ~] IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.9:80 sh -> 192.168.20.7:80 Masq 1 0 0 -> 192.168.20.8:80 Masq 1 0 0 [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> [root@Director ~] <h1>Test Page On RS1.maricle.com.cn</h1> root@Director ~] IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.9:80 sh -> 192.168.20.7:80 Masq 1 0 11 -> 192.168.20.8:80 Masq 1 0 0
|
关于rr算法和sh算法请看我上一篇博客LVS工作模型和调度算法详解
本文偏操作,下面一篇将介绍DR模型的实现