环境:
系统:centos7
ip:172.16.22.221 test221 master
ip:172.16.22.222 test222 backup
VIP:172.16.22.219
同时安装keepalived
# yum install -y keepalived
都安装nginx,这里已经编译安装过了
如果没有可以使用yum快速安装
编辑监控脚本
[root@test221 ~]# vim /usr/local/sbin/check_ng.sh
#!/bin/bash
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq "0" ]; then
/etc/init.d/nginx start
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
[root@test221 ~]# chmod +x !$
chmod +x /usr/local/sbin/check_ng.sh
编辑keepalived配置文件
[root@test221 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
donxan@gmail.com
}
notification_email_from root@test221
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/usr/local/sbin/check_ng.sh"
interval 3
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass aiker>com
}
virtual_ipaddress {
172.16.22.219
}
track_script {
chk_nginx
}
}
[root@test221 ~]# systemctl stop nginx
[root@test221 ~]# systemctl start keepalived.service
[root@test221 ~]# ps aux | grep nginx
root 28553 0.0 0.0 4188 348 ? Ss 3月17 0:00 runsv nginx
root 28554 0.0 0.0 4332 348 ? S 3月17 0:00 svlogd -tt /var/log/gitlab/nginx
root 29249 0.0 0.0 37616 3012 ? Ss 3月17 0:00 nginx: master process /opt/gitlab/embedded/sbin/gitlab-web -p /var/opt/gitlab/nginx
gitlab-+ 29250 0.0 0.0 41708 5436 ? S 3月17 0:00 nginx: worker process
gitlab-+ 29251 0.0 0.0 41708 5436 ? S 3月17 0:17 nginx: worker process
gitlab-+ 29252 0.0 0.0 41708 5436 ? S 3月17 0:17 nginx: worker process
gitlab-+ 29253 0.0 0.0 41708 5436 ? S 3月17 0:17 nginx: worker process
gitlab-+ 29254 0.0 0.0 37768 1492 ? S 3月17 0:01 nginx: cache manager process
root 29940 0.0 0.0 111180 9920 ? Ss 22:39 0:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
www 29941 0.0 0.2 141900 34916 ? S 22:39 0:00 nginx: worker process
www 29943 0.0 0.2 141900 34916 ? S 22:39 0:00 nginx: worker process
www 29946 0.0 0.2 141900 34912 ? S 22:39 0:00 nginx: worker process
www 29947 0.0 0.2 141900 34916 ? S 22:39 0:00 nginx: worker process
www 29948 0.0 0.0 111180 10256 ? S 22:39 0:00 nginx: cache manager process
www 29949 0.0 0.0 111180 10256 ? S 22:39 0:00 nginx: cache loader process
root 30043 0.0 0.0 110248 900 pts/1 S+ 22:39 0:00 grep --color=auto nginx
[root@test221 ~]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:39:41 CST; 1min 22s ago
Process: 29926 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 29927 (keepalived)
CGroup: /system.slice/keepalived.service
├─29927 /usr/sbin/keepalived -D
├─29928 /usr/sbin/keepalived -D
├─29929 /usr/sbin/keepalived -D
├─29940 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
├─29941 nginx: worker process
├─29943 nginx: worker process
├─29946 nginx: worker process
├─29947 nginx: worker process
└─29948 nginx: cache manager process
3月 25 22:39:42 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:42 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:42 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:42 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
[root@test221 ~]#
从配置:
[root@test222 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
donxan@gmail.com
}
notification_email_from root@test222
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/usr/local/sbin/check_ng.sh"
interval 3
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass aiker>com
}
virtual_ipaddress {
172.16.22.219
}
track_script {
chk_nginx
}
}
~
[root@test222 ~]# mv backup_check_ng.sh /usr/local/sbin/check_ng.sh
[root@test222 ~]# vim !$
vim /usr/local/sbin/check_ng.sh
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq "0" ]; then
service nginx start
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
[root@test222 ~]# chmod +x !$
chmod +x /usr/local/sbin/check_ng.sh
[root@test222 ~]# service nginx stop
Stoping nginx... done
[root@test222 ~]# ps aux | grep nginx
root 16906 0.0 0.0 110244 896 pts/2 S+ 22:47 0:00 grep --color=auto nginx
[root@test222 ~]# systemctl start keepalived
[root@test222 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:47:48 CST; 31s ago
Process: 16913 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 16914 (keepalived)
CGroup: /system.slice/keepalived.service
├─10576 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─10577 nginx: worker process
├─10578 nginx: worker process
├─10579 nginx: worker process
├─10580 nginx: worker process
├─10581 nginx: cache manager process
├─10582 nginx: cache loader process
├─10593 /usr/sbin/keepalived -D
├─10594 /usr/sbin/keepalived -D
└─10595 /usr/sbin/keepalived -D
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: Registering Kernel netlink command channel
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: Registering gratuitous ARP shared channel
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: Opening file '/etc/keepalived/keepalived.conf'.
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: Truncating auth_pass to 8 characters
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) removing protocol VIPs.
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: Using LinkWatch kernel netlink reflector...
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Entering BACKUP STATE
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
3月 25 22:47:48 test222 Keepalived_vrrp[16916]: VRRP_Script(chk_nginx) succeeded
Hint: Some lines were ellipsized, use -l to show in full.
[root@test222 ~]# ps aux | grep nginx
root 16930 0.0 0.0 108620 3180 ? Ss 22:47 0:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
www 16931 0.0 0.1 139340 29248 ? S 22:47 0:00 nginx: worker process
www 16932 0.0 0.1 139340 29248 ? S 22:47 0:00 nginx: worker process
www 16933 0.0 0.1 139340 29248 ? S 22:47 0:00 nginx: worker process
www 16934 0.0 0.1 139340 29248 ? S 22:47 0:00 nginx: worker process
www 16935 0.0 0.0 108620 3868 ? S 22:47 0:00 nginx: cache manager process
www 16936 0.0 0.0 108620 3616 ? S 22:47 0:00 nginx: cache loader process
root 17052 0.0 0.0 110248 900 pts/2 S+ 22:48 0:00 grep --color=auto nginx
[root@test222 ~]#
一、测试:master停掉keepalived
[root@test221 ~]# systemctl stop keepalived.service
[root@test221 ~]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: inactive (dead) since 日 2018-03-25 22:51:35 CST; 6s ago
Process: 29926 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 29927 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/keepalived.service
├─29940 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
├─29941 nginx: worker process
├─29943 nginx: worker process
├─29946 nginx: worker process
├─29947 nginx: worker process
└─29948 nginx: cache manager process
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:39:47 test221 Keepalived_vrrp[29929]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:34 test221 systemd[1]: Stopping LVS and VRRP High Availability Monitor...
3月 25 22:51:34 test221 Keepalived[29927]: Stopping
3月 25 22:51:34 test221 Keepalived_healthcheckers[29928]: Stopped
3月 25 22:51:34 test221 Keepalived_vrrp[29929]: VRRP_Instance(VI_1) sent 0 priority
3月 25 22:51:34 test221 Keepalived_vrrp[29929]: VRRP_Instance(VI_1) removing protocol VIPs.
3月 25 22:51:35 test221 Keepalived_vrrp[29929]: Stopped
3月 25 22:51:35 test221 Keepalived[29927]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
3月 25 22:51:35 test221 systemd[1]: Stopped LVS and VRRP High Availability Monitor.
[root@test221 ~]#
backup:
[root@test222 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:47:48 CST; 4min 11s ago
Process: 16913 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 16914 (keepalived)
CGroup: /system.slice/keepalived.service
├─10576 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─10577 nginx: worker process
├─10578 nginx: worker process
├─10579 nginx: worker process
├─10580 nginx: worker process
├─10581 nginx: cache manager process
├─10582 nginx: cache loader process
├─10593 /usr/sbin/keepalived -D
├─10594 /usr/sbin/keepalived -D
└─10595 /usr/sbin/keepalived -D
3月 25 22:51:35 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:35 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:35 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:35 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:51:40 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
backup keepalived已经启动VIP
重启master keepalived,vip重新切回到master
[root@test221 ~]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:57:13 CST; 10min ago
Process: 11476 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 11477 (keepalived)
CGroup: /system.slice/keepalived.service
├─11477 /usr/sbin/keepalived -D
├─11478 /usr/sbin/keepalived -D
├─11479 /usr/sbin/keepalived -D
├─16046 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
├─16047 nginx: worker process
├─16048 nginx: worker process
├─16049 nginx: worker process
├─16050 nginx: worker process
└─16052 nginx: cache manager process
3月 25 22:57:15 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:15 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:15 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:15 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 25 22:57:20 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
二、master停掉Nginx
[root@test221 ~]# service nginx stop
Stoping nginx... done
[root@test221 ~]# ps aux | grep nginx
root 16037 0.0 0.0 110244 900 pts/1 S+ 23:02 0:00 grep --color=auto nginx
root 28553 0.0 0.0 4188 348 ? Ss 3月17 0:00 runsv nginx
root 28554 0.0 0.0 4332 348 ? S 3月17 0:00 svlogd -tt /var/log/gitlab/nginx
[root@test221 ~]# ps aux | grep nginx
root 16046 0.0 0.0 111180 4692 ? Ss 23:02 0:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
www 16047 0.0 0.1 141900 29232 ? S 23:02 0:00 nginx: worker process
www 16048 0.0 0.1 141900 29232 ? S 23:02 0:00 nginx: worker process
www 16049 0.0 0.1 141900 29232 ? S 23:02 0:00 nginx: worker process
www 16050 0.0 0.1 141900 29232 ? S 23:02 0:00 nginx: worker process
www 16052 0.0 0.0 111180 5028 ? S 23:02 0:00 nginx: cache manager process
www 16055 0.0 0.0 111180 5028 ? S 23:02 0:00 nginx: cache loader process
root 16106 0.0 0.0 110244 900 pts/1 S+ 23:02 0:00 grep --color=auto nginx
root 28553 0.0 0.0 4188 348 ? Ss 3月17 0:00 runsv nginx
root 28554 0.0 0.0 4332 348 ? S 3月17 0:00 svlogd -tt /var/log/gitlab/nginx
[root@test221 ~]#
Nginx停止后,keepalived会自动检查重启Nginx
3、关闭master防火墙vrrp,
[root@test221 ~]# iptables -I OUTPUT -p vrrp -j DROP
[root@test221 ~]# systemctl status keepalived.service -l
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:57:13 CST; 18h ago
Process: 11476 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 11477 (keepalived)
CGroup: /system.slice/keepalived.service
├─11477 /usr/sbin/keepalived -D
├─11478 /usr/sbin/keepalived -D
├─11479 /usr/sbin/keepalived -D
├─16046 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─16047 nginx: worker process
├─16048 nginx: worker process
├─16049 nginx: worker process
├─16050 nginx: worker process
└─16052 nginx: cache manager process
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: VRRP_Instance(VI_1) Received advert with lower priority 90, ours 100, forcing new election
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:24:40 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
查看backup keepalived status
[root@test222 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:47:48 CST; 18h ago
Process: 16913 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 16914 (keepalived)
CGroup: /system.slice/keepalived.service
├─10576 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─10577 nginx: worker process
├─10578 nginx: worker process
├─10579 nginx: worker process
├─10580 nginx: worker process
├─10581 nginx: cache manager process
├─10582 nginx: cache loader process
├─10593 /usr/sbin/keepalived -D
├─10594 /usr/sbin/keepalived -D
└─10595 /usr/sbin/keepalived -D
3月 26 17:17:54 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:54 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:54 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:54 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
master删除刚才添加的iptables规则
[root@test221 ~]# iptables -D OUTPUT 1
[root@test221 ~]# systemctl status keepalived.service -l
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:57:13 CST; 18h ago
Process: 11476 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 11477 (keepalived)
CGroup: /system.slice/keepalived.service
├─11477 /usr/sbin/keepalived -D
├─11478 /usr/sbin/keepalived -D
├─11479 /usr/sbin/keepalived -D
├─16046 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─16047 nginx: worker process
├─16048 nginx: worker process
├─16049 nginx: worker process
├─16050 nginx: worker process
└─16052 nginx: cache manager process
3月 26 17:33:07 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:07 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:07 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:07 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:08 test221 Keepalived_vrrp[11479]: Sending gratuitous ARP on eth0 for 172.16.22.219
backup上查看keepalived status
[root@test222 ~]# systemctl status keepalived -l
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2018-03-25 22:47:48 CST; 18h ago
Process: 16913 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 16914 (keepalived)
CGroup: /system.slice/keepalived.service
├─10576 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.con
├─10577 nginx: worker process
├─10578 nginx: worker process
├─10579 nginx: worker process
├─10580 nginx: worker process
├─10581 nginx: cache manager process
├─10582 nginx: cache loader process
├─10593 /usr/sbin/keepalived -D
├─10594 /usr/sbin/keepalived -D
└─10595 /usr/sbin/keepalived -D
3月 26 17:17:54 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:17:59 test222 Keepalived_vrrp[16916]: Sending gratuitous ARP on eth0 for 172.16.22.219
3月 26 17:33:03 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 90
3月 26 17:33:03 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) Entering BACKUP STATE
3月 26 17:33:03 test222 Keepalived_vrrp[16916]: VRRP_Instance(VI_1) removing protocol VIPs.
转载于:https://blog.51cto.com/m51cto/2091360