MASTER级配置:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 100
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.23.52.200
}
}
virtual_server 10.23.52.200 80{
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 1
protocol TCP
real_server 10.23.52.113 80{
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_:retry 3
}
}
real_server 10.23.52.114 80{
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
查看监听情况:
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.23.52.200:80 wrr persistent 1
-> 10.23.52.113:80 Route 1 0 0
-> 10.23.52.114:80 Route 1 0 0
[root@localhost keepalived]#
查看日志:
[root@localhost keepalived]# tail -f /var/log/messages
Mar 6 10:31:25 localhost kernel: IPVS: [wrr] scheduler registered.
Mar 6 10:31:26 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar 6 10:31:27 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Mar 6 10:31:27 localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Mar 6 10:31:27 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.23.52.200
Mar 6 10:31:32 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.23.52.200
Mar 6 10:32:08 localhost Keepalived_healthcheckers: TCP connection to [10.23.52.113]:80 failed !!!
Mar 6 10:32:08 localhost Keepalived_healthcheckers: Removing service [10.23.52.113]:80 from VS [10.23.52.200]:80
Mar 6 10:32:20 localhost Keepalived_healthcheckers: TCP connection to [10.23.52.113]:80 success.
Mar 6 10:32:20 localhost Keepalived_healthcheckers: Adding service [10.23.52.113]:80 to VS [10.23.52.200]:80
访问真是IP:
[root@localhost keepalived]# curl 10.23.52.113
<!DOCTYPE html>
Welcome to nginx! body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.我是113号机器
[root@localhost keepalived]#
访问VIP一直没有反应:
[root@localhost keepalived]# curl 10.23.52.200
curl: (7) couldn't connect to host
[root@localhost keepalived]#