1:下载haproxy
官网:http://www.haproxy.org/
下载地址:http://www.haproxy.org/download/1.7/src/haproxy-1.7.8.tar.gz
创建用户:
useradd -M haproxy
2:安装
tar -zxvf haproxy-1.7..tar.gz -C /usr/local
ln -s haproxy-1.7. haproxy #参数说明
TARGET=linux26 #内核版本,使用uname -r查看内核,如:2.6.-.el5,此时该参数就为linux26;kernel 大于2..28的用:TARGET=linux2628
ARCH=x86_64 #系统位数
PREFIX=/usr/local/haprpxy #/usr/local/haprpxy为haprpxy安装路径 #安装
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
3:配制haproxy.cfg文件
在目录/usr/local/haproxy/下创建haproxy.cfg
global
maxconn
daemon
chroot /usr/local/haproxy
pidfile /var/run/haproxy.pid
#debug
#quiet
user haproxy
group haproxy defaults
log global
mode http
option httplog
option dontlognull
log 127.0.0.1 local0
retries
option redispatch
maxconn
#contimeout
#clitimeout
#srvtimeout
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s listen admin_stats
bind 0.0.0.0:
mode http
stats uri /dbs
stats realm Global\ statistics
stats auth admin:admin listen proxy-mysql
bind 0.0.0.0:
mode tcp
balance roundrobin
option tcplog
# option mysql-check user haproxy #在mysql中创建无任何权限用户haproxy,且无密码
server MySQL1 node1: check weight maxconn
server MySQL2 node2: check weight maxconn
server MySQL3 node3: check weight maxconn
option tcpka
4:启动haproxy
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
5:查看状态
http://node4:8888/dbs
密码:admin/admin
#说明:
#8888即haproxy配置文件中监听端口
#dbs 即haproxy配置文件中的监听名称