Haproxy to build and configure LB load Balancer cluster, you can monitor the running status of Web server via Web page.

Source: Internet
Author: User
Tags haproxy

Haproxy provides high availability, Load Balancing and proxies based on TCP and HTTP applications that support Virtual Host , it is a free, fast and reliable solution. Haproxy is especially useful for Web sites that are heavily loaded, and often require session-hold or seven-tier processing.

Experiment (I.)

Experimental purpose: Using Haproxy to do load balancing clusters (layer seven)

Lab Environment Preparation:

Client IP address: 1.1.1.1 host name Waiwang

Web1 IP address: 1.1.1.10 host name: localhost

web2 IP address: 1.1.1.20 host name: localhost

Configure the IP address of the Haproxy server: 1.1.1.254 hostname: FANLJ

Software packages used in the lab: haproxy-1.4.24.tar.gz

1. Check that software depends on the software pcre Pcre-devel is installed.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B0/wKioL1YEnRSj0E8NAADPCTrNnss156.jpg "title=" Qq20150925090351.png "alt=" Wkiol1yenrsj0e8naadpctrnnss156.jpg "/>

2. Unpack the package, and install, because in the unpacked package has makefile so do not need to configure and compile, direct installation, target specifies the kernel version, use_pcre specifies the dependent software for Pcre,prefix specified software installation directory, Create the Conf folder to hold the configuration file, create a log folder to hold the journal files, copy the configuration files from the source package into the configuration file created.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B3/wKiom1YEnC2hYpI4AAHx5e45Oqo466.jpg "title=" Qq20150925090002.png "alt=" Wkiom1yenc2hypi4aahx5e45oqo466.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B0/wKioL1YEna2h93WjAADk2eXJFSg529.jpg "title=" Qq20150925090622.png "alt=" Wkiol1yena2h93wjaadk2exjfsg529.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B0/wKioL1YEn9HBEI6yAADLhCSAUfs127.jpg "title=" Qq20150925091532.png "alt=" Wkiol1yen9hbei6yaadlhcsaufs127.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B0/wKioL1YEoX3DHK_yAABofQ57tbc707.jpg "title=" Qq20150925092239.png "alt=" Wkiol1yeox3dhk_yaabofq57tbc707.jpg "/>

3. Modify the master configuration file to do the load balancing cluster. Global is globally set, defaults is the default setting, listen is the name of the specified virtual service, IP address and port number, web-ser the name defined for itself, After the IP address and port 80 are used for that IP address (0.0.0.0 for all addresses) and port to receive connection requests, balance specifies the way to distribute, Roundrobin is polling, the server is followed by the IP address and port that truly provides Web access, and the preceding keywords can be defined.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B0/wKioL1YEpfeD1_rEAADl5D7hv9U337.jpg "title=" Qq20150925094125.png "alt=" Wkiol1yepfed1_reaadl5d7hv9u337.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B0/wKioL1YEpgGQfVUpAAH9O0PfEgQ345.jpg "title=" Qq20150925094141.png "alt=" Wkiol1yepggqfvupaah9o0pfegq345.jpg "/>

4. Start the Haproxy service

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B1/wKioL1YEpwHScCSCAAHcj3DsXoU142.jpg "title=" Qq20150925094610.png "alt=" Wkiol1yepwhsccscaahcj3dsxou142.jpg "/>

The above error occurred when starting the service, the solution is to prompt 21 line keyword Redispatch before adding the keyword to option Redispatch, and then start again after modification.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B1/wKioL1YEp7LxpIhgAAAtufCNt5M883.jpg "title=" Qq20150925094908.png "alt=" Wkiol1yep7lxpihgaaatufcnt5m883.jpg "/>

There was an error when starting the service again, unable to load/usr/share/haproxy when starting the configuration file, modifying the path to/usr/local/haproxy, and starting the service again after modification.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B3/wKiom1YEp-qS_e4-AAEfDYPyc_8476.jpg "title=" Qq20150925094945.png "alt=" Wkiom1yep-qs_e4-aaefdypyc_8476.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B1/wKioL1YEqHKQAGEXAAA-xsIu65g349.jpg "title=" Qq20150925095219.png "alt=" Wkiol1yeqhkqagexaaa-xsiu65g349.jpg "/>

5. After successful startup, review the process and port, and the stopping process can be done by killing the process.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B4/wKiom1YEqR_DsLnqAAEKeZEJDqs390.jpg "title=" Qq20150925095517.png "alt=" Wkiom1yeqr_dslnqaaekezejdqs390.jpg "/>

6. Test the client, start the website service on Web1 and WEB2, and modify the default page, Web1 page for 1.1.1.10,WEB2 is 1.1.1.20.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B1/wKioL1YEqsnxDtT-AADJjt8ZoU8255.jpg "title=" Qq20150925100219.png "alt=" Wkiol1yeqsnxdtt-aadjjt8zou8255.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B4/wKiom1YEqs-R2lHlAADJjt8ZoU8456.jpg "title=" Qq20150925100219.png "alt=" Wkiom1yeqs-r2lhlaadjjt8zou8456.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B4/wKiom1YEqxDQMq07AADK8JO-FZM009.jpg "title=" Qq20150925100331.png "alt=" Wkiom1yeqxdqmq07aadk8jo-fzm009.jpg "/>

7.haproxy provides Web page monitoring information, and can monitor its web page is down, stats uri/haproxy-admin to set up Web page monitoring, restart the service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B4/wKiom1YEq_uS5_tnAAEY-1VeefQ746.jpg "title=" Qq20150925100716.png "alt=" Wkiom1yeq_us5_tnaaey-1veefq746.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B4/wKiom1YErJPTcCN3AAC_zix15zI562.jpg "title=" Qq20150925100938.png "alt=" Wkiom1yerjptccn3aac_zix15zi562.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B4/wKiom1YErJuD0SYPAACQVGL6-GY360.jpg "title=" Qq20150925100948.png "alt=" Wkiom1yerjud0sypaacqvgl6-gy360.jpg "/>

8. Because the client does not have the desktop installed, it accesses the test itself on the Haproxy service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B4/wKiom1YErVzQt2KQAAQLdyefoR4051.jpg "title=" Qq20150925101233.png "alt=" Wkiom1yervzqt2kqaaqldyefor4051.jpg "/>

9. Drop the page on the WEB2 to see if it is monitored.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B4/wKiom1YErcqCsPp-AAEDMThGieA236.jpg "title=" Qq20150925101508.png "alt=" Wkiom1yercqcspp-aaedmthgiea236.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B1/wKioL1YEreiSQSQEAASSjoHg7f4970.jpg "title=" Qq20150925101539.png "alt=" Wkiol1yereisqsqeaassjohg7f4970.jpg "/>

Summary: Haproxy load balancer clusters can monitor the Web server's running status information through a Web page.

Explanation of configuration file parameters

Global//Globally set
Log 127.0.0.1 local0//Logging Output configuration
Maxconn 4096//maximum number of connections

Chroot/usr/local/haproxy
UID 99//user UID of the owning run
GID 99//the user group to which the run belongs
Daemon//After station form operation
Nbproc 2//start 2 Haproxy instances

Pidfile/usr/local/haproxy/run/haproxy.pid
Defaults//Default settings
Log Global

Mode http? HTTP mode is used by default
Option Httplog//log category
Retries 3?? 3 connection failures that the server is not available
Option Redispatch//when the ServerID corresponding server is hung, force a redirect to another healthy server
Stats Uri/haproxy-admin//Set up monitoring

Contimeout 5000//Connection time-out
Clitimeout 50000//Client connection time-out

Srvtimeout 50000//server-side connection time-out

Listen Web-ser 0.0.0.0:80 #

#cookie Specify the number of the ServerID to define itself

#check Inter 2000 heartbeat check frequency 2 seconds

#rise 2 consecutive 2 checks to heartbeat that the server is available
#fall 5 5 times in a row, the heartbeat is not considered a server unavailable

Experiment (II)

Experimental purpose: Haproxy do lb load Balancing cluster, let a client's multiple access requests are haproxy distributed to the back end of the same server (only applicable to the Web cluster).

Experimental environment: Ibid.

1. Modify the master configuration file, the cookie ServerID Insert indirect nocache to insert the cookie information nocache to not cache.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B2/wKioL1YEuBPStoGIAAF0uUzin34650.jpg "title=" Qq20150925105318.png "alt=" Wkiol1yeubpstogiaaf0uuzin34650.jpg "/>

2. Restart the service

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B2/wKioL1YEt-ih2nLbAAC_zix15zI830.jpg "title=" Qq20150925100938.png "alt=" Wkiol1yet-ih2nlbaac_zix15zi830.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B5/wKiom1YEt_LyLRCXAACQVGL6-GY323.jpg "title=" Qq20150925100948.png "alt=" Wkiom1yet_lylrcxaacqvgl6-gy323.jpg "/>

3. Client testing only the HTTP protocol carries cookie information.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B5/wKiom1YEuJvzUpVIAAC6daPywKA429.jpg "title=" Qq20150925110121.png "alt=" Wkiom1yeujvzupviaac6dapywka429.jpg "/>

Experiment (III)

Experimental Purpose: Haproxy implement LB load Balancing cluster, distributing the connection request used according to the type of file the user accesses.

Lab Environment:

Client IP address: 1.1.1.1 host name Waiwang

Web1 IP address: 1.1.1.10 hostname: localhost provides Web services. HTML end of page

web2 IP address: 1.1.1.20 hostname: localhost provides Web services. HTML end of page

web3 IP address: 1.1.1.30 hostname: localhost provides Web services

. PHP End of page

WEB4 IP address: 1.1.1.40 hostname: localhost provides Web services

. PHP End of page

Configure the IP address of the Haproxy server: 1.1.1.254 hostname: FANLJ

Software packages used in the lab: haproxy-1.4.24.tar.gz

Experimental requirements:
When a user accesses Http://haproxy-ip default access to Web1 or WEB2 pages

Access WEB3 and WEB4 pages when users visit http:/haproxy-ip/.php

Access Web1 and WEB2 pages when users visit http://haproxy-ip/.html

1. Installing a PHP-enabled package

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B4/wKioL1YE3p3zIiAZAAAwUB7XUwY860.jpg "title=" Qq20150925134325.png "alt=" Wkiol1ye3p3ziiazaaawub7xuwy860.jpg "/>

2.web1 and WEB2 are configured as above, configuring WEB3 and WEB4 pages.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B8/wKiom1YE9yLArAGoAAD8bocqViE556.jpg "title=" Qq20150925152734.png "alt=" Wkiom1ye9ylaragoaad8bocqvie556.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B5/wKioL1YE9zCCuv80AADzh4FmZWo488.jpg "title=" Qq20150925152805.png "alt=" Wkiol1ye9zccuv80aadzh4fmzwo488.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B9/wKiom1YFAYvQlqEdAADI_8BpXQ0036.jpg "title=" Qq20150925161233.png "alt=" Wkiom1yfayvqlqedaadi_8bpxq0036.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B6/wKioL1YFAirhYEkRAAC0i-QBQLk620.jpg "title=" Qq20150925161508.png "alt=" Wkiol1yfairhyekraac0i-qbqlk620.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B6/wKioL1YFAwmyHLWNAAE4_kTrj9k615.jpg "title=" Qq20150925161848.png "alt=" Wkiol1yfawmyhlwnaae4_ktrj9k615.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B9/wKiom1YFA-rAXZLJAAE4zrvIAMQ061.jpg "title=" Qq20150925162241.png "alt=" Wkiom1yfa-raxzljaae4zrviamq061.jpg "/>

3. Modify Haproxy to provide LB load balancer configuration file, examples directory in source package, frontend define service policy, backend server group to provide service, bind 0.0.0.0:80 listen access to 80 port request for all ports of native , Mode HTTP is a seven-tier mode, option Httplog is configured to use global logging, the ACL is a matching policy, Use_backend requests for access are matched against ACLs when the request is distributed to that server group, Default_ Backend people access that server group by default, backend is the host that actually provides the Web service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B9/wKiom1YFBMei8FZHAACG_WudCfQ548.jpg "title=" Qq20150925162620.png "alt=" Wkiom1yfbmei8fzhaacg_wudcfq548.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/B7/wKioL1YFDb-QdKxaAAHTm2ZVSX0993.jpg "title=" Qq20150925170415.png "alt=" Wkiol1yfdb-qdkxaaahtm2zvsx0993.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/BA/wKiom1YFDceBMNJUAAMdxZrbE-k891.jpg "title=" Qq20150925170058.png "alt=" Wkiom1yfdcebmnjuaamdxzrbe-k891.jpg "/>

4. Start the Haproxy service

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B8/wKioL1YFFK-jV9F5AAN8yScUh10908.jpg "title=" Qq20150925173403.png "alt=" Wkiol1yffk-jv9f5aan8yscuh10908.jpg "/>

5. Client-side testing

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/BA/wKiom1YFE2vTw7gSAAEVwNqnJeA653.jpg "title=" Qq20150925172848.png "alt=" Wkiom1yfe2vtw7gsaaevwnqnjea653.jpg "/>

Summary: The HAPROXY load Balancer cluster can monitor the Web server's running state information through a Web page, and can distribute the connection requests that are used depending on the type of file the user accesses.

This article is from the "Down to earth" blog, make sure to keep this source http://343614597.blog.51cto.com/7056394/1698299

Haproxy to build and configure LB load Balancer cluster, you can monitor the running status of Web server via Web page.

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.