LVS+Keepalived配置总结
keepalived 控制虚IP(VIP)在master和backup的IP接口上的漂移
通过service keepalived start|stop来控制服务
如下:
[root@node220 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdiscnoqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500qdisc pfifo_fast qlen 1000
link/ether00:0c:29:0f:e6:5a brd ff:ff:ff:ff:ff:ff
inet192.168.2.220/16 brd 192.168.255.255 scope global eth0
inet192.168.2.118/32 scope global eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:0f:e6:64 brdff:ff:ff:ff:ff:ff
inet172.16.1.1/24 brd 172.16.1.255 scope global eth1
[root@node220 ~]# service keepalived stop
Stopping keepalived: [ OK ]
[root@node220 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdiscnoqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu1500 qdisc pfifo_fast qlen 1000
link/ether00:0c:29:0f:e6:5a brd ff:ff:ff:ff:ff:ff
inet192.168.2.220/16 brd 192.168.255.255 scope global eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu1500 qdisc pfifo_fast qlen 1000
link/ether00:0c:29:0f:e6:64 brd ff:ff:ff:ff:ff:ff
inet172.16.1.1/24 brd 172.16.1.255 scope global eth1
LVS控制虚拟IP地址与后端真实服务器的对应关系:
LVS由ipvsadm来控制配置文件的保存和服务器启动
[root@node220 ~]# service ipvsadm start
Clearing the current IPVS table: [ OK ]
Applying IPVS configuration: [ OK ]
[root@node220 ~]# service ipvsadm status
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
->RemoteAddress:Port ForwardWeight ActiveConn InActConn
TCP 192.168.2.118:80 rr persistent 300
->192.168.2.222:80 Route 10 0 0
[root@node220 ~]# service ipvsadm stop
Clearing the current IPVS table: [ OK ]
[root@node220 ~]# service ipvsadm status
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
->RemoteAddress:Port ForwardWeight ActiveConn InActConn
可以通过service ipvsadm save 将配置信息保存在/etc/sysconfig/ipvsadm中
[root@node220 ~]# service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]