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

实现keepalived + tomcat 双机热备

时间:2017-05-17 19:20:24      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:ipaddr   bond0   weight   查询   tcp   virt   round   notify   ace   

1.安装keepalived

我这里是给予keepalived+mysql 主主双机热备基础上做的

global_defs {
router_id HA_MySQL
}

vrrp_instance VI_1 {
state BACKUP
interface bond0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.69.37.119
}
track_script {
chk_tomcat
}
}

virtual_server 10.69.37.119 3306 {
delay_loop 2
# lb_algo rr
# lb_kind NAT
persistence_timeout 20
protocol TCP
real_server 10.69.37.75 3306{
weight 3
notify_down /usr/local/keepalived_sh/keepalived_shoudown.sh
TCP_CHECK {
connect_timeout 4
nb_get_retry 3
delay_before_retry 3
}
}
}

vrrp_script chk_tomcat {
#script "killall -0 nginx"
script "/usr/local/keepalived_sh/tomcat_check.sh"
interval 2
weight -5
fall 3
rise 2
}

下面是tomcat_check.sh

#!/bin/bash
JAVA_PROCESS=`ps -C java --no-heading| wc -l`
if [ $JAVA_PROCESS -eq 0 ];then
echo "tomcat is stop"
sleep 2
if [ `ps -C java --no-heading| wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
fi
fi

结束

ps -C java --no-heading| wc -l 

这个命令是查询tomcat是否存在  结果为0不存在为1存在

 

实现keepalived + tomcat 双机热备

标签:ipaddr   bond0   weight   查询   tcp   virt   round   notify   ace   

原文地址:http://www.cnblogs.com/lqCnblog/p/6868983.html

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