Windows 下使用nginx对SqlServer进行负载均衡

windows 下使用nginx对SqlServer进行负载均衡
1.自从nginx版本1.9之后,nginx 便增加了对tcp与udp协议的支持
官方文档
The ngx_stream_core_module module is available since version 1.9.0. This module is not built by default, it should be enabled with the –with-stream configuration parameter.
2.但是在linux下默认不安装这个模块,需要在编译时通过指定 –with-stream 参数来激活这个模块。
https://nginx.org/en/docs/stream/ngx_stream_core_module.html
在windows下
1.我希望在window下做mysql的均衡
D:ToolsWebServerNginxnginx-1.13.5>nginx.exe -V

版本信息

nginx version: nginx/1.13.5
built by cl 16.00.40219.01 for 80x86
built with OpenSSL 1.0.2l 25 May 2017
TLS SNI support enabled

安装的模块

configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre-8.41 --with-zlib=objs.msvc8/lib/zlib-1.2.11 --with-select_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.0.2l --with-openssl-opt=no-asm --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module

Windows 下使用nginx对SqlServer进行负载均衡

4.免去了window下编译nginx的步骤
1.修改nginx.conf

stream 测试mysql均衡 2017-9-11

stream
{

upstream mssql{
    hash $remote_addr consistent;
server 127.0.0.1:49905 max_fails=3 fail_timeout=30s;
    server 127.0.0.1:1433 max_fails=3 fail_timeout=30s;

}
server {
    listen 1444;
    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass mssql;

}

}

简单的测试配置,更详细请参考官方文档

https://nginx.org/en/docs/stream/ngx_stream_core_module.html

Windows 下使用nginx对SqlServer进行负载均衡

2.注意:如果你在本机上(Nginx与SqlServer都在同一机器上)做测试,server的端口不要为1433,不然会SqlServer的端口冲突
3.如果是生产环境,负载均衡服务器与SqlServer不在同一机器,可以为1433
4.启动nginx,启动sqlserver
5.你可以使用命令行来查看端口占用,查看nginx是否运行成功
netstat -ano|findstr "1444"
Windows 下使用nginx对SqlServer进行负载均衡

使用nginx的地址与端口,直接连接sqlserver,查看是否连接成功
127.0.0.1,1444
Windows 下使用nginx对SqlServer进行负载均衡
使用SQLServert管理工具进行连接测试

Windows 下使用nginx对SqlServer进行负载均衡
Windows 下使用nginx对SqlServer进行负载均衡

SqlServer的负载均衡
1.以上测试,只使用了一台SqlServer服务器,真正的负载均衡可不会
2.还要做以下的工作,创建SqlServer的集群,将SqlServer的数据同步。

上一篇:C#并发编程经典实例--并发编程概述


下一篇:Orleans 支持Linq 表达式参数