Deploying Haproxy and Nginx to build Web clusters on CentOS7

Source: Internet
Author: User
Tags system log nginx server haproxy rsyslog

Haproxy is a free and open source software written in C that provides high availability, load balancing, and TCP and HTTP-based application proxies that can run on most major Linux operating systems.
This experiment uses three servers to build a Web cluster, haproxy as a dispatch server, two Nginx servers as node servers.

Experimental environment

Host | System | IP Address | As long as the software

Host system IP Address main software
Haproxy Server Centos-7-x86_64 192.168.100.101 Haproxy
Nginx Server Centos-7-x86_64 192.168.100.102 Nginx
Nginx Server Centos-7-x86_64 192.168.100.103 Nginx
Client Windows 192.168.100.100 IE browser

Installing the NGINXF server

  • Install and compile the environment
    yum -y install pcre-devel zlib-devel gcc gcc-c++ make  -yuseradd -M -s /sbin/nologin nginx //为其创建管理用户tar zxvf nginx-1.12.0.tar.gz -C /opt/ //解压./configure --prefix=/usr/local/nginx \  //安装路径--user=nginx \               //指定管理用户--group=nginx  //为其编译    //指定管理组make && make install //安装 cd /usr/local/nginx/html/ //存放首页路径vim index.html //修改它也行从新生成一个也可也echo "this is nginx 1!!" > tast.html //但访问的是后面要加tast如 http://127.0.0.1/tastln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  //创建软连接,方便管理nginx -t                                            //检查配置文件是否正确  nginx                                           //启动服务netstat -ntap | grep 80                             //查看服务是否正确开启关闭防火墙systemctl disable firewalld.service systemctl stop firewalld.servicesetenforce 0

    Self-Test two identical configurations

    调度服务器配置
  • Installing the Haproxy Software compilation environment
    yum -y install pcre-devel bzip2-devel gcc gcc-c++ make tar zxf haproxy-1.5.19.tar.gzcd haproxy-1.5.19/make TARGET=linux26     

    Configuring the Haproxy Server

    MKDIR/ETC/HAPROXYCP haproxy-1.5.19/examples/haproxy.cfg/etc/haproxy/haproxy.cfg Cd/etc/haproxy/vim haproxy.cfg// Modify its profile global log 127.0.0.1 local0//log format and system log saved together log 127.0.0.1 Local1 notice//notice log level #log Logho    St Local0 Info maxconn 4096//maximum number of links chroot/usr/share/haproxy//delete uid full gid daemon #debug      #quietdefaults Log global mode HTTP option Httplog//write the httpd format of the logfile format write option Dontlognull      Retries 3//number of attempts 3 times if the link is not considered unavailable redispatch//delete maxconn Contimeout 5000//MAX link clitimeout 50000 srvtimeout 50000//Timeout Modify the Listen section to the following listen Webcluster 0.0.0.0:80//Specify node service option Httpchk GET/      Test.html//get Submission Method access time back Add test.html balance roundrobin server inst1 192.168.100.102:80 check Inter fall 3  Server Inst2 192.168.100.103:80 check Inter fall 3cp/opt/haproxy-1.5.19/examples/haproxy.init/etc/init.d/haproxy Start the script service Haproxy startStart the service and then you can access multiple rinses, nginx1 and nginx2 page rotation display. 

    Log optimization for Haproxy

  • The Haproxy log is output to syslog in the system by default. Not very convenient to view, in order to better manage the Haproxy log, we need to define the log separately
    vim /etc/haproxy/haproxy.cfg log /dev/log    local0 info     //信息提示个告警分离开log /dev/log    local0 notice  // 删除原有的 替换service haproxy restart

Touch/etc/rsyslog.d/haproxy.conf

vim/etc/rsyslog.d/haproxy.conf//Insert the following words

if ($programname = = ' Haproxy ' and $syslogseverity-text = = ' info ')//More type
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

Deploying Haproxy and Nginx to build Web clusters on CentOS7

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.