: This article describes how to implement layer-4 load balancing for nginx. For more information about PHP tutorials, see. Environment:
System: CentOS 5.6 X86_64
Nginx: nginx-1.2.4
Topology:
-10.0.1.201: 1433
LB (10.0.1.212: 1433) --- |
-10.0.1.202: 1433
By default, nginx does not support tcp server load balancer and requires patching. (connection method: after a connection is received from the client, a new connection is created locally and initiated to the backend server.) the configuration is as follows:
1. install Nginx
1. download nginx
# Wget http://nginx.org/download/nginx-1.2.4.tar.gz
2. download the tcp module patch
# Wget https://github.com/yaoweibin/nginx_tcp_proxy_module/tarball/master
SOURCE page: https://github.com/yaoweibin/nginx_tcp_proxy_module
3. install nginx
# Tar xvf nginx-1.2.4.tar.gz
# Tar xvf yaoweibin-nginx_tcp_proxy_module-v0.4-45-ga40c99a.tar.gz
# Cd nginx-1.2.4
# Patch-p1 <../yaoweibin-nginx_tcp_proxy_module-a40c99a/tcp. patch
#./Configure -- prefix =/usr/local/nginx -- with-pcre =.../pcre-8.30 -- add-module = ../yaoweibin-nginx_tcp_proxy_module-ae321fd/
# Make
# Make install
II. modify the configuration file
Modify the nginx. conf configuration file
# Cd/usr/local/nginx/conf
# Vim nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Tcp {
Upstream mssql {
Server 10.0.1.201: 1433;
Server 10.0.1.202: 1433;
Check interval = 3000 rise = 2 fall = 5 timeout = 1000;
}
Server {
Listen 1433;
Server_name 10.0.1.212;
Proxy_pass mssql;
}
}
3. start nginx
# Cd/usr/local/nginx/sbin/
#./Nginx
View Port 1433:
# Lsof: 1433
IV. test
# Telnet 10.0.1.201 1433
V. test with SQL server client
Summary: nginx supports Layer-4 server load balancer. you only need to install a patch package! In many cases, layer 4 and Layer 7 coexist in enterprises. if your server is under low pressure, you do not have to use the lvs-nginx model, it is a good choice to achieve a balance between layer 4 and Layer 7 with nginx + patching!
The above describes how to implement layer-4 load balancing for nginx, including some content. I hope to help anyone who is interested in PHP tutorials.