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 { #
#     acassen@firewall.loc
#     failover@firewall.loc
#     sysadmin@firewall.loc
#   }
#   notification_email_from Alexandre.Cassen@firewall.loc
#   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 { #
#     acassen@firewall.loc
#     failover@firewall.loc
#     sysadmin@firewall.loc
#   }
#   notification_email_from Alexandre.Cassen@firewall.loc
#   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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值