keepalived ,egnix ,tomcat 高可用,高并发 应用架构的搭建

keepalived ,egnix ,tomcat 高可用,高并发 应用架构的搭建


keepalived 中需要构建Virtual IP 地址 ,并创建一个nginx  check 文件 检测  nginx Server 运行状态 ,如果ngnix  进程不可访问,则kill掉killall keepalived 进程,实现VIP 漂移

ngnix 托管tocmat 服务器地址,因此在tomcat web 服务器上不再需要LVS 功能 即 去掉 lo:A  设备的绑定


本架构共四台机器 :


服务器 A ,IP   192.168.168.101  安装 keepalived ,ngnix  ,配置 keepalived(MASTER) ,ngnix(A,B ngnxi 配置要完全相同),不需要lvs

服务器 B ,IP   192.168.168.102  安装 keepalived ,ngnix  ,配置 keepalived(BACKUP) ,ngnix(A,B ngnxi 配置要完全相同),不需要lvs

服务器 C,IP   192.168.168.103   安装tomcat ,不需要lvs

服务器 D,IP   192.168.168.104   安装tomcat,不需要lvs


示例 keepalived 配置:


! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from hello@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_script check_nginx {
   script "/home/check_nginx.sh"
   interval 2
   weight 2
}
 
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 199
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    192.168.239.100/24 dev eth0 label eth0:1
    }
    track_script {
       check_nginx
    }
}


====

check_nginx,sh

#!/bin/bash
#
URL="http://192.168.239.30/"
code=`curl -I -m 5 -o /dev/null -s -w %{http_code} $URL`
if [ $code -ne 200 ];then
  sleep 2
  code=`curl -I -m 5 -o /dev/null -s -w %{http_code} $URL`
  if [ $code -ne 200 ];then
     killall keepalived
  fi
fi



====

示例 ngnix  配置:


 upstream yxh {
       server 192.168.184.188:8080 weight=1;
       server 192.168.184.168:8080 weight=1;
      # check interval=3000 rise=2 fall=5 timeout=1000 type=http;
      # check_http_send "HEAD / HTTP/1.0\r\n\r\n";
      # check_http_expect_alive http_2xx http_3xx;
     }
     server {
        listen       80;
        server_name  www.host1.com;
        location / {
            #root   html;
            #index  index.html index.htm;
            #-----------
            #auth_basic "hi who are you ?";
            #auth_basic_user_file /var/users;
            #index index.html index.htm;
            #------------------
            #proxy_pass http://192.168.184.168:8080/;
             proxy_pass http://yuxh/;
            #index index.html index.htm;
        }












posted @ 2016-05-15 16:35  yuerspring  阅读(133)  评论(0编辑  收藏  举报