Keepalived+HAProxy配置高可用负载均衡,解决keepalived无法安装问题。
1 系统环境
Keepalived-1.2.2 :keepalived-1.2.2.tar.gz
OS: CentOS 5.7
HAProxy:haproxy-1.4.20.tar.gz
具体下载目录在 /2012年资料/3月/15日/Keepalived+HAProxy配置高可用负载均衡/
我的ip环境:
haproxy keepalived 主:192.168.200.104:1080
haproxy keepalived 备:192.168.200.101:1080
vip:192.168.200.181
web:192.168.200.104:8080 192.168.200.104:9090
1.tar -zxvf keepalived-1.2.2.tar.gz
2.cd keepalived-1.2.2
3../configura --prefix=/
执行这一步可能出现如下错误: configure: error: !!! OpenSSL is not properly installed on your system. !!! !!! Can not include OpenSSL headers files. 解决办法: [root@master ~]# yum -y install openssl-devel
4.make && make install
5.cd /etc/keepalived/
6.mv keepalived.conf keepalived.conf.default
7.vi keepalived.conf
vrrp_script chk_http_port { script /etc/keepalived/check_haproxy.sh" Interval 2 weight 2 global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER #192.168.200.104,在192.168.200.101上则改为BACKUP interface eth0 virtual_router_id 51 priority 200 #192.168.200.104,在192.168.200.101上则改为100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { chk_http_port } virtual_ipaddress { 192.168.200.181 } }
8.vi /etc/keepalived/check_haproxy.sh
#!/bin/bash A=`ps -C haproxy --no-header |wc -l` if [ $A -eq 0 ];then /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg sleep 3 if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then /etc/init.d/keepalived stop fi fi
9.chmod 755 /etc/keepalived/check_haproxy.sh
3 安装HAProxy 4 测试1./etc/init.d/keepalived start (这条命令会自动把haproxy启动)