It你好linux 学习文档之haproxy 学习笔记 itnihao@ .com
It你好linux 学习文档之haproxy 学习笔记V1.0
一,haproxy的功能
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第 应用的软负载实现。
LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载。
HAProxy相比LVS的使用要简单很多,功能方面也很丰富。当前,HAProxy支持两种主要的 模
式:"tcp"也即4层(大多用于邮件 、内部协议通信 等),和7层(HTTP)。在4层模式下,HAproxy
仅在 端和 之间转发双向流量。7层模式下,HAProxy会分析协议,并且能通过允许、拒绝、交换、
增加、修改或者删除请求(request)或者回应(response)里指定内容来控制协议,这种操作要基于特定规则。
详情可以在HAProxy 官方网站( )可以 配置说明文档(configuration.txt)和架构文
件(architecture.txt)作为 。
二,haproxy的安装
haproxy软件的安装
#!/bin/bash
#this is workonrhel6.X centos6.XOK,if in rhel5.X ,youshould configure logs foryourself
#date 2012-06-18
#authoritnihao
ha_install (){
#wget
./etc/init.d/functions
tarxvfhaproxy-1.4.21.tar.gz
cdhaproxy-1.4.21
make TARGET=linux26 PREFIX=/usr/local
make install PREFIX=/usr/local
cd../
[-d/etc/haproxy ]&&mkdir /etc/haproxy
#copyexaplesfile
cp-rfexamples//etc/haproxy/
cp-rftests//etc/haproxy/
#mkdir /var/log/haproxy
mkdir /var/haproxy
#copyconfigure file
cpconf/haproxy.init /etc/init.d/haproxy
cpconf/haproxy/etc/haproxy/haproxy.cfg
#add default services
chmod755/etc/init.d/haproxy
chkconfig--addhaproxy
chkconfig--level 345 haproxyon
servicehaproxyrestart
It你好linux 学习文档之haproxy 学习笔记 itnihao@ .com
}
r _ha (){
#add haproxylog
cat>>/etc/r .conf<< EOF
\$ModLoad imudp
\$UDPServerRun514
\$UDPServerAddress
local3.* /var/log/haproxy.log
EOF
#add haproxy.log
cat>/etc/logrotate.d/haproxy.cfg<< EOF
/var/log/haproxy.log
{
rotate4
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
reload r >/dev/null 2>&1||true
endscript
}
EOF
}
ha_