当前位置: 技术问答>linux和unix
没有局域网环境,全是公网IP可以做LVS吗,该如何做了!请大家赐教!
来源: 互联网 发布时间:2017-01-31
本文导语: 现在有3台服务器,各有一个公网IP地址。IP地址形式如下: IP1:122.224.224.001 IP2:122.224.224.002 IP3:122.224.224.003 我想用IP1做主LVS(不做备LVS), IP2和IP3两台服务器为两个tomcat WEB服务节点。配置上有什么特殊的吗? 我按以...
现在有3台服务器,各有一个公网IP地址。IP地址形式如下:
IP1:122.224.224.001
IP2:122.224.224.002
IP3:122.224.224.003
我想用IP1做主LVS(不做备LVS),
IP2和IP3两台服务器为两个tomcat WEB服务节点。配置上有什么特殊的吗?
我按以下的方法做没有成功:
1、在IP1上安装:
keepalived-1.1.15-7.1
ipvsadm-1.24-123.2
linux-554e:/usr # rpm -ivh keepalived-1.1.15-7.1.i586.rpm
Preparing... ########################################### [100%]
1:keepalived ########################################### [100%]
keepalived 0:off 1:off 2:off 3:on 4:off 5:on 6:off
linux-554e:/usr # rpm -ivh ipvsadm-1.24-123.2.i586.rpm
Preparing... ########################################### [100%]
1:ipvsadm ########################################### [100%]
Updating etc/sysconfig/ipvsadm...
2 配置文件:/etc/keepalived/keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
122.224.224.001
}
}
virtual_server 122.224.224.001 8888 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 122.224.224.002 8888 {
weight 2
TCP_CHECK {
connect_port 8888
connect_timeout 15
nb_get_retry 3
delay_before_retry 3
}
}
real_server 122.224.224.003 8888 {
weight 1
TCP_CHECK {
connect_port 8888
connect_timeout 15
nb_get_retry 3
delay_before_retry 3
}
}
}
3 启动 lvs:~ # rckeepalived start
启动正常
如下:
linux-554e:/etc/keepalived # ps -ef |grep keep
root 13820 1 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
root 13821 13820 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
root 13822 13820 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
4、配置WEB服务器IP2和IP3
修改文件/etc/sysctl.conf添加以下内容:
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
运行 sysctl -p
修改文件/etc/sysconfig/network/ifcfg-lo添加以下内容
IPADDR_0='122.224.224.001'
NETMASK_0='255.255.255.255'
LABEL_0='0'
运行 rcnetwork restart
一切正常
我现在打开浏览器输入:http://122.224.224.001:8888,理论上应当将服务重定向到http://122.224.224.002:8888或http://122.224.224.002:8888,但是却无法访问,没有重定向成功。
我在IP1上执行ipvsadm -lcn,有如下结果
linux-554e:/etc/keepalived # ipvsadm -lcn
IPVS connection entries
pro expire state source virtual destination
TCP 00:56 SYN_RECV 183.128.209.247:2909 122.224.224.001:8888 122.224.224.002:8888
TCP 00:47 NONE 183.128.209.247:0 122.224.224.001:8888 122.224.224.002:8888
TCP 00:57 SYN_RECV 183.128.209.247:2910 122.224.224.001:8888 122.224.224.002:8888
我在IP1上执行ipvsadm -l,有如下结果
linux-554e:/etc/keepalived # ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP linux-554e.site:ddi-tcp-1 wrr persistent 50
-> 122.224.224.002:ddi-tcp-1 Route 2 0 2
-> 122.224.224.003:ddi-tcp-1 Route 1 0 0
我是初次配置LVS,请问各位大侠,我应当如何来配置,才能使我的LVS生效呢!
IP1:122.224.224.001
IP2:122.224.224.002
IP3:122.224.224.003
我想用IP1做主LVS(不做备LVS),
IP2和IP3两台服务器为两个tomcat WEB服务节点。配置上有什么特殊的吗?
我按以下的方法做没有成功:
1、在IP1上安装:
keepalived-1.1.15-7.1
ipvsadm-1.24-123.2
linux-554e:/usr # rpm -ivh keepalived-1.1.15-7.1.i586.rpm
Preparing... ########################################### [100%]
1:keepalived ########################################### [100%]
keepalived 0:off 1:off 2:off 3:on 4:off 5:on 6:off
linux-554e:/usr # rpm -ivh ipvsadm-1.24-123.2.i586.rpm
Preparing... ########################################### [100%]
1:ipvsadm ########################################### [100%]
Updating etc/sysconfig/ipvsadm...
2 配置文件:/etc/keepalived/keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
122.224.224.001
}
}
virtual_server 122.224.224.001 8888 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 122.224.224.002 8888 {
weight 2
TCP_CHECK {
connect_port 8888
connect_timeout 15
nb_get_retry 3
delay_before_retry 3
}
}
real_server 122.224.224.003 8888 {
weight 1
TCP_CHECK {
connect_port 8888
connect_timeout 15
nb_get_retry 3
delay_before_retry 3
}
}
}
3 启动 lvs:~ # rckeepalived start
启动正常
如下:
linux-554e:/etc/keepalived # ps -ef |grep keep
root 13820 1 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
root 13821 13820 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
root 13822 13820 0 21:45 ? 00:00:00 /usr/sbin/keepalived -D
4、配置WEB服务器IP2和IP3
修改文件/etc/sysctl.conf添加以下内容:
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
运行 sysctl -p
修改文件/etc/sysconfig/network/ifcfg-lo添加以下内容
IPADDR_0='122.224.224.001'
NETMASK_0='255.255.255.255'
LABEL_0='0'
运行 rcnetwork restart
一切正常
我现在打开浏览器输入:http://122.224.224.001:8888,理论上应当将服务重定向到http://122.224.224.002:8888或http://122.224.224.002:8888,但是却无法访问,没有重定向成功。
我在IP1上执行ipvsadm -lcn,有如下结果
linux-554e:/etc/keepalived # ipvsadm -lcn
IPVS connection entries
pro expire state source virtual destination
TCP 00:56 SYN_RECV 183.128.209.247:2909 122.224.224.001:8888 122.224.224.002:8888
TCP 00:47 NONE 183.128.209.247:0 122.224.224.001:8888 122.224.224.002:8888
TCP 00:57 SYN_RECV 183.128.209.247:2910 122.224.224.001:8888 122.224.224.002:8888
我在IP1上执行ipvsadm -l,有如下结果
linux-554e:/etc/keepalived # ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP linux-554e.site:ddi-tcp-1 wrr persistent 50
-> 122.224.224.002:ddi-tcp-1 Route 2 0 2
-> 122.224.224.003:ddi-tcp-1 Route 1 0 0
我是初次配置LVS,请问各位大侠,我应当如何来配置,才能使我的LVS生效呢!
|
是的,虚拟IP不能和物理IP相同...
你想做的话,可以把001关机,然后在002上运行keepalived,虚拟IP是001
|
如果001是虚拟ip,002和003应该在lo上同时有虚拟IP的监听,在002和003上执行
ifconfig | grep 001 看正常否
keepalived运行在002上,此时只有在002上运行ipvsadm才有输出,ipvsadm -l 输出形如:
TCP 001:8888 wrr persistent 50
-> 002:8888 Local 2 0 2
-> 003:8888 Route 1 0 0
目前我个人怀疑的是:
1.iptables问题,尝试iptables -F后再测试,另外我记得002的 sysctl里要开启ip转发功能。
2.keepalived没有正常载入配置文件,这货很讨厌的一点是没有配置文件检查功能,自己查看/var/log/message 中是否有配置文件加载的报错
3.002和003上是否安装了ipvs?
ifconfig | grep 001 看正常否
keepalived运行在002上,此时只有在002上运行ipvsadm才有输出,ipvsadm -l 输出形如:
TCP 001:8888 wrr persistent 50
-> 002:8888 Local 2 0 2
-> 003:8888 Route 1 0 0
目前我个人怀疑的是:
1.iptables问题,尝试iptables -F后再测试,另外我记得002的 sysctl里要开启ip转发功能。
2.keepalived没有正常载入配置文件,这货很讨厌的一点是没有配置文件检查功能,自己查看/var/log/message 中是否有配置文件加载的报错
3.002和003上是否安装了ipvs?