haproxy简单配制for mysql

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.8.tar.gz -C /usr/local
ln -s haproxy-1.7.8 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安装路径

#安装
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 4096
        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 3
        option redispatch
        maxconn 2000
        #contimeout      5000
        #clitimeout      50000
        #srvtimeout      50000
        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:8888
        mode        http
        stats uri   /dbs
        stats realm     Global statistics
        stats auth  admin:admin

listen  proxy-mysql
        bind 0.0.0.0:3306
        mode tcp
        balance roundrobin
        option tcplog
       # option mysql-check user haproxy #在mysql中创建无任何权限用户haproxy,且无密码
        server MySQL1 node1:3306 check weight 1 maxconn 2000
        server MySQL2 node2:3306 check weight 1 maxconn 2000
        server MySQL3 node3:3306 check weight 1 maxconn 2000
        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配置文件中的监听名称
原文地址:https://www.cnblogs.com/feiyun126/p/7270528.html