使用nginx的tcp負載解決exchange2016的客戶端訪問負載

Ace_xiao發表於2017-11-07

安裝nginx過程就參考nginx官網咖,

這裡提供一下具體我的測試環境中nginx的配置

修改配置檔案:

vim /etc/nginx/nginx.conf

具體內容如下:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections  1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}
#負載exchange2016前端的模組配置

stream {
    upstream mail {
        least_conn;//連線數進行負載
        server 172.20.224.136:443 max_fails=2 fail_timeout=10s;//被動檢查伺服器響應
        server 172.20.224.57:443 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        443;
        proxy_pass    mail;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
    upstream smtp {
        least_conn;
        server 172.20.224.136:25 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:25 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        25;
        proxy_pass    smtp;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
    upstream pop {
        least_conn;
        server 172.20.224.136:110 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:110 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        110;
        proxy_pass    pop;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
    upstream imap {
        least_conn;
        server 172.20.224.136:143 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:143 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        143;
        proxy_pass    imap;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
    upstream pops {
        least_conn;
        server 172.20.224.136:995 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:995 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        995;
        proxy_pass    pops;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
        upstream imaps {
        least_conn;
        server 172.20.224.136:993 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:993 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        993;
        proxy_pass    imaps;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
    upstream smtps {
        least_conn;
        server 172.20.224.136:587 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:587 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        587;
        proxy_pass    smtps;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }
        upstream smtps1 {
        least_conn;
        server 172.20.224.136:465 max_fails=2 fail_timeout=10s;
        server 172.20.224.57:465 max_fails=2 fail_timeout=10s;
        }
    server {
        listen        465;
        proxy_pass    smtps1;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }

   }

配置使用wq推出儲存,在使用命令 
cd /etc/nginx/nginx.d
nginx -s reload
重新載入服務之後就可以使用了

相關文章