keepalived+nginx配置文件及检查nginx服务的脚本
脚本一启动的速度要快一些哦,因为脚本二要判断两次以后才启动哎
这两个一般配合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服务的脚本的更多相关文章
- Nginx的编译安装及服务启动脚本
1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries".同时,还需 ...
- nginx之旅(第一篇):nginx下载安装、nginx启动与关闭、nginx配置文件详解、nginx默认网站
一.nginx下载安装 版本nginx 1.15.5 系统环境centos7.5(本机ip192.168.199.228) 关闭selinux 和防火墙firewall 1.下载 wget http: ...
- Nginx配置文件、优化详解
上篇<编译安装nginx>已将nginx安装好,这篇写nginx配置文件和部分优化参数. 查看nginx的配置文件路径,可以使用nginx配置文件检查命令nginx -t: [root@n ...
- linux下如何查找nginx配置文件的位置
nginx的配置放在nginx.conf文件中,一般我们可以使用以下命令查看服务器中存在的nginx.conf文件. locate nginx.conf /usr/local/etc/nginx/ng ...
- nginx配置文件详解(三)
nginx配置文件详细解析 nginx安装目录: /usr/local/nginx 配置文件: /usr/local/nginx/conf 目录下的 nginx.conf文件 nginx优化方法1 ...
- Nginx系列一:正向代理和反向代理、Nginx工作原理、Nginx常用命令和升级、搭建Nginx负载均衡
转自https://www.cnblogs.com/leeSmall/p/9351343.html 仅供个人学习 一.什么是正向代理.什么是反向代理 1. 正向代理,意思是一个位于客户端和原始服务器( ...
- Nginx(四)-- Nginx的扩展-OpenRestry
1. OpenResty 安装及使用 OpenResty 是一个通过 Lua 扩展 Nginx 实现的可伸缩的 Web 平台,内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地 ...
- 检查nginx后端real server脚本,实现发现宕机剔除,恢复服务自动加入功能
#!/bin/bash #Author: Liang WeiCheng ip_array=($(grep "server 10.112.84" /etc/nginx/nginx.c ...
- Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)
一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含义就是某个URL重写成特定的URL(类似于Redirect),从某种意义上说为了美观或者对搜索引擎友好, ...
随机推荐
- 第四篇.Bootstrap网格系统偏移列和嵌套列
偏移列: 在bootstrap网格系统中我们可以使用偏移列来达到让某列右移的效果,如下所示: <div class="row"> <div class=" ...
- iOS App 获取从后台返回前台时的页面
产品美美的给小伙伴提了一个需求,当程序从后台进入前台时,如果是指定的页面,则弹出提示框. 大家首先想到的方法就是通过 AppDelegate.h 进行控制,相对复杂的步骤就是 在程序进入后台时对当前页 ...
- STM32——assert_param(expr)
在STM32的固件库和提供的例程中,到处都可以见到assert_param()的使用.如果打开任何一个例程中的stm32f10x_conf.h文件,就可以看到实际上assert_param是一个宏定义 ...
- Python开发入门与实战13-基于模板的界面
13. 基于模板的界面 本章我们将继续基于库存的简单例子来阐述如何在python django中体现MVC的架构,根据djangobook说明: M:数据存取部分,由django数据库层处理,本章要讲 ...
- selenium问题记录
错误一: 错误信息:Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: 原 ...
- 横向滑动的GridView
思路: GridView行数设置为一行,外面套一个HorizontalScrollView,代码中设置GridView宽度 xml代码 <HorizontalScrollView android ...
- 通过a++来理解闭包改变作用域的问题
纯属个人理解,如果有误请指出! 让我们先看一段代码 function dog(){ var a=100; a++; return a; } alert(dog()); alert(dog()); 我们 ...
- 用DropBox分享Unity3D的Web应用
用U3D做好游戏好想分享给亲朋好友体验怎么办?导出exe,apk都可以,只是下载始终是个门槛. 幸好还可以导出web版(虽然要安装unity3d的插件),但自己没有服务器怎么办,没关系~,现 在是云时 ...
- vs2012 检测到有潜在危险的 Request.Form 值
今天用vs2012写网站,其中要用到网页编辑器,调试时提示:检测到有潜在危险的 Request.Form 值随即上网搜索: 解决方法一:具体页面添加 ValidateRequest="fal ...
- PKU 1003解题
首先庆祝一下,今天连A了3题.感觉后面这题太简单了.. 由于英文不好 ,找了个翻译: 若将一叠卡片放在一张桌子的边缘,你能放多远?如果你有一张卡片,你最远能达到卡片长度的一半.(我们假定卡片都正放在桌 ...