Haproxy+nginx Building a Web cluster

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

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.

    • This example describes the use of a haproxy+ngin set of web clusters
    • Experimental requirements
    • Haproxy as a dispatch server
    • Nginx as a node server
    • Windows is used to test
Server Host IP Installing the Software
Haproxy Server 192.168.200.102/24 Haproxy-1.5.19.tar.gz
Nginx server 1 192.168.200.103/24 Nginx-1.12.0.tar.gz
Nginx server 2 192.168.200.104/24 Nginx-1.12.0.tar.gz
Windows Client 192.168.200.101/24 IE browser

  • Install configure Nginx server

      # useradd-m-s/sbin/nologin nginx # mount.cifs//192.168.200.1/GX /gx# Yum install-y pcre-devel zlib-devel gcc gcc-c++ make# tar/gx/zxvf nginx-1.12.0.tar.gz-c/opt/# cd/opt/nginx-1.12 .0/./configure--prefix=/usr/local/nginx--user=nginx--group=nginx# make && make Installnginx server 1 # echo "This is 7.1"/usr/local/nginx/html/test.html//nginx1 Add test page nginx server * echo "This is 7.2"/usr/local/nginx/html/ test.html//nginx2 Add Test page # ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin/# nginx//start nginx# Systemctl stop fi Rewalld.service//Off firewall # Setenforce 0  
  • Installing the Configuration Haproxy server

    # yum install -y pcre-devel bzip2-devel gcc gcc-c++ make# mount.cifs //192.168.200.1/gx /gx# tar zxvf /gx/haproxy-1.5.19.tar.gz -C /opt/# cd /opt/haproxy-1.5.19/# make TARGET=linux26# make install# mkdir /etc/haproxy# cp examples/haproxy.cfg /etc/haproxy/# vim /etc/haproxy/haproxy.cfg        删除以下语句        chroot /usr/share/haproxy     //根目录        redispatch            //强制将请求发给已经down的服务器    替换listen开头的行及后面所有行    listen  webcluster 0.0.0.0:80       //定义一个webcluster的应用    option httpchk GET /test.html    //检查服务器的test.html文件    balance roundrobin                  //负载均衡调度算法使用轮询算法    server inst1 192.168.200.103:80 check inter 2000 fall 3   //定义在线节点1    server inst2 192.168.200.104:80 check inter 2000 fall 3   //定义在线节点2

    • 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# service haproxy start   //启动Haproxy服务
    • Windows Client Test
    • In the browser input http://192.168.200.102/test.html
    • More refresh several times can see NGINX1, NGINX2 test page for Build success

    • Haproxy Log Definition separation
    • Haproxy logs are output to system syslog by default, and viewing is inconvenient.
    • For better management of logs, Haproxy's info and notice logs can be logged separately to different log files
      .

      1:在global下面两行日志文件配置 重新定义分离    # vim /etc/haproxy/haproxy.cfg    global            log /dev/log    local0 info                log /dev/log    local0 notice    # service haproxy restart   //修改了配置文件需要重启服务2:修改rsyslog配置    # touch /etc/rsyslog.d/haproxy.conf    # vim /etc/rsyslog.d/haproxy.conf        if ($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        &~    # systemctl restart rsyslog.service  //重启 rsyslog服务3:查看日志    # cd /var/log/haproxy/    # cat haproxy-info.log  



Haproxy+nginx Building a Web cluster

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.