Linux Haproxy for simple four-layer load balancing

Source: Internet
Author: User
Tags syslog haproxy

HAProxy provides high availability, load balancing, and proxies based on TCP and HTTP applications, supporting virtual hosting, which is a free, fast, and reliable solution.


Haproxy four-layer load Balancing Setup


Host Planning:

Server 192.168.1.148 provides haproxy services

Backstage Web1 192.168.1.150

WEB2 192.168.1.136


Installing with the source package

Extract:

TAR-ZXVF haproxy-1.4.24.tar.gz

Go to unzip directory:

CD haproxy-1.4.24

Compile:

Make target=linux26 arch=i386 (specify kernel and 32-bit version)

Error

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F1/wKioL1VYY_aS4T27AAH49_bmqlE916.jpg "title=" compile 1. PNG "alt=" Wkiol1vyy_as4t27aah49_bmqle916.jpg "/>

Workaround: Install GCC

Yum Install GCC

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F1/wKioL1VYZCaQIbPpAAHF1j74uPY858.jpg "title=" resolved. PNG "alt=" Wkiol1vyzcaqibppaahf1j74upy858.jpg "/>

Recompile: Make Target=linux26 arch=i386

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/F7/wKiom1VYYs3yEolUAADiNBWZwmc963.jpg "title=" compilation. PNG "alt=" Wkiom1vyys3yeoluaadinbwzwmc963.jpg "/>

To perform the installation again:

Make Prefix=/var/haproxy Install (Specify installation path)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYYyiiZBpGAAFGPN-9Kg0991.jpg "title=" installation. PNG "alt=" Wkiom1vyyyiizbpgaafgpn-9kg0991.jpg "/>


View the installation directory

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F2/wKioL1VYZNqiKeZoAACEg8tsR30408.jpg "title=" directory. PNG "alt=" Wkiol1vyznqikezoaaceg8tsr30408.jpg "/>

Create the specified directory in the installation directory after installation is complete

Mkdir-p bin logs conf Var/run var/chroot

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYY3jTN6VdAAE8QI_Sr6c972.jpg "title=" to create a directory. PNG "alt=" Wkiom1vyy3jtn6vdaae8qi_sr6c972.jpg "/>

Copy the configuration file to the Conf directory of the installation directory under the decompression directory

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/F7/wKiom1VYY82zbjNLAADMZVOeL7E063.jpg "title=" Copy configuration file . PNG "alt=" Wkiom1vyy82zbjnlaadmzvoel7e063.jpg "/>


Add a system user before editing a configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/F7/wKiom1VYZCexbKJbAABboPvTPro323.jpg "title=" Add users. PNG "alt=" Wkiom1vyzcexbkjbaabbopvtpro323.jpg "/>

Furthermore, the log service for adding haproxy

In/etc/syslog.conf add the following:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYZHDCnUalAAAqnAf1fao684.jpg "style=" float: none; "title=" Log 1. PNG "alt=" Wkiom1vyzhdcnualaaaqnaf1fao684.jpg "/>

Edit/etc/sysconfig/syslog


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/F2/wKioL1VYZeqwSVp7AABLpX1QpDY024.jpg "style=" float: none; "Title=" Log 2. PNG "alt=" Wkiol1vyzeqwsvp7aablpx1qpdy024.jpg "/>

Restart Log service after completion

Service Syslog Restart

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/F7/wKiom1VYZTbxbLPsAABtFgSSwCY402.jpg "title=" Restart the log. PNG "alt=" Wkiom1vyztbxblpsaabtfgsswcy402.jpg "/>

Configure Haproxy When you are ready to complete

Vi/var/haproxy/conf/haproxy/cfg

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYZbGTO8rdAAE2011FGck162.jpg "style=" float: none; "title=" Conf configuration 2. PNG "alt=" Wkiom1vyzbgto8rdaae2011fgck162.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F2/wKioL1VYZyuQwDghAAG9qku5_NY135.jpg "style=" float: none; "title=" conf configuration. PNG "alt=" Wkiol1vyzyuqwdghaag9qku5_ny135.jpg "/>


Start Haproxy when editing is complete

/var/haproxy/sbin/haproxy-f/var/haproxy/conf/haproxy.cfg (every time you start trouble, you can add your own Haproxy startup script)


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F2/wKioL1VYZ2-CPN1nAACHWRrdN1o804.jpg "title=" Qidong . PNG "alt=" Wkiol1vyz2-cpn1naachwrrdn1o804.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYZtbhgBECAAB9E6BzDy4027.jpg "title=" test3. PNG "alt=" Wkiom1vyztbhgbecaab9e6bzdy4027.jpg "/>

Alternatively, you can use Killall haproxy to kill the process.


Test after everything is done


Open the other two web machines and launch the Apache service.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F7/wKiom1VYZx6gFW1EAAD6QYtyDRk362.jpg "style=" float: none; "Title=" test1. PNG "alt=" Wkiom1vyzx6gfw1eaad6qytydrk362.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/F2/wKioL1VYaJjg6WKOAAaYReYGX9o576.jpg "style=" float: none; "Title=" test2. PNG "alt=" Wkiol1vyajjg6wkoaaayreygx9o576.jpg "/>


Test Load Balancing

The server address of the browser-side input haproxy is constantly refreshed, you can see the following results

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F2/wKioL1VYaUOgoLaqAACF4dW0z-I819.jpg "style=" float: none; "Title=" test4. PNG "alt=" Wkiol1vyauogolaqaacf4dw0z-i819.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/F7/wKiom1VYZ8nR7i_YAAB6TuFSlSg010.jpg "style=" float: none; "Title=" test5. PNG "alt=" Wkiom1vyz8nr7i_yaab6tufslsg010.jpg "/>

Thus, the purpose of load balancing is achieved.


Close one of the web machines

Refresh the Status Display page to see

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F2/wKioL1VYaazzg65ZAAEwIX3WDJU364.jpg "title=" Test6. PNG "alt=" Wkiol1vyaazzg65zaaewix3wdju364.jpg "/>

The Haproxy four-layer load balancer is now complete.

This article is from the "Filter New" blog, please be sure to keep this source http://wahehe.blog.51cto.com/8935316/1652107

Linux Haproxy for simple four-layer load balancing

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.