Build high-availability load balancing-centos6.4+haproxy+keepalive

Source: Internet
Author: User

1. Experimental Topology as follows, this is done with NGINX Port-based virtual host, easy to test later

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/6B/wKioL1SBuUmgED6_AAEIceBESQw873.jpg "title=" t1.jpg "alt=" wkiol1sbuumged6_aaeicebesqw873.jpg "/>

2. Preparation before installation

Haproxy Domestic Download You know

keepalived www.keepalive.org

Sync time

#ntpdate pool.ntp.org

3.haproxy installation ( same as Main and standby node installation )

#tar-zxvf haproxy-1.5.9.tar.gz #cd haproxy-1.5.9# uname-alinux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Fe b 00:31:26 UTC x86_64 x86_64 x86_64 gnu/linux#make target=linux26 prefix=/usr/local/haproxy install#cd/usr/local/ haproxy# mkdir conf Logs

4. Create configuration file information as follows

#vim  conf/haproxy.cfg global       log 127.0.0.1 local0 Log output configuration, all logs are recorded on this machine, output      maxconn  5120  //maximum number of connections via local0        chroot   /usr/local/haproxy  //Change Current working directory       uid      100  //the uid     of the owning user  gid      100  //the Gid     daemon of the owning user   //Run as background haproxy        nbproc   2   //Create 2 processes in Deamon mode      pidfile  /usr/local/haproxy/logs/haproxy.pid   //pid file   defaults       log      127.0.0.1  local3       mode    http   //http seven floor, TCP4 layer, health onlyreturn ok     option  httplog  //using httpd log format       option  dontlognull       option  redispatch        retries 3  //Three failures think Service Unavailable  maxconn 3000   //default maximum number of connections      contimeout 5000  //connection time-out       clitimeout 50000  //Client Timeout Time      srvtimeout 50000   //server time-out time      stats enable       stats Url     stats auth admin:admin of the  URI /ADMIN  //statistics page   //User name password for the statistics page      stats realm haproxy \ statistic   //Statistics page Tip Information  stats hide-version//Hide Statistics page version information   listen web_proxy *:80  server web1 192.168.1.128:80 check inter 5000 fall 1 rise 2   server web1  192.168.1.128:8080 check inter 5000 fall 1 rise 2//check inter  5000  is to detect the heartbeat frequency,rise 2  is 2 times correct to think that the service available,fall 1  is 1 times failed to think the service is unavailable, weight represents the weight


5,keepalive installation configuration ( Primary and standby installation, note the configuration file modification )

# yum-y Install OPENSSL-DEVEL#TAR-ZXVF keepalived-1.2.13.tar.gz#cd keepalived-1.2.13#./configure--prefix=/usr/local /keepalived#make && make install #cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/#ln-S/usr/ Local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/keepalived#chmod +x/etc/init.d/keepalived #mkdir/etc/ Keepalived#ln-sf/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/keepalived.conf


6. Modify the configuration file

# cat /etc/keepalived/keepalived.conf ! configuration file for keepalived  global_defs {   notification_email {     [email  protected]   }   notification_email_from [email protected]    smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id  LVS_DEVEL}vrrp_script chk_haproxy {   script  "/root/chk_haproxy.sh"//Detection script    interval 2   weight 2} vrrp_instance VI_1 {     state master //the initial state of the instance, the standby node is backup    interface eth0     virtual_router_id 51    priority 100//High Priority Select Master, at least high backup50     advert_int 1    authentication {         auth_type pass//authentication mode, support PASS and ah        auth_pass 1111// Certified Passwords     }    virtual_ipaddress {         192.168.1.200//vip    }         track_script {        chk_haproxy//Detection Command          }}


7.keepalived detection Script

# cat chk_haproxy.sh #!/bin/basha= ' ps-c haproxy--no-header | Wc-l ' if [$A = 0]; then/etc/init.d/keepalived STOPFI


8. Start keepalived

# service keepalived start error message starting keepalived:/bin/bash:keepalived:command not found[failed] Workaround # ln-s/usr/local /keepalived/sbin/keepalived/usr/sbin/keepalived


9. validation Process

First look at the nginx configuration

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/6B/wKioL1SBucbA6ItBAAAzqQE_bzc009.jpg "style=" float: none; "title=" n1.jpg "alt=" Wkiol1sbucba6itbaaazqqe_bzc009.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/6C/wKiom1SBuTfwak8fAAA3WKZaigc720.jpg "style=" float: none; "title=" n2.jpg "alt=" Wkiom1sbutfwak8faaa3wkzaigc720.jpg "/>


Start master and SLAVE separately , and see the Primary and Standby node log as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/6B/wKioL1SBuerDM0_DAAbUFIbrmZY465.jpg "style=" float: none; "title=" k2.jpg "alt=" Wkiol1sbuerdm0_daabufibrmzy465.jpg "/>


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/6C/wKiom1SBuVuTVXm7AAWD8QeEkDM914.jpg "style=" float: none; "title=" k3.jpg "alt=" Wkiom1sbuvutvxm7aawd8qeekdm914.jpg "/>


VIP information can be seen on Master

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/6B/wKioL1SBugnBBbePAAHTydFGE3I380.jpg "title=" k1.jpg "alt=" wkiol1sbugnbbbepaahtydfge3i380.jpg "/>

after the test Haproxy Whether load balancing is correct

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/6B/wKioL1SBuiajdLtwAAAywJz0uGU276.jpg "style=" float: none; "title=" h1.jpg "alt=" Wkiol1sbuiajdltwaaaywjz0ugu276.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/6C/wKiom1SBuZbB8uGkAAA2Hl_b_yQ987.jpg "style=" float: none; "title=" h2.jpg "alt=" Wkiom1sbuzbb8ugkaaa2hl_b_yq987.jpg "/>


Look at the automatic monitoring page and discover that polling is normal!

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/6C/wKiom1SBuaSTGL02AAU2LoofBZs748.jpg "title=" h3.jpg "alt=" wkiom1sbuastgl02aau2loofbzs748.jpg "/>

After the test Master haproxy hangs, whether to switch

#killall Haproxy

After looking at the keepalived log information, found that the master has been stopped according to the script, and the VIP began to drift

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/6B/wKioL1SBulaDv-RTAAEvuh5mw14842.jpg "style=" float: none; "title=" k4.jpg "alt=" Wkiol1sbuladv-rtaaevuh5mw14842.jpg "/>


Slave can see that it has risen to Master and has received a VIP address

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/6C/wKiom1SBuceDAnHdAAHOMu_gli8719.jpg "title=" k5.jpg "Style=" Float:none; "alt=" wkiom1sbucedanhdaahomu_gli8719.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/6B/wKioL1SBulbitXtRAAG-qE5S4ng497.jpg "title=" k6.jpg "Style=" Float:none; "alt=" wkiol1sbulbitxtraag-qe5s4ng497.jpg "/>


Finally in test access, are normal!

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/6C/wKiom1SBug-w1e9kAAApyRuh3Gs501.jpg "style=" float: none; "title=" n3.jpg "alt=" Wkiom1sbug-w1e9kaaapyruh3gs501.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/6B/wKioL1SBup_x8xZiAAAwvlfn9YQ627.jpg "style=" float: none; "title=" n4.jpg "alt=" Wkiol1sbup_x8xziaaawvlfn9yq627.jpg "/>



This article is from the "Bamboo Potential" blog, please be sure to keep this source http://peaceweb.blog.51cto.com/3226037/1586797

Build high-availability load balancing-centos6.4+haproxy+keepalive

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.