码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived对nginx高可用演练脚本

时间:2016-04-01 20:15:14      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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  #查看两边的日志







   

 

keepalived对nginx高可用演练脚本

标签:

原文地址:http://www.cnblogs.com/MYSQLZOUQI/p/5345850.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!