1. Installation
# yum Install Haproxy
2. Modify the configuration
# vim/etc/haproxy/haproxy.cfg
Configured as follows
global daemon nbproc 1 pidfile /var/run/ haproxy.piddefaults mode tcp #默认的模式mode { tcp|http|health },tcp is 4 layer, HTTP is 7 layer, health will only return OK retries 3 #两次连接失败就认为是服务器不可用, you can also set option by the rear redispatch #当serverId对应的服务器挂掉后, force directed to other healthy servers option abortonclose #当服务器负载很高的时候, Automatically end the current queue processing longer links maxconn 4096 #默认的最大连接数 timeout connect 5000ms #连接超时 timeout client 30000ms #客户端超时 timeout server 30000ms #服务器超时 timeout check 2000 #= Heartbeat Detection Timeout log globallisten mysql_cluster bind 10.10.91.71:3306 mode tcp Maxconn 4086 server node2 10.10.91.72:3306 server node3 10.10.91.75:3306
3. Start
#/etc/init.d/haproxy Start
4. View status
#/etc/init.d/haproxy Status
Points to note:
1, Port 3306 can not be occupied, if the machine has MySQL, the service must be closed.
2,/var/run/haproxy.pid directory permissions to enough, if there is haproxy.pid before the first boot must be deleted.
3, other errors please refer to the blog http://blog.csdn.net/aa168b/article/details/50372649
Haproxy does not need to write the MySQL health test, the software itself can detect the MySQL service stopped, and then switch to the normal server, and when the MySQL server restarts, the Haproxy does not need to restart, but also can identify and switch up.
Haproxy implementing MySQL Cluster load Balancing