Build a Web cluster using Haproxy

Source: Internet
Author: User
Tags haproxy rsyslog

Overview:
Haproxy is a cluster scheduling tool that provides high availability, load balancing, and proxy software based on TCP (layer fourth) and HTTP (layer seventh) applications, supporting virtual hosting, which 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. Haproxy runs on today's hardware and can support 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 server from being exposed to the web.
Case Environment:
Build a set of Web clusters using three server simulations, as shown in the topology diagram below.

Case Environment Table:

Implementation steps:
First, compile and install Nginx service
1. Build the NGINX1, use the NGINX-1.12.0.TAR.GZ installation package to compile and install.
[email protected] ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make-y
[Email protected] tomcat]# tar zxvf nginx-1.12.0.tar.gz-c/opt/

[[email protected] nginx-1.12.0]# make && make install
① set up the test interface and start the Nginx service

② testing on Client Access http://192.168.100.100/test.html

2. Build Nginx2
① the steps to compile and install are the same as Nginx1, except that the test interface is established.

② after the installation is complete, test the client access http://192.168.100.120/test.html

Second, compile and install Haproxy
1. Compiling and installing using the HAPROXY-1.5.19.TAR.GZ installation package
[email protected] ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make-y
[Email protected] tomcat]# tar zxvf haproxy-1.5.19.tar.gz-c/opt/
[[email protected] haproxy-1.5.19]# make target=linux26 compile and install
[[email protected] haproxy-1.5.19]# make install
Third, Haproxy server configuration
1. Setting up the Haproxy configuration file
[[email protected] haproxy-1.5.19]# mkdir/etc/haproxy Create profile Directory
[[email protected] haproxy-1.5.19]# cp examples/haproxy.cfg/etc/haproxy/copy haproxy.cfg to config file directory
2. Delete all Listen items
[Email protected] haproxy-1.5.19]# cd/etc/haproxy/
[Email protected] haproxy]# vim haproxy.cfg
Add to

Delete the following statement

3. Create a self-launching script

IV. Testing the Web cluster
1. Test High Performance
① the client uses the browser to open http://192.168.100.100/test.html for testing
② again opens a new browser page to access http://192.168.100.120/test.html for testing

V. Haproxy's Log segmentation
1. Modify the options for the log configuration in the Haproxy configuration file, and add the following configuration:

These two lines of configuration are placed in the global global Configuration project of Haproxy, which is mainly to log Haproxy's info and notice logs to separate log files.
Then restart Haproxy to complete the Haproxy configuration

2. Modify the Rsyslog configuration
For ease of administration, the Haproxy-related configuration is independently defined to haproxy.conf and placed under/ETC/RSYSLOG.D, and all configuration files under this directory are automatically loaded when Rsyslog startup is =.

Add the following content:

This part of the configuration is to record the Haproxy info log to/var/log/haproxy/haproxy-info.log, notice log to/var/log/haproxy/haproxy-notice.log, where "&~" means that Rsyslog stops processing this information after it is written to the log file.
Then save the configuration file to restart the Rsyslog service and complete the configuration.
[Email protected] ~]# systemctl restart Rsyslog.service
3. Test log information
After the client accesses http://192.168.100.100/test.html, use/var/log/haproxy/haproxy-info.log to instantly view the Haproxy access request log information.

Build a Web cluster using Haproxy

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.