Use Haproxy to build a Web cluster (with source packages)

Source: Internet
Author: User
Tags node server haproxy

Haproxy Introduction:
Haproxy provides high availability, load balancing, and proxies based on TCP (layer fourth) and HTTP (layer seventh) applications, supporting virtual hosts;
Haproxy is especially useful for web sites that are particularly heavily loaded, and often require session-hold or seven-tier processing. Haproxy runs on today's hardware, fully supports tens of thousands of concurrent connections, and its operating mode makes it easy and safe to integrate into your current architecture while protecting your Web servers from being exposed to the network.
Haproxy implements an event-driven, single-process model that supports very large numbers of concurrent connections. A multi-process or multithreaded model is rarely capable of handling thousands of concurrent connections because of memory limitations, System scheduler restrictions, and ubiquitous lock limits.
Advantages of Haproxy:
A, free open source, stability is also very good
B, Haproxy can run full 10Gbps
C, Haproxy support connection rejection, for a small ddosxxx web site developed and has saved a lot of sites, this advantage is not the other load balancer
D, Haproxy support full transparent proxy (already have the typical characteristics of hardware firewall)
E, Haproxy now more than the online MySQL cluster environment, we often use it as MySQL (read) load balancer
F, with powerful monitoring server status of the page, in real-world we combine nagios for mail or SMS alarm

Experimental topology:

Lab Environment:

Host Operating System IP Address main software
Haproxy CentOS 7.0 x86_64 192.168.37.131 Haproxy-1.5.19.tar.gz
WEB1 node Server CentOS 7.0 x86_64 192.168.37.128 Nginx-1.12.0.tar.gz
WEB2 node Server CentOS 7.0 x86_64 192.168.37.130 Nginx-1.12.0.tar.gz
Client Windows 7 192.168.37.100 No

Package Sharing:
Haproxy https://pan.baidu.com/s/1o6266kAIwcaVxjKdCNZNQw Password: vxxz
Nginx Https://pan.baidu.com/s/13G9Mc3uX5dgYMYh4RflcWQ Password: vtkv

Experimental process:
One, Web node server Setup
1. Installation Environment Package

   [[email protected] ~]# yum install -y pcre-devel zlib-devel gcc gcc-c++

2. Create an administrative user

   [[email protected] ~]#useradd -M -s /sbin/nologin nginx

3, Decompression Nginx Package

    [[email protected] ~]#mkdir /opt/abc    [[email protected] ~]#mount.cifs //192.168.37.1/SHARE /opt/abc    [[email protected] ~]#tar zxvf /opt/abc/nginx-1.12.0.tar.gz -C /opt/

4. Configuration and Installation

    [[email protected] ~]#cd /opt/nginx-1.12.0            ./configure         --prefix=/usr/local/nginx \     #安装目录        --user=nginx \      #用户        --group=nginx     #组    [[email protected] ~]#make && make install

5, set the Nginx homepage content, distinguish between two node servers, one for Web1, the other for WEB2

6, the establishment of soft links, easy to manage

    [[email protected] ~]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

7. Turn on the service, turn off the firewall and security function

    [[email protected] ~]#nginx    [[email protected] ~]#systemctl stop firewalld.service    [[email protected] ~]#setenforce 0

Another WEB2 node Server Setup step above, just differentiate on the first page display
8. Test:

Second, Haproxy server
1. Installation Environment Package

    [[email protected] ~]#yum install -y pcre-devel bzip2-devel gcc gcc-c++

2, Decompression Haproxy bag

    [[email protected] ~]#mkdir /opt/abc    [[email protected] ~]#mount.cifs //192.168.37.1/SHARE /opt/abc    [[email protected] ~]#tar zxvf /opt/abc/haproxy-1.5.19.tar.gz -C /opt/

3. Configuration

     [[email protected] ~]#cd /opt/haproxy-1.5.19/       [[email protected] ~]#make TARGET=linux26     [[email protected] ~]#make install     

4. Create Haproxy Profile Directory

        [[email protected] ~]#mkdir /etc/haproxy

5, copy the file configuration template to the ETC directory

        [[email protected] ~]#cp examples/haproxy.cfg /etc/haproxy/

6. Edit the configuration file

        [[email protected] ~]#vim /etc/haproxy/haproxy.cfg


7. Create startup script, give execute permission

     [[email protected] ~]#cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy     [[email protected] ~]#chmod +x /etc/init.d/haproxy

8. Join the service System

         [[email protected] ~]#chkconfig --add /etc/init.d/haproxy         [[email protected] ~]#ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy

9. Start the service, turn off the firewall and security function

        [[email protected] ~]#service haproxy start        [[email protected] ~]#systemctl stop firewalld.service        [[email protected] ~]#setenforce 0  

10. Testing

Experiment Done!

Use Haproxy to build a Web cluster (with source packages)

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.