脚本一启动的速度要快一些哦,因为脚本二要判断两次以后才启动哎

这两个一般配合keepalived使用

脚本一:

#!/bin/bash
#author:fansik
#description:check nginx service run=`ps -C nginx --no-header | wc -l`
if [ $run -eq ]
then
/etc/rc.d/init.d/nginx start
sleep
fi

脚本二:

#!/bin/bash
#author:fansik
#description:check nginx service count=
for (( k=; k<; k++ ))
do
check_code=$( curl --connect-timeout -sL -w "%{http_code}\\n" http://localhost/index.html -o /dev/null )
if [ "$check_code" != "" ]; then
count=$(expr $count + )
sleep
continue
else
count=
break
fi
done
if [ "$count" != "" ]; then
/etc/init.d/nginx start
exit
else
exit
fi

keepalived的配置文件/etc/init.d/keepalived.conf:主配置文件如下,从配置文件将MASTER改成BACKUP,双主模型的时候在添加一个vrrp_instance VI_1主里面变成BACKUP,从里面变成MASTER,virtual_router_id变一下

! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from fanjb@localhost
smtp_server 127.0.0.1
smtp_connect_timeout
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx1.sh"
interval
weight -
fall
rise
} vrrp_script chk_notify {
script "/etc/keepalived/chk_nginx.sh"
interval
weight -
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
10.10.10.250
}
track_script {
chk_nginx
chk_notify
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}

通知脚本:/etc/keepalived/nodify.sh

#!/bin/bash
#author:fansik
#description:check nging status vip=10.10.10.250
contact='root@localhost' notify() {
mailsubject="`hostname` to be $1:$vip floating"
mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` change to be $1"
echo $mailbody | mail -s "$mailsubject" $contact
} case "$1" in
master)
notify master
exit
;;
backup)
notify backup
exit
;;
fault)
notify fault
exit
;;
*)
echo "Usage:`basename $0` {master|backup|fault}"
exit
;;
esac

keepalived+nginx配置文件及检查nginx服务的脚本的更多相关文章

  1. Nginx的编译安装及服务启动脚本

    1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries".同时,还需 ...

  2. nginx之旅(第一篇):nginx下载安装、nginx启动与关闭、nginx配置文件详解、nginx默认网站

    一.nginx下载安装 版本nginx 1.15.5 系统环境centos7.5(本机ip192.168.199.228) 关闭selinux 和防火墙firewall 1.下载 wget http: ...

  3. Nginx配置文件、优化详解

    上篇<编译安装nginx>已将nginx安装好,这篇写nginx配置文件和部分优化参数. 查看nginx的配置文件路径,可以使用nginx配置文件检查命令nginx -t: [root@n ...

  4. linux下如何查找nginx配置文件的位置

    nginx的配置放在nginx.conf文件中,一般我们可以使用以下命令查看服务器中存在的nginx.conf文件. locate nginx.conf /usr/local/etc/nginx/ng ...

  5. nginx配置文件详解(三)

    nginx配置文件详细解析 nginx安装目录:  /usr/local/nginx 配置文件:  /usr/local/nginx/conf 目录下的 nginx.conf文件 nginx优化方法1 ...

  6. Nginx系列一:正向代理和反向代理、Nginx工作原理、Nginx常用命令和升级、搭建Nginx负载均衡

    转自https://www.cnblogs.com/leeSmall/p/9351343.html 仅供个人学习 一.什么是正向代理.什么是反向代理 1. 正向代理,意思是一个位于客户端和原始服务器( ...

  7. Nginx(四)-- Nginx的扩展-OpenRestry

    1. OpenResty 安装及使用 OpenResty 是一个通过 Lua 扩展 Nginx 实现的可伸缩的 Web 平台,内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地 ...

  8. 检查nginx后端real server脚本,实现发现宕机剔除,恢复服务自动加入功能

    #!/bin/bash #Author: Liang WeiCheng ip_array=($(grep "server 10.112.84" /etc/nginx/nginx.c ...

  9. Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)

    一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含义就是某个URL重写成特定的URL(类似于Redirect),从某种意义上说为了美观或者对搜索引擎友好, ...

随机推荐

  1. ubuntu关于apache服务命令

    一.Start Apache 2 Server /启动apache服务 # /etc/init.d/apache2 startor$ sudo /etc/init.d/apache2 start 二. ...

  2. DotNetBar for Windows Forms 12.1.0.0_冰河之刃重打包版 原创发布

    关于 DotNetBar for Windows Forms 12.1.0.0_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

  3. 【转】Java反射 之 反射基础

    一.反射 反射:Java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为 ...

  4. jQuery--事件总结

    标准的绑定: bind(type,[,data],fn)==>第一个参数是事件类型 第二个可选参数作为event.data 传递给事件对象的额外数据对象 第三个参数为用来绑定的处理函数 简写绑定 ...

  5. Java_DOM创建XML

    import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream; ...

  6. hosts持续更新

    Google hosts网址: https://laod.cn/hosts/2016-google-hosts.html

  7. Isolation-based Anomaly Detection

    Anomalies are data points that are few and different. As a result of these properties, we show that, ...

  8. 深入理解unslider.js源码

    最近用到了一个挺好用的幻灯片插件,叫做unslider.js,就想看看怎么实现幻灯片功能,就看看源码,顺便自己也学习学习.看完之后收获很多,这里和大家分享一下. unslider.js 源码和使用教程 ...

  9. linux msql

    安装mysql 1.使用rpm 安装mysql 或者使用yum安装 使用rpm 安装 下载 Centos 7 所需要的mysql包 tar -xf 解压整合包 根据依赖 安装 common>li ...

  10. C++ Windows进程管理

    功能: 1.各个进程启动.挂起.恢复.停止等 2.监听进程的运行状态,进程退出(正常.非正常)时,通知用户 3.异步队列 4.线程安全 进程管理器类: #ifndef __ProcessManager ...