标签:
keepalived对nginx高可用演练脚本
参考文章:http://deidara.blog.51cto.com/400447/302402/
1、安装nginx、keepalived、epel-release源 yum install -y epel-release yum install -y nginx yum install -y keepalived 2、配置好nginx 3、设置keepalived配置文件 #主机 vi /etc/keepalived/keepalived.conf vrrp_script chk_nginx { script "/usr/local/nginx_pid.sh" interval 2 fall 2 #测试失败的次数 rise 1 #测试成功的次数 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 5 authentication { auth_type PASS auth_pass eric } track_script { chk_nginx } virtual_ipaddress { 192.168.14.206 } } #备机 vi /etc/keepalived/keepalived.conf vrrp_script chk_nginx { script "/usr/local/nginx_pid.sh" interval 2 fall 2 rise 1 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 99 advert_int 5 authentication { auth_type PASS auth_pass eric } track_script { chk_nginx } virtual_ipaddress { 192.168.14.206 } } 4、自备都建nginx_chk脚本 vi /opt/nginx_chk.sh #!/bin/bash # version 0.0.2 A=`ps -C nginx --no-header |wc -l` if [ $A -eq 0 ];then /usr/local/nginx/sbin/nginx sleep 3 if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then killall keepalived ## 则结束 keepalived 进程 fi fi chmod +x /opt/nginx_pid.sh 5、启动nginx和keepalived /etc/init.d/nginx start /etc/init.d/keepalived start 6、查看日志和ip ip addr tailf /var/log/messages 7、故障演练 killall nginx tailf /var/log/messages #查看两边的日志
标签:
原文地址:http://www.cnblogs.com/MYSQLZOUQI/p/5345850.html