编译安装haproxy
wget http://www.haproxy.org/download/1.7/src/haproxy-1.7.11.tar.gz
一、安装
#tar xf haproxy-1.7.11.tar.gz
#cd haproxy-1.7.11
#make TARGET=linux2628 ARCH=x86_64
#make install PREFIX=/data/haproxy
参数说明
TARGET=linux26 #内核版本,使用uname -r查看内核,如:2.6.18-371.el5,此时该参数就为linux26;kernel 大于2.6.28的用:TARGET=linux2628
ARCH=x86_64 #系统位数
PREFIX=/usr/local/haprpxy #/usr/local/haprpxy为haprpxy安装路径
二、配置启动用户
groupadd haproxy
useradd -g haproxy haproxy -s /sbin/nologin
三、配置配置文件
mkdir /data/haproxy/etc
mkdir /data/haproxy/run
cd /data/haproxy/etc
vim haproxy.cfg
global
log 127.0.0.1 local2
pidfile /data/haproxy/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
defaults
mode tcp
log global
option tcplog
option tcpka
retries 3
timeout connect 5s
timeout client 1h
timeout server 1h
listen emq_tcp
bind *:13306
mode tcp
option tcplog
balance roundrobin
server emq1 192.168.3.127:3306 check inter 5000 rise 2 fall 2
server emq2 192.168.3.129:3306 check inter 5000 rise 2 fall 2
listen private_monitoring
bind 0.0.0.0:8100
mode http
option httplog
stats enable
stats uri /admin
stats refresh 30s
stats auth admin:admin
启动:
./haproxy -f …/conf/haproxy.cfg