实现keepalived + tomcat 双机热备
Posted lq_cnblogs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现keepalived + tomcat 双机热备相关的知识,希望对你有一定的参考价值。
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 双机热备的主要内容,如果未能解决你的问题,请参考以下文章
群集架构篇 ?——nginx反向代理+keepalived双机热备+tomcat服务器池+后端数据库