搭建haproxy
Posted 为生活而努力
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建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
以上是关于搭建haproxy的主要内容,如果未能解决你的问题,请参考以下文章
基于HAProxy+Keepalived高可用负载均衡web服务的搭建
Haproxy+etcd+confd+Docker搭建节点自动发现的高可用负载均衡框架