搭建haproxy
1:下载haproxy
wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz
2:解压,编译,安装
tar zxf haproxy-1.3.20.tar.gz
cd haproxy-1.3.20
uname -a
make TARGET=linux2.6 PREFIX=/usr/local/product/haproxy-1.3.20
make install PREFIX=/usr/local/product/haproxy-1.3.20
3:ln -s /usr/local/product/haproxy-1.5.9 /usr/local/haproxy
4:创建haproxy配置文件
mkdir /etc/haproxy
cd /etc/haproxy
vi haproxy.cfg
########################
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user www
group www
daemon
nbproc 8
#debug
#quiet
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 50000
timeout client 50000
timeout server 50000
#Ha代理mysql
listen mysql_db 0.0.0.0:3306
server db_1 rdsh0t197b6ly9dth6c5.mysql.rds.aliyuncs.com:3306 check inter 2000 rise 2 fall 5
#Ha代理http
listen http_app 0.0.0.0:8080
mode http
option httplog
balance roundrobin
server app1 172.21.8.188:80 cookie app1 weight 5 check inter 2000 rise 2 fall 3
5:启动haproxy
/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg
6:haproxy 启动
cp /haproxy-1.3.20/examples/haproxy.init /etc/init.d/haproxy
cp /usr/local/haproxy/sbin/haproxy /usr/sbin/
chmod a+x /etc/init.d/haproxy