环境:
系统:CentOS 5.6 X86_64
Nginx:nginx-1.2.4
拓扑:
— 10.0.1.201:1433
LB(10.0.1.212:1433)——-|
— 10.0.1.202:1433
默认nginx不支持tcp的负载均衡,需要打补丁,(连接方式:从客户端收到一个连接,将从本地新建一个连接发起到后端服务器),具体配置如下:
一、安装Nginx
1.下载nginx
# wget http://nginx.org/download/nginx-1.2.4.tar.gz
2.下载tcp模块补丁
# wget https://github.com/yaoweibin/nginx_tcp_proxy_module/tarball/master
源码主页: https://github.com/yaoweibin/nginx_tcp_proxy_module
3.安装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
二、修改配置文件
修改nginx.conf配置文件
# 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;
}
}
三、启动nginx
# cd /usr/local/nginx/sbin/
# ./nginx
查看1433端口:
#lsof :1433
四、测试
# telnet 10.0.1.201 1433
五、使用sql server client工具测试