#######################################################################################
一、keepalived安装(主备机器安装方法一样)
wget
tar zxvf popt-1.16.tar.gz
cd popt-1.16
./configure
make && make install
wget
tar zxvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure --prefix=/usr/local/keepalived
make && make install
二、初始化脚本
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir -p /etc/keepalived/
ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
chmod +x /etc/init.d/keepalived
三、主机器配置文件(vi /etc/keepalived/keepalived.conf ),备机器只要(修改有注释地方即可)
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/usr/local/keepalived/check_haproxy.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER (备机,改MASTER为BACKUP)
interface eth0
virtual_router_id 51
priority 150 (备机,改150为149)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
10.1.1.60
}
}
四、检测haproxy状态的文件
status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
if [ "${status}" = "0" ]; then
/etc/init.d/haproxy start
status2=$(ps aux|grep haproxy | grep -v grep | grep -v bash |wc -l)
if [ "${status2}" = "0" ]; then
/etc/init.d/keepalived stop
fi
fi
五、启动keepalived
/etc/init.d/keepalived start
HAproxy 的详细介绍:请点这里
HAproxy 的下载地址:请点这里
推荐阅读:
Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
CentOS 6.3下Haproxy+Keepalived+Apache配置笔记
Haproxy + KeepAlived 实现WEB群集 on CentOS 6