nginx&tomcat with keepalived for configing cluster

rpm -ql keepalived

rpm --ivh keepalived

mkdir -p /var/temp/nginx

#nginx source  install

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi


make install


single nginx
××××××××××××××××××××××pc-133&pc-134××××××××tomcat cluster××××××××××××××
edit nginx.conf

upstream tomcate_server {
    server 192.168.190.133 weight=20;
    server 192.168.190.134 weight=10;
}
server {
location / {
    proxy_pass http://tomcate_server;
    ...
    ...
}

..
}



****************config keepalived********************

global_defs {
#   notification_email { #
#     [email protected]
#     [email protected]
#     [email protected]
#   }
#   notification_email_from [email protected]
#   smtp_server 192.168.200.1
#   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_script check_nginx_status {

    script "/etc/keepalived/check_nginx_status.sh"

   interval  2

   weight 2

}

vrrp_instance VI_1 {
    state MASTER    #master
    interface eth0
    virtual_router_id 51 #
    advert_int 1 #
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.190.138   #
       # 192.168.200.17 #
       # 192.168.200.18 #
    }
}

×××××××××××××××××××keepalived back up×××××××

global_defs {
#   notification_email { #
#     [email protected]
#     [email protected]
#     [email protected]
#   }
#   notification_email_from [email protected]
#   smtp_server 192.168.200.1
#   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP    
    interface eth0
    virtual_router_id 51
    priority 99    #prio
    advert_int 1 #
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.190.138    # virtual IP
       # 192.168.200.17 # banding IP
       # 192.168.200.18 # banding IP
    }
}

**********************keepalived script********

#!/bin/bash

nginxVal=`ps -C nginx--no-header |wc -l` 

if [ $nginxVal -eq 0 ];then

servicekeepalived stop

fi


#other command

ip show addr eth0

service keepalived status/start/stop.restart

./sbin/nginx -s quit

你可能感兴趣的:(nginx)