keepalived切换之后,长链接会断开么
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived切换之后,长链接会断开么相关的知识,希望对你有一定的参考价值。
参考技术A 不会。在使用长连接的情况下,当一个网页打开完成后,客户端和服务器之间用于传输HTTP数据的TCP连接不会关闭,客户端再次访问这个服务器时,会继续使用这一条已经建立的连接。Keep-Alive不会永久保持连接,它有一个保持时间,可以在不同的服务器软件(如Apache)中设定这个时间。实现长连接需要客户端和服务端都支持长连接。
通过keepalived实现 MySQL VIP 自动切换
首先配置keepalived。链接如下:
http://blog.itpub.net/28939273/viewspace-1808369/
主服务器keepalived的配置文件内容如下:
[[email protected] keepalived]# cat keepalived.conf
vrrp_script check_mysql_port {
script "/etc/keepalived/keepalived_check_mysql.sh"
interval 1
weight -10
}
global_defs {
router_id MYSQL_YOON
}
vrrp_instance mysql_yoon_master {
state MASTER
interface eth0
virtual_router_id 245
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass mysql_yoon
}
virtual_ipaddress {
172.16.232.245
}
track_script {
check_mysql_port
}
}
备用服务器keepalived配置文件内容:
[[email protected] keepalived]# cat keepalived.conf
vrrp_script check_mysql_port {
script "/etc/keepalived/keepalived_check_mysql.sh"
interval 1
weight -10
}
global_defs {
router_id MYSQL_YOON
}
vrrp_instance mysql_yoon_master {
state MASTER
interface eth0
virtual_router_id 245
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass mysql_yoon
}
virtual_ipaddress {
172.16.232.245
}
track_script {
check_mysql_port
}
}
在/etc/keepalived/下创建keepalived_check_mysql.sh
[[email protected] keepalived]# vi keepalived_check_mysql.sh
#!/bin/bash
MYSQL=/export/servers/mysql/bin/mysql
MYSQL_HOST=127.0.0.1 #如何在执行过程中,keepalived进程莫名自动关闭的话,尝试将127.0.0.1改成localhost,我是由localhsot改成了127.0.0.1才可以,一定要注意
MYSQL_USER=root
MYSQL_PASSWORD=yoon
CHECK_TIME=3
#mysql is working MYSQL_OK is 1 , mysql down MYSQL_OK is 0
MYSQL_OK=1
function check_mysql_helth (){
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD} -e "show status;" >/dev/null 2>&1
if [ $? = 0 ] ;then
MYSQL_OK=1
else
MYSQL_OK=0
fi
return $MYSQL_OK
}
while [ $CHECK_TIME -ne 0 ]
do
let "CHECK_TIME -= 1"
check_mysql_helth
if [ $MYSQL_OK = 1 ] ; then
CHECK_TIME=0
exit 0
fi
if [ $MYSQL_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ]
then
/etc/init.d/keepalived stop
exit 1
fi
sleep 1
done
并在备用服务器上也创建同样的脚本
以上是关于keepalived切换之后,长链接会断开么的主要内容,如果未能解决你的问题,请参考以下文章