博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos6.5 keepalived检测脚本
阅读量:6903 次
发布时间:2019-06-27

本文共 1910 字,大约阅读时间需要 6 分钟。

一,keepalived配置文件修改

1,master 上配置keepalived

cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {   router_id LVS_1}vrrp_script chk_ngx {    script "/data/shell/health_chk.sh"    interval 2    weight 2}vrrp_instance VI_1 {    state MASTER    interface eth1    virtual_router_id 51    priority 100    advert_int 1    nopreempt        #设置 nopreempt 防止抢占资源,只生效BACKUP节点    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.20.22    }    track_script {        chk_ngx    }}

 

2,backup 上配置keepalived

cat /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {   router_id LVS_2}vrrp_script chk_ngx {        script "/data/shell/health_chk.sh"        interval 2        weight 2}vrrp_instance VI_1 {    state BACKUP    interface eth1    virtual_router_id 51    nopreempt    priority 99    advert_int 1    nopreempt            #设置 nopreempt 防止抢占资源,只生效BACKUP节点    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.20.22    }    track_script {        chk_ngx    }}

3,健康检测脚本

cat health_chk.sh#!/bin/bashA=`ps -C nginx --no-header |wc -l`B=`ps aux|grep -v grep |grep 'zookeeper.properties' |wc -l`C=`ps aux|grep -v grep |grep 'server.properties' |wc -l`if [ $A -eq 0 ];then      /usr/sbin/nginx      sleep 3      if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then        /etc/init.d/keepalived stop      fifiif [ $B -eq 0 ];then    /etc/init.d/zookeeper start    sleep 3    if [ `ps aux|grep -v grep |grep 'zookeeper.properties' |wc -l` -eq 0 ];then        /etc/init.d/keepalived stop    fifiif [ $C -eq 0 ];then    /etc/init.d/kafka start    sleep 3    if [ `ps aux|grep -v grep |grep 'server.properties' |wc -l` -eq 0 ];then        /etc/init.d/keepalived stop    fifi

nginx、zk、kafka都是可以正常启动的应用。可自行更改。

此文可结合进行测试。

转载于:https://www.cnblogs.com/fuhai0815/p/9796769.html

你可能感兴趣的文章
学习html我们从百度百科开始
查看>>
如何Spring Cloud Zuul作为网关的分布式系统中整合Swagger文档在同一个页面上
查看>>
实现一个炫酷的随机标签排列效果(颜色随机,大小随机,成菱形排列的列表)...
查看>>
flex 布局
查看>>
数字资产交易所开发:平台币快速吸金的背后
查看>>
小程序自定义音频组件,带滚动条,IOS循环失效问题
查看>>
Swift开发之粒子动画的实现
查看>>
我学Java我傲娇
查看>>
挖矿蠕虫肆虐,详解云防火墙如何轻松“制敌”
查看>>
Linux -- Samba之客户端访问(Linux和windows)
查看>>
八个Docker的真实应用场景
查看>>
vpc的使用方法
查看>>
GitExtensions GitCredentialWinStore syntax error near unexpected token `('
查看>>
Java获取EXE文件图标的方法
查看>>
“驱动程序在 \Device\Harddisk0\D 上检测到控制器错误”的根本解决办法!
查看>>
ubuntu 之修改权限的问题
查看>>
php 框架ci去index.php的方法
查看>>
Hyper-v学习(四),SMB虚拟机实时迁移
查看>>
基于spring3注解的google分页
查看>>
实用命令行工具详解—crontab
查看>>