CentOS Installation Configuration Haproxy+nginx environment

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


Install Nginx (as HTTP server) and Haproxy (reverse proxy) in the test environment, and configure Haproxy log output to/var/log/haproxy.log, take note.

It should be explained that this is only a basic installation, configuration method, and does not involve specific usage in a production environment.


First, install Nginx

1. Preparation environment

Yum install-y gcc #一般都有yum install-y gcc-c++ #非必须yum install-y pcre pcre-devel #正则匹配yum install-y zlib Zlib-dev El #gzip压缩yum install-y OpenSSL openssl-devel #https使用

2. Download (take nginx-1.9.15 as an example)

CD soft/wget "Http://nginx.org/download/nginx-1.9.15.tar.gz"

3. Installation

Installed by default under/usr/local/nginx/

TAR-XZVF nginx-1.9.15.tar.gzcd Nginx-1.9.15/./configuremakemake Install

4. Configuration

#配置文件路径:/usr/local/nginx/conf/nginx.conf

5. Start/Stop

#帮助:/usr/local/nginx/sbin/nginx-h# start:/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf# stop:/usr/ Local/nginx/sbin/nginx-s stop# Reload:/usr/local/nginx/sbin/nginx-s reload# view version:/usr/local/nginx/sbin/nginx-v

6. Testing

After the installation started, found that the browser can not access Nginx, after troubleshooting, due to firewall restrictions, after release normal:

/sbin/iptables-i input-p TCP--dport 80-j accept/sbin/iptables-l


Second, installation Haproxy

1. Installation

Yum Install Haproxy

2. Configuration

Configuration file Location:

/etc/haproxy/haproxy.cfg

In the last few lines, the backend is configured with Nginx of the cost machine, as follows:

# in real-world applications, multiple different back-end IPs will be configured, and multiple backend services will be available. #---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------backend app balance Roundrobin ser Ver app1 127.0.0.1:80 Check server app2 127.0.0.1:80 Check server app3 127.0.0.1:80 Check server APP4 127.0.0 .1:80 Check

3. Start

#帮助: haproxy-h# start: haproxy-f/etc/haproxy/haproxy.cfg# restart: haproxy-f/etc/haproxy/haproxy.cfg-sf ' cat/var/run/ Haproxy.pid ' #版本: haproxy-v

4. Testing

Set up the firewall (5000 for haproxy Port):

/sbin/iptables-i input-p TCP--dport 5000-j ACCEPT

With a browser access to Haproxy (Port 5000), you can see that the final access is index.html under the Nginx server.


Third, configure the Haproxy log output

1, Configuration Haproxy

Configuration file Location:

/etc/haproxy/haproxy.cfg

You can keep the default log entry:

Log 127.0.0.1 Local2

You can increase the log format description as needed:

Log-format < Specify formats >

If you change the configuration, you need to restart the operation:

Haproxy-f/etc/haproxy/haproxy.cfg-sf ' Cat/var/run/haproxy.pid '

2, Configuration Rsyslog

Configuration file Location:

/etc/rsyslog.conf

Remove these four lines of comments:

# provides UDP syslog reception$modload imudp$udpserverrun 514# provides TCP syslog reception$modload Imtcp$inputtcpserve Rrun 514

To add a log path for Local2:

# Save Haproxy log to haproxy.loglocal2.*/var/log/haproxy.log

Last reboot Rsyslog:

/etc/init.d/rsyslog restart

Once again with the browser test access Haproxy, you can see the log output to the/var/log/haproxy.log

And you can see from the log that Haproxy is in turn accessing the backend app1~app4, although they are all the same service (Ip:port)



Finish



This article is from the "11484324" blog, please be sure to keep this source http://11494324.blog.51cto.com/11484324/1772372

CentOS Installation Configuration Haproxy+nginx environment

Related Article

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.