Build a Web cluster using Haproxy

Source: Internet
Author: User
Tags nginx server node server haproxy rsyslog

Haproxy is a popular cluster scheduling tool, with many similar cluster scheduling tools, such as LVS and Nginx. In comparison, LVS performance is the best, but the construction of relatively complex, Nginx upstream module support cluster function, but the cluster node health Check function is not strong, performance is not haproxy good. Lab Environment:
Host Operating System IP Address main software
Haproxy Server Centos7-3 192.168.1.60 Haproxy-1.5.19.tar.gz
Nginx server 1 Centos7-3 192.168.1.61 Nginx-1.12.0.tar.gz
Nginx server 2 Centos7-3 192.168.1.61 Nginx-1.12.0.tar.gz
Client Windows7 192.168.1.66 IE browser
Experimental deployment: one. Node Server 11. Install the required packages
#yum install pcre-devel zlib-devel gcc gcc-c++ make –y
2. New Admin user Nginx
#useradd –M –s /sbin/nologin nginx
3. Unzip the Nginx package into the/OPT directory
#tar zxvf nginx-1.12.0.tar.gz –C /opt/          //保证在由此软件包的目录下
4. Configure in the nginx-1.12.0 directory
#cd nginx-1.12.0/#./configure --prefix=/usr/local/nginx \         //安装目录--user=nginx \                  //用户--group=nginx                   //用户组
5. Compiling and installing
#make && make install
6. Add a home page file
#cd /usr/local/nginx/html#echo “this is benet web”>test.html
7. Establish a soft connection for easy management
#ln –s /usr/local/nginx/sbin/nginx /usr/local/sbin
8. Start Nginx
#nginx
9. Turn off the firewall and enhance security features
#systemctl stop firewalld.service#setenforce 0
10. Testing


Two The configuration process for node server 2 node server 2 is the same as node server 1 as a whole, just be aware of the distinction between home settings and node server 1. Test: three. Haproxy server 1. Install the required packages
#yum install –y pcre-devel bzip2-devel gcc gcc-c++ make
2. Unpack the package to the/OPT directory (guaranteed in the directory with this package)
#tar zxvf haproxy-1.5.19.tar.gz –C /opt/
3. Compiling and installing
#cd /opt/haproxy-1.5.19#make TARGET=linux26#make install
4. Create a directory to store the configuration files
#mkdir /etc/haproxy
5. Copy the configuration template file to the storage directory
#cp examples/haproxy.cfg /etc/haproxy/
6. Modify the configuration file
#cd /etc/haproxy/#vim haproxy.cfg删除所有listen项目并删除以下语句chroot /usr/share/haproxyredispatch添加listen webcluster 0.0.0.0:80     option httpchk GET /test.html          //检查系统的test.html文件     balance roundrobin                 //负载均衡调度算法使用轮询算法     server inst1 192.168.1.61:80 check inter 2000 fall 3       //定义在线节点     server inst2 192.168.1.62:80 check inter 2000 fall 3
7. Create a self-launching script
#cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy#chmod +x /etc/init.d/haproxy                   //赋予可执行权限#chkconfig –add /etc/init.d/haproxy             //加入系统服务#ln –s /usr/local/sbin/haproxy /usr/sbin/haproxy
8. Start Haproxy
#service haproxy start
9. Turn off the firewall and enhance security features
#systemctl stop firewalld.service#setenforce 0
10. Test on the client win7:


Four Add Log function 1. Editing a configuration file
#vim /etc/haproxy/haproxy.cfglog  /dev/log   /local0 infolog  /dev/log   /local0 notice              //将配置文件里global下面的两行进行替换
2. Restart Haproxy
#service haproxy restart
3. Modify the Rsyslog configuration
#vim /etc/rsyslog.d/haproxy.confif ($programname == ‘haproxy‘ and $syslogseverity-text == ‘info‘)then -/var/log/haproxy/haproxy-info.log&~if ($programname == ‘haproxy‘ and $syslogseverity-text == ‘notice‘)then -/var/log/haproxy/haproxy-notice.log&~
4. Restart the System Log service
#systemctl restart rsyslog.service
5. Test log information
#tail –f /var/log/haproxy/haproxy-info.log

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.