分类: 系统运维
2014-04-02 10:02:20
分别在两台服务器安装Nginx、keepalived,如下:
yum install -y pcre-devel 安装perl 兼容的正规表达式库
tar -xzf nginx-1.2.4.tar.gz && cd nginx-1.2.4 ; sed -i -e 's/1.2.2//g' -e 's/nginx\//TDTWS/g' -e 's/"NGINX"/"TDTWS"/g' src/core/nginx.h &&./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
tar -xzvf keepalived-1.2.1.tar.gz &&cd keepalived-1.2.1 && ./configure && make && make install
if
[ $? -eq 0 ];then
echo "Install keepalived success,please waiting configure keepalived ..............."
else
echo "Install keepalived failed ,please check install version !"
exit 0
fi
DIR=/usr/local/ ;cp $DIR/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ ; cp $DIR/etc/sysconfig/keepalived /etc/sysconfig/ ; mkdir -p /etc/keepalived ; cp $DIR/sbin/keepalived /usr/sbin/
! Configuration File for keepalived
global_defs {
notification_email {
wgkgood@163.com
}
notification_email_from wgkgood@163.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/data/sh/check_nginx.sh"
interval 2
weight 2
}
# VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_typePASS
auth_pass 1111
}
virtual_ipaddress {
192.9.117.162
}
track_script {
chk_nginx
}
}
#!/bin/bash
#auto check nginx process
#2012-10-16 wugk
killall -0 nginx
if
[[ $? -ne 0 ]];then
/etc/init.d/keepalived stop
fi