Haproxy implementing MySQL Slave Library load Balancing

Source: Internet
Author: User
Tags mysql load balancing haproxy

This article mainly describes the implementation of MySQL from the library through Haproxy load balancing, as for MySQL master-slave construction, this article no longer repeat, you can refer to my previous blog. 1. Download the Haproxy package first
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.13.tar.gz

2. Installation
tar zxvf haproxy-1.4. . Tar . GZCD haproxy-1.4. /Make target=linux26 prefix=/usr/local/haproxy # #我的系统内核为2. 6, so target=linux26makeinstall Prefix=/usr/local/haproxy

3. Configure
mkdir /etc/haproxytouch /etc/haproxy/haproxy.cfgvi /etc/haproxy/ Haproxy.cfg
# #写入以下内容:
Global Daemon Nbproc1Pidfile/var/run/haproxy.piddefaults Mode tcp #默认的模式mode {TCP|http|Health },tcp is Layer 4, HTTP is 7 layer, health will return OK retries2#两次连接失败就认为是服务器不可用, you can also force direct to other healthy servers by setting the option Redispatch #当serverId对应的服务器挂掉后 later opt Ion Abortonclose #当服务器负载很高的时候, automatically end the current queue processing more than the long link maxconn4096#默认的最大连接数 Timeout Connect 5000ms #连接超时 timeout client 30000ms #客户端超时 Timeout server 30000ms #服务器超时 #timeout Check -#=heartbeat detection Timeout log127.0.0.1Local0 Err #[err WarningInfodebug]####### #test1配置 ################ #listen test1 bind0.0.0.0:3306Mode TCP #maxconn4086#log127.0.0.1local0 Debug Server S1192.168.103.59:3306Server S2192.168.103.52:3306####### #frontend配置 ##############
Under the Test1 configuration, add the server S1 192.168.103.59:3306 and server S2 192.168.103.52:3306, which is the MySQL IP and port number from the library, and multiple additions from the library continue below. 4. Start Haproxy inunzip the directory to execute haproxy-f/etc/haproxy/haproxy.cfgFirst stop the program that occupies Port 3306 haproxy-f/etc/haproxy/haproxy.cfg (if prompt error: bash:haproxy: Command not foundPerform1 cd/usr/local/haproxy/sbin 2./haproxy-f/etc/haproxy/haproxy.cfg  5. Test using NAVICAT connection to install the Haproxy machine first connected to the 52 close connection, re-connect 103.55 visible to achieve MySQL load balancing. 6. Other considerations View Haproxy's Process Ps-ef | grep haproxy kill-9 28924 kill Haproxy running process and connect 55 failed View All processes ps-ef Modify configuration file: Restart Haproxy:

Haproxy implementing MySQL Slave Library load Balancing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.