Linux Server Haproxy build a Web cluster environment instance

Source: Internet
Author: User
Tags nginx server haproxy

Operating system: CentOS 6.5 haproxy software version: haproxy-1.4.24 nginx software version: nginx-1.6.2


Haproxy is a popular cluster scheduling tool, previously mentioned Nginx upstream module can also realize the load balance of the cluster, but Nginx can not perform health checks on the nodes, performance is not haproxy good

Common scheduling algorithms for load Balancing: RR (Round Robin) Polling schedule, LC (Least Connections) Minimum number of connections, and SH (source Hashing) source-based access scheduling


Case topology diagram:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7C/F2/wKiom1bdAt-gl5kFAABCErV-UvA881.jpg "title=" Case topology diagram. jpg "alt=" wkiom1bdat-gl5kfaabcerv-uva881.jpg "/>

Case Environment:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/F0/wKioL1bdA8aQPKVAAADBHjXT3Bs576.jpg "title=" Case environment. jpg "alt=" wkiol1bda8aqpkvaaadbhjxt3bs576.jpg "/>


First, build Nginx server

1. Compile the installation (install Nginx on two servers respectively)

Nginx installation Method can refer to: Nginx source Installation


2. Create a test page on Nginx server 1 and start the service, notice that the firewall

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7C/F2/wKiom1bdBuGC9745AAAmRVc3-Bo056.jpg "title=" Test page 1.jpg "alt=" Wkiom1bdbugc9745aaamrvc3-bo056.jpg "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/F2/wKiom1bdBvyhztFwAABE96vcVAw627.jpg "title=" Start Nginx1.jpg "alt=" Wkiom1bdbvyhztfwaabe96vcvaw627.jpg "/>


3. Create a test page on Nginx server 2 and start the service, notice that the firewall

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/F0/wKioL1bdCXHgIrWMAABoQOSBnqk001.jpg "title=" Test page 2.jpg "alt=" Wkiol1bdcxhgirwmaaboqosbnqk001.jpg "/>

Production environment, two servers above the page should be the same, here in order to see the effect of load balancing, so different


Second, build Haproxy server

1. Compiling the installation

Preparation: Install Haproxy required Kit Pcre-devel, Bzip-devel

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/F2/wKiom1bdDA_hTU6-AAAWfBR7AQ4784.jpg "title=" Preparation tool. jpg "alt=" wkiom1bdda_htu6-aaawfbr7aq4784.jpg "/>


Installing Haproxy

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7C/F2/wKiom1bdDPHwqbMMAAAnbp9SOdk747.jpg "title=" Install haproxy.jpg "alt=" Wkiom1bddphwqbmmaaanbp9sodk747.jpg "/>


Establish Haproxy profile (Create profile directory, copy haproxy.cfg files to this directory)

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/F2/wKiom1bdDXuBUHGQAAApvkSmdQ8284.jpg "title=" Create a configuration file. jpg "alt=" wkiom1bddxubuhgqaaapvksmdq8284.jpg "/>


2. Modify the configuration file

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/F2/wKiom1bdD2-hpv58AAAUZYUzaZg121.jpg "title=" Vim configuration file. jpg "alt=" wkiom1bdd2-hpv58aaauzyuzazg121.jpg "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/F1/wKioL1bdHBbi7TdgAACVZewsYgQ638.jpg "title=" Modify the configuration file. jpg "alt=" wkiol1bdhbbi7tdgaacvzewsygq638.jpg "/>


3. Create a self-launching script

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7C/F1/wKioL1bdEW6BgiuwAABGCeo6jKc660.jpg "title=" Create a self-startup script. jpg "alt=" wkiol1bdew6bgiuwaabgceo6jkc660.jpg "/>


4. Start the Haproxy service and pay attention to the firewall

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7C/F1/wKioL1bdHK-jZ_XEAABSaQUNeN0570.jpg "title=" Start Haproxy.jpg "alt=" Wkiol1bdhk-jz_xeaabsaqunen0570.jpg "/>


Third, test the Web cluster effect

1. The first time the client opens 192.168.1.60, the display is as follows:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/F3/wKiom1bdHXXzUk_WAAB_w49iwuk969.jpg "title=" Test 1.jpg "alt=" Wkiom1bdhxxzuk_waab_w49iwuk969.jpg "/>

2. Press "F5" directly to refresh the webpage, the result is as follows:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7C/F2/wKioL1bdHh6DQ0DWAACBROravew649.jpg "title=" Test 2.jpg "alt=" Wkiol1bdhh6dq0dwaacbroravew649.jpg "/>

You can see that each time you access the server is different, so that load balancing


3. We shut down Nginx server 1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7C/F3/wKiom1bdHmKSY6PLAAAQfnm1T84105.jpg "title=" Close Nginx.jpg "alt=" Wkiom1bdhmksy6plaaaqfnm1t84105.jpg "/>


Then continue to access 192.168.1.60 with the following results:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/F2/wKioL1bdHwqx0WD0AACBROravew715.jpg "title=" Test 2.jpg "alt=" Wkiol1bdhwqx0wd0aacbroravew715.jpg "/>

Web pages can still be browsed, thus satisfying the high availability of the cluster

Linux Server Haproxy build a Web cluster environment instance

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.