linux LVS NAT模式连接不到?大神帮忙看看

机器1配置
配置:eht0,如果是虚拟机Net模式
DEVICE=eth0
HWADDR=00:0C:29:E0:42:2C
TYPE=Ethernet
UUID=a47598a6-fd21-43ac-a345-b46aad466153
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BROADCAST=192.168.188.255
IPADDR=192.168.188.2
NETMASK=255.255.255.0
NETWORK=192.168.188.1
配置:eth1,如果是虚拟机设置桥接模式
DEVICE=eth1
HWADDR=00:50:56:3e:b7:21
TYPE=Ethernet
UUID=a47598a6-fd21-83ac-a345-b46aad466153
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BROADCAST=192.168.1.255
IPADDR=192.168.1.238
NETMASK=255.255.255.0
NETWORK=192.168.1.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
重启网卡:service network restart

然后配置机器2,虚拟机nat配置
DEVICE=eth0
HWADDR=00:0c:29:fb:61:a2
TYPE=Ethernet
IPADDR=192.168.188.3
NETMAST=255.255.255.0
GATEWAY=192.168.188.2
NETMASK=255.255.255.0
机器三配置,虚拟机nat配置
DEVICE=eth0
HWADDR=00:0C:29:93:B2:D7
TYPE=Ethernet
UUID=a47598a6-fd21-43ac-a345-b46aad466153
BROADCAST=192.168.188.255
IPADDR=192.168.188.4
NETMASK=255.255.255.0
NETWORK=192.168.188.0
GATEWAY=192.168.188.2
且机器1、2、3能互相ping通
我们要看看机器中的内核是否包含ipvs的功能?
[root@sy-0217 network-scripts]# grep -i 'ipvs' /boot/config-2.6.32-431.el6.i686
# IPVS transport protocol load balancing support
# IPVS scheduler
# IPVS application helper
机器一配置IP转发功能
vim /etc/sysctl.conf
修改net.ipv4.ip_forward = 0改为1
执行:sysctl -p 命令让内核马上生效

在机器2和机器3上安装http:yum -y install httpd
切换到html目录
cd /var/www/html/
vi index.html
内容为RalServer1,第2台机子为RalServer2
启动httpd
service httpd restart
chkconfig httpd on
关闭所有机器的防火墙
关闭: chkconfig iptables off
service iptables stop
重启虚拟机
机器1安装ipvsadm: yum -y install ipvsadm
service ipvsadm start
ipvsadm -C
[root@sy-0217 network-scripts]# ipvsadm -A -t 192.168.188.2:80 -s rr
[root@sy-0217 network-scripts]# ipvsadm -a -t 192.168.188.2:80 -r 192.168.188.3 -m -w 1
[root@sy-0217 network-scripts]# ipvsadm -a -t 192.168.188.2:80 -r 192.168.188.4 -m -w 2
在机器1执行
[root@sy-0217 network-scripts]# curl http://192.168.188.2
RalServer1
[root@sy-0217 network-scripts]# curl http://192.168.188.2
alServer2
机器2或者3执行
[root@sy-0225 network-scripts]# curl http://192.168.188.2
curl: (7) couldn't connect to host
在现实机子执行发现也是连接不上,连接的时候InActConn不为0
[root@sy-0217 network-scripts]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.188.2:80 rr
-> 192.168.188.3:80 Masq 1 0 1
-> 192.168.188.4:80 Masq 2 0 0

Forums:

randomness