nginx+keepalived

vi/etc/keepalived/keepalived.conf

global_defs{

notification_email{

[email protected]

}

[email protected]

smtp_servermail.abc.com

smtp_connect_timeout30

router_idLVS_DEVEL

}

vrrp_scriptchk_nginx{

script"/etc/keepalived/chk_nginx.sh"

interval2

weight2

}

vrrp_instanceVI_1{

stateMASTER

interfaceeth0

virtual_router_id51

priority101

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

track_script{

chk_nginx#监测nginx进程状态

}

virtual_ipaddress{

172.16.33.123

}

}

vi/etc/keepalived/chk_nginx.sh

#!/bin/sh

#checknginxserverstatus

NGINX=/usr/local/nginx/sbin/nginx

PORT=80

nmaplocalhost-p$PORT|grep"$PORT/tcpopen"

if[$?-ne0];then

/etc/init.d/keepalivedstop

fi