High-performance Server Haproxy+nginx architecture configuration

Source: Internet
Author: User

with the maturity of the load balancer, the well-known software load balancer such as LVS, HAProxy, all aspects of performance as well as hardware load balancing, HAProxy provides high availability, load balancing and proxy based on TCP and HTTP applications, support virtual host, it is free, A solution that is fast and reliable.
Haproxy is especially useful for Web sites that are heavily loaded, and often require session-hold or seven-tier processing.
We usually use the load balancer is based on four-tier, new large-scale Internet companies are also using Haproxy, understand the haproxy large concurrency, seven-tier applications, and so on, today we look at haproxy+keepalived based on the seven-tier load of high-availability load balancing configuration.
First, the system environment:
System version: CentOS6.0 x86_64haproxy version: 1.4.21 keepalived version: 1.2.1 nginx version: 1.2.2master_ip:192.168.0.130 backup_ip : 192.168.0.131 vip:192.168.0.133 web_1:192.168.0.134 web_2:192.168.0.135
Second, Haproxy installation:
1) Install the 192.168.0.130 first:
Download the latest stable version: 1.4.21
CD/USR/SRC, wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gztar xzf haproxy-1.4.21.tar.gz & &CD haproxy-1.4.21 &&make target=linux26 prefix=/usr/local/haproxy &&make Install prefix=/usr/ Local/haproxy
After installation, you will see three directories in the/usr/local/haproxy/directory: Doc, sbin, share
2) next configure Haproxy.
Cd/usr/local/haproxy, Mkdir-p etc/
Then create a new Haproxy.cfg file under/usr/local/haproxy/etc/and copy the Haproxy configuration file here:
global           log 127.0.0.1    local0           maxconn 65535            chroot /usr/local/haproxy            uid 99               gid 99           daemon            nbproc 8            pidfile /usr/local/haproxy/haproxy.pid      defaults             log      127.0.0.1       local3              mode   http              option httplog             option  httpclose             option  dontlognull             option  Forwardfor             option redispatch              retries 2              maxconn 65535              balance source              stats   uri     /web-status              contimeout      5000              clitimeout       50000             srvtimeout       50000    listen  chinaapp.sinaapp.com            bind *:80            mode http           option  httplog           log global            option httpchk head /index.html http/1.0            server web1  192.168.0.134:80  weight 5  check inter 2000 rise 2 fall 3            server web2  192.168.0.135:80 weight 5  check  Inter 2000 rise 2 fall 3
Then start Haproxy and execute the start command as follows:
/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/etc/haproxy.cfg [WARNING] 217/202150 (2857): Proxy ' Chinaapp.sinaapp.com ': In multi-process mode, stats'll be a limited to process assigned to the current request.
Will be prompted as above information, the NBPROC process if set to 1 will not prompt, if you want to remove this hint can modify the compilation file. In the source configuration src/cfgparse.c found as follows
if (Nbproc > 1) {if (Curproxy->uri_auth) {-Warning ("Proxy '%s ': in Multi-proces s mode, stats'll be limited to process assigned to the current request.\n ", + Warning (" Proxy '%s '): in Multi-process mode, stats is limited to the process assigned to the current request.\n ",
Adjust the Nbproc > 1 values.
Third, installation keepalived:
CD/USR/SRC; wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz tar xzf keepalived-1.2.1.tar.gz cd keepalived-1.2.1 &  amp;&./configure–with-kernel-dir=/usr/src/kernels/2.6.32-71.el6.x86_64/&&make &&make Install dir=/usr/local/CP $DIR/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/&& CP $DIR/etc/sysconfig/keepalived/ etc/sysconfig/&& mkdir-p/etc/keepalived && CP $DIR/sbin/keepalived/usr/sbin/
Iv. Configuration keepalived:
! 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  "/data/sh/check_haproxy.sh"      interval 2      weight 2  }  # VIP1  vrrp_instance VI_1 {       state BACKUP      interface eth0       lvs_sync_daemon_inteface eth0      virtual_ router_id 151      priority 100      advert_int 5       nopreempt      authentication {           auth_typePASS           auth_pass 2222      }      virtual_ ipaddress {          192.168.0.133       }      track_script {       chk_haproxy     }  }
V. Create a Haproxy script:
Set executable permissions chmod +x check_haproxy.sh, as follows:
#!/bin/bash #auto Check Haprox process #2012 -8-12 wugk killall-0 haproxy if [[$?-ne 0]];then/etc/init.d/k Eepalived Stop fi
Backup is also configured as Haproxy, keepalived, configured with a change priority of 90, and then started.


Six, test haproxy+keepalived:


When the 131 haproxy process is manually killed, the keepalived background log is displayed as follows, and access to the VIP 192.168.0.133 Normal Access:

650) this.width=650; "src=" http://img1.51cto.com/attachment/201208/180520314.png "border=" 0 "/>

Visit Haproxy status such as:

650) this.width=650; "src=" http://img1.51cto.com/attachment/201208/181453164.png "border=" 0 "/>

This article refers to the wine brother http://andrewyu.blog.51cto.com/1604432/669491 haproxy+keepalived High-availability load balancing configuration

This article is from the "Keio Education-maintenance architect Training" blog, please be sure to keep this source http://jfedu.blog.51cto.com/8172058/1686835

High-performance Server Haproxy+nginx architecture configuration

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.