天天看点

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,如需转载请自行联系原作者

继续阅读