Install Haproxy under Redhat

Source: Internet
Author: User
Tags haproxy
install Haproxy under Redhat

First view the system kernel version number and system name

Uname-a
Linux rh64pfcrm01kf 2.6.32-358.el6.x86_64 #1 SMP Tue, 11:47:41 EST 2013 x86_64 x86_64 x86_64 gnu/linux
Haproxy Installation

Haproxy official website Download source code installation package http://www.haproxy.org/download/1.7/src/haproxy-1.7.5.tar.gz, and copy the source package to a Linux directory

Perform the following command to install Haproxy

TAR–XZVF haproxy-1.7.5.tar.gz  #解压文件
cd haproxy-1.7.5 make
target=linux2628 make
install PREFIX=/USR /local/haproxy

Problem encountered: Execute make target=linux2628 error: Make:gcc:Command not found
Workaround: GCC not installed, yum install GCC

Configure Haproxy.cfg
Examples of installation packages: Examples/option-http_proxy.cfg
My final configuration:

Global
    log 127.0.0.1 local3 info
    chroot/usr/local/haproxy
    pidfile     /var/run/haproxy.pid 
    User Haproxy
    Group haproxy
    Daemon
    stats socket/var/lib/haproxy/stats level admin
    maxconn 1024

Defaults
    log global
    mode TCP
    option Tcplog
    timeout Connect 5000
    timeout client 50000
    Timeout server 50000
    balance roundrobin
    Retries 3

Listen mysql_proxy_1
    bind ip.5451  #ip
    mode TCP
    server PlfA ip1:3306 Check weight 5 #mysql数据库服务器
    server PLFB ip2:3306 Check weight 5

Listen Stats
    bind 0.0.0.0:1080
    mode http
    maxconn 
    stats refresh 30s 
    stats 
    uri/stats stats Realm hapcloud\ haproxy 
    stats auth admin:** # user name and password stats hide-version 
    admin if TRUE

Configure script startup and shutdown Haproxy
There are also examples in the installation package:

Cp-p examples/haproxy.init/etc/rc.d/init.d/haproxy
chmod +x/etc/rc.d/init.d/haproxy
chkconfig–-add Haproxy
vi/etc/rc.d/init.d/haproxy  #这里需要把BIN的值替换为BIN =haproxy installation directory/sbin/$BASENAME

Start Service Haproxy Start
Turn off service Haproxy stop
Restart Service Haproxy Restart

Can be viewed through the Http://ip.1080/stats page after startup

Common instructions
Dynamic setting Weights: Weight value is 0-256

echo "Set weight Mysql_proxy_1/plfa 0" |socat stdio/var/lib/haproxy/stats set weight <backend>/<server> < weight>[%]

Dynamic shutdown and open background service

echo "Disable Server Mysql_proxy_1/plfa" | Socat stdio/var/lib/haproxy/stats Disable Server <backend>/<server>
echo "Enable Server Mysql_proxy_1/plfa" | Socat stdio/var/lib/haproxy/stats Enable server <backend>/<server>

MySQL Test

Mysql-uhaproxy-phaproxy123456-h*.*.*.*-p5451-d test-e "SELECT COUNT (1) from Test;"

Follow-up research on how to combine keepalived.

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.