1. Download
Nginx Download, the latest version is 1.11.5
Address: http://nginx.org/en/download.html
PCRE (Nginx installation required dependency package) download
Address: https://sourceforge.net/projects/pcre/files/pcre/
Nginx_upstream_check_module (Nginx back end node Health Check plugin) download
Address: Https://github.com/yaoweibin/nginx_upstream_check_module
2. Installation
Download the three packages:
Nginx-1.11.5.tar.gz,
Pcre-8.39.tar.gz,
Nginx_upstream_check_module-master.zip
Placed under the/home/hdfs/directory.
2.1. Install the dependency package Pcre first
cd/home/hdfs/
TAR-XZVF pcre-8.39.tar.gz
CD pcre-8.39
./configure
Make
Make install
==============================================================================
2.2. Installing Nginx
Unzip Nginx_upstream_check_module-master.zip #解压
TAR-XZVF nginx-1.11.5.tar.gz
CD./nginx-1.11.5/src
Patch-p1
#找到刚刚解压的nginx_upstream_check_module目录下和nginx版本对应的补丁,
./configure--prefix=/usr/local/nginx--conf-path=/usr/local/nginx/conf/nginx.conf--with-http_realip_module-- With-http_addition_module--with-http_gzip_static_module--with-http_random_index_module--with-http_stub_status_ Module--with-http_sub_module--with-http_dav_module--with-openssl=/usr/local/src/openssl-1.0.1g--add-module=/ home/hdfs/nginx_upstream_check_module-master/
If this process is an error:
./configure:error:the HTTP gzip module requires the Zlib library.
You can either disable the module by using--without-http_gzip_module
option, or install the Zlib library into the system, or build the Zlib library
Statically from the source with Nginx by using--with-zlib=<path> option.
Execution: Yum install-y zlib-devel according to Zlib pack
Make install
Do not error installation completed.
===============================================================================3. Configuring load Balancing and health checks
Enter Nginx according to the directory,
Cd/usr/local/nginx/conf
More nginx.conf, the key configuration is as follows:
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Keepalive_timeout 65;
#gzip on;
Upstream 172.19.189.53{#负载均衡配置, the default policy, according to time successively, there are other by IP hash, weight
Server 172.19.189.49:7070;
Server 172.19.189.50:7070;
Server 172.19.189.51:7070;
Check interval=3000 rise=2 fall=3 timeout=3000 type=http port=7070;
# interval=3000: Interval 3 seconds check, rise=2: Check 2 times OK backend node up,fall=3: Three check failed backend node down,timeout=3000: Timeout 3 seconds, type=http: Send HTTP Check request type, port=7070 check the port, which can be omitted, and the default is the same as the port in server 172.19.189.49:7070.
Check_http_send "Head/kylin http/1.0\r\n\r\n"; ①
Check_http_expect_alive http_2xx http_3xx;
}
server {
Listen 8880; #nginx监听的端口, can be modified.
server_name kylin_balance;
Location/{
Proxy_pass http://172.19.189.53; #反向代理, which application server the agent----②
Proxy_set_header Host $host; #此下三行设置把客户端的真实ip传给后端, can save
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Root HTML, #请求到达nginx服务器后, can not be distributed, will go to the Nginx installation directory root search page
Index index.html index.htm; #默认找index. html, customizable page
}
Location/status {#健康检查
Check_status;
Access_log off;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {#错误页面
root HTML;
}
}
}
Note: ①, if the request URL type is http://ip:port/name type, here the setting to add/kylin after head, otherwise the backend Health check node has been down.
②, this URL is a part of the request domain name that accesses the app service, such as app service deployment in
172.19.189.49/172.19.189.50/172.19.189.51 Three
The request URL that does not pass Nginx is: Http://172.19.189.49:7070/kylin, the request URL that accesses through Nginx is:/http 172.19.189.53:8880/.
Start after modifying configuration./nginx, if you encounter error while loading shared Libraries:libpcre.so.1:cannot open Shared object file:no such file or dir Ectory
How many bits of the system are viewed by Uname–a:
If it is a 32-bit system: Ln-s/usr/local/lib/libpcre.so.1/lib
If it is a 64-bit system: Ln-s/usr/local/lib/libpcre.so.1/lib64
4. View load Balancing and node health:
1. Load Balancing
1.1 This method, is also installed in other application server Nginx, the root of the index.html to display the contents of the native IP, so that the page input request, you can visually see the load is balanced.
1.2 By viewing the log of the service, open the log of the application on multiple servers and see if the request is distributed to different machines.
2. Node health status Monitoring
If the monitored services are normal, the status shows up as shown below
Stop service on 49, after a short time, the status is displayed down
Note: Nginx Start stop command:
Nginx-s Stop/start/reload (Modify the configuration file nginx.conf Direct reload to take effect, do not have to stop after the start)
Reference article Links:
Http://www.linuxidc.com/Linux/2015-03/114988.htm
Http://www.linuxidc.com/Linux/2015-03/114986.htm