基于Keepalived+Haproxy搭建四层负载均衡器

转自:http://www.net130.com/CMS/Pub/special/special_fzjh/special_fzjh_fa/2011_06_16_3578.htm

一、前言
       Haproxy是稳定、高性能、高可用性的负载均衡解决方案,支持HTTP及TCP代理后端服务器池,因支持强大灵活的7层acl规则,广泛作为HTTP反向代理。本文则详细介绍如何利用它的四层交换与Keepalived实现一个负载均衡器,适用于Socket、ICE、Mail、Mysql、私有通讯等任意TCP服务。系统架构图如下:


 

二、平台环境


OS:Centos5.4(64X)
MASTER:192.168.0.20
BACKUP:192.168.0.21
VIP:192.168.0.100
Serivce Port:11231


三、平台安装配置
1、添加非本机IP邦定支持


#vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1
#sysctl �Cp


2、配置平台日志支持


#vi /etc/syslog.conf
添加:
local3.*        /var/log/haproxy.log
local0.*        /var/log/haproxy.log

#vi /etc/sysconfig/syslog
修改:
SYSLOGD_OPTIONS="-r -m 0"
#/etc/init.d/syslog restart


3、关闭SELINUX


vi /etc/sysconfig/selinux
修改:
SELINUX=disabled
#setenforce 0


4、配置iptables,添加VRRP通讯支持

iptables -A INPUT -d 224.0.0.18 -j ACCEPT


也可以编辑/etc/sysconfig/iptables文件 在倒数第三行添加-A INPUT -d 224.0.0.18 -j ACCEPT


5、Keepalived的安装、配置


#mkdir -p /home/install/keepalivedha
#cd /home/install/keepalivedha
#wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz
#tar zxvf keepalived-1.2.2.tar.gz
#cd keepalived-1.2.2
#./configure
#make && make install


 


#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/


你可能感兴趣的:(keepalived)