Haproxy performs Load Balancing for mysql and haproxymysql
1. First install haproxywget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gztar zcvf haproxy-1.4.24.tar.gzcd haproxy-1.4.24Make TARGET = linux26 PREFIX =/usr/local/haproxy # Install haproxy on/usr/local/haproxymake install PREFIX=/usr/local/haproxy# The PREFIX must be in uppercase; otherwise, it cannot be installed in the specified directory/usr/local/haproxy.2. Create the haproxy. cfg configuration file under/usr/local/haproxy/etc. Content:
global log 127.0.0.1Local0 info # log related log 127.0.0.1local1 notice maxconn 4096 chroot /usr/local/haproxy uid root gid root daemon #debug #quiet pidfile /usr/local/haproxy/haproxy.pid defaults log global mode http #option httplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen mysql bind 0.0.0.0:23306# Proxy Port Mode tcp # mode TCP Option mysql-check user root # mysql health check root is the mysql Login user Name Balance roundrobin # Scheduling Algorithm server mysql1 192.168.153.128:3306 weight 1 check inter 1s rise 2 fall 2 # Health check plus check server mysql2 192.168.153.134:3306 weight 1 check inter 1s rise 2 fall 2Listen stats # monitoring mode http bind 0.0.0.0:8888 stats enable stats uri /dbs stats realm Global\ statistics stats auth admin:admin
# Option mysql-check user root # comment out the mysql health check root as the mysql Login user Name
Start mysql service for both users. 3. Start [root @ web2 etc] #/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/etc/haproxy. cfg
[Root @ web2 etc] # cd ../sbin/
[Root @ web2 sbin] # ls
Haproxy
[Root @ web2 sbin] # ps-ef | grep haproxy
Root 4223 1 0 18:12? 00:00:00/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/etc/haproxy. cfg
Root 4228 3754 0 00:00:00 pts/0 grep haproxy
[Root @ web2 sbin] #4. Access ip: 8888/dbs enter admin to log on