天天看點

openfire叢集+nginx負載均衡

openfire有通過tcp端口通訊,是以nginx需要額外安裝nginx_tcp_proxy_module.

nginx tcp代理功能由nginx_tcp_proxy_module子產品提供,同時監測後端主機狀态。該子產品包括的子產品有: ngx_tcp_module, ngx_tcp_core_module, ngx_tcp_upstream_module, ngx_tcp_proxy_module, ngx_tcp_upstream_ip_hash_module。

安裝:

使用nginx最新版nginx-1-10.1.tar.gz

下載下傳nginx_tcp_proxy_module 位址:

<a href="http://blog.51cto.com/lookingdream/1844829#">?</a>

<code>https:</code><code>//github</code><code>.com</code><code>/yaoweibin/nginx_tcp_proxy_module/archive/master</code><code>.zip</code>

tar -xzvf nginx-1.10.1.tar.gz

cd nginx-1.10.1

patch -p1 &lt; /root/nginx_tcp_proxy_module-master/tcp.patch  打更新檔

./configure --prefix=/usr/local/nginx --add-module=/root/nginx_tcp_proxy_module-master 編譯

make&amp;make install

nginx 配置檔案:

# vim /etc/nginx/nginx.conf    

tcp  {   //添加  

    timeout 1d;  

    proxy_read_timeout 10d;  

    proxy_send_timeout 10d;  

    proxy_connect_timeout 30;  

    upstream openfire5222{  

        server 192.168.253.150:5222;  

        server 192.168.253.151:5222;  

         check interval=3000 rise=2 fall=5 timeout=1000;  

    }  

    server{  

        listen 6222;  nginx安裝在192.168.253.151上面 是以這裡的端口不能跟151上面的端口重複

        proxy_pass openfire5222;  

        so_keepalive on;  

        tcp_nodelay on;  

    upstream openfire5223{  

        server 192.168.253.150:5222;  

        check interval=3000 rise=2 fall=5 timeout=1000;  

        listen 6223;  

        proxy_pass openfire5223;  

}  

http{  //添加以下内容  

。。。。。。。。。。。。省略。。。。。。。。。。。。。。  

    upstream openfire7070{  

        server 192.168.253.151:7070;  

        server 192.168.253.150:7070;  

        listen 17070;  

        server_name 192.168.253.151;  

        location / {  

            proxy_pass http://openfire7070;  

        }  

    upstream openfire9090{  

        server 192.168.253.150:9090;  

        server 192.168.253.151:9090;  

         ip_hash;  

    server {  

        listen 19090;  

            proxy_pass http://openfire9090;  

啟動nginx。

登入192.168.253.151:19090檢視,

或者用用戶端spark登入均可。

     本文轉自yzy121403725 51CTO部落格,原文連結:http://blog.51cto.com/lookingdream/1844829,如需轉載請自行聯系原作者

繼續閱讀