Build a Web cluster using Haproxy

Source: Internet
Author: User
Tags haproxy

Build a Web cluster using 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. The haproxy runs on the current 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.
Structure extension and complement diagram

Experimental environment
Host Operating System IP Address main software
Haproxy Server Centos7.3x86_64 192.168.100.101/24 Haproxy-1.5.19.tar.gz
Web server 1 Centos7.3x86_64 192.168.100.102/24 Nginx-1.12.0.tar.gz
Web server 2 Centos7.3x86_64 192.168.100.103/24 Nginx-1.12.0.tar.gz
Install the Configuration Web server
    • Both Web servers have the same installation configuration process, primarily setting different test pages to differentiate between two Web servers.

Install the build Environment package Pcre-devel bzip2-devel GCC gcc-c++;

Yum install PCRE-DEVDL zlib-devel gcc gcc-c++ make-y

Create Nginx user, unzip the Nginx compressed package, and compile and install;

Useradd-m-s/sbin/nologin Nginx

MKDIR/OPT/ABC #创建挂载点

Mount.cifs//192.168.100.3/RHEL7/OPT/ABC #将宿主机的相关软件包挂载

Tar zxvf nginx-1.12.0.tar.gz-c/opt #解压nginx压缩包

cd/nginx-1.12.0

./configure \
--prefix=/usr/local/nginx \ #安装目录
--user=nginx \ #用户
--group=nginx #属组

Make && make install

Add Test Home page (add Test homepage on two Web servers respectively);

Cd/user/local/nginx/hatml

echo "This is Web1 test" > Test.html #web1服务器测试首页内容

echo "This is WEB2 test" > Test.html #web2服务器测试首页内容

Establish soft connection, make the system to identify Nginx command, start nginx;

Ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin/#使系统识别nginx命令

Nginx #启动

Turn off firewalls and security features;

Systemctl Stop Firewalld.service #关闭防火墙

Setenforce 0 #关闭安全功能

Installation Configuration Haproxy Service

Install the build Environment package Pcre-devel bzip2-devel gcc gcc-c++ make;

Yum install pdre-devel bzip2-devel gcc gcc-c++ make

Unzip the Haproxy compressed package, and compile the installation;

MKDIR/OPT/ABC #创建挂载点

Mount.cifs//192.168.100.3/RHEL7/OPT/ABC #将宿主机中的相关软件包挂载

Tar zxvf haproxy-1.2.19.tar.gz-c/opt #解压haproxy服务压缩包

cd/opt/haproxy-1.5.19

Make Target=linux26 #64为系统

Make install

Set up the Haproxy configuration file and edit it;

Mkdir/etc/harpoxy

CP examples/haproxy.cfg/etc/haproxy #将haproxy. cfg files to the configuration file

Cd/etc/haproxy

Vim Haproxy.cfg #编辑配置文件

删除以下语句chroot /usr/share/haproxyredispatch                  添加listen  webcluster 0.0.0.0:80        option httpchk GET /test.html        balance roundrobin        server inst1 192.168.100.102:80 check inter 2000 fall 3     #节点1服务器        server inst2 192.168.100.103:80 check inter 2000 fall 3     #节点2服务器

The Haproxy startup script is copied to the/ETC/INIT.D, and a soft connection is established to facilitate the identification of the system;

Cp/opt/haproxy-1.5.19/examples/haproxy.init/etc/init.d/haproxy #将haproxy的启动脚本复制到/ETC/INIT.D

chmod +x Haproxy

Chkconfig--add/etc/init.d/haproxy

Ln-s/usr/local/sbin/haproxy/usr/sbin/haproxy #建立软连接便于系统所识别

Turn off firewalls and security features;

Systemctl Stop Firewalld.service

Setenforce 0

Login Verification
    • Haproxy server as a Load Balancer server, customer service browser only need to access the IP address of the Haproxy server to refresh, you can access to two Web servers different at this time home.

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.