KeepLived + nginx 高可用
. 环境准备
1. VMware;
2. 4台CentOs7虚拟主机:192.168.122.217, 192.168.122.165
3. 系统服务:LVS, Keepalived
4. Web服务器:nginx
. 软件安装
在2台虚拟机上,我们以如下方式搭建集群:
192.168.122.217 nginx-1+keepalived-1
192.168.122.165 nginx-2+keepalived-2
两台机器安装keeplived和nginx
yum install -y keepalived nginx
接下来我们要配置keeplive服务
192.168.122.217配置
cat > /etc/keepalived/keepalived.conf <<EOF
! Configuration File for keepalived
global_defs {
router_id 192.168.122.217
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval
weight -
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
mcast_src_ip 192.168.122.217
nopreempt
authentication {
auth_type PASS
auth_pass
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.50
}
}
EOF ## 192.168.122.217 为节点IP,192.168..50 VIP
192.168.122.165配置
cat > /etc/keepalived/keepalived.conf <<EOF
! Configuration File for keepalived
global_defs {
router_id 192.168.122.165
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval
weight -
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
mcast_src_ip 192.168.122.165
nopreempt
authentication {
auth_type PASS
auth_pass
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.50
}
}
EOF ## 192.168.122.165 为节点IP,192.168.122.50 VIP
创建健康检查脚本,脚本放在/etc/keepalived/check_nginx.sh ,两台机都要放
[root@fefgegrege opt]# cat check_nginx.sh
PORT_PROCESS=`ps aux|grep -v grep|grep nginx|wc -l`
if [ $PORT_PROCESS -eq ];then
echo "nginx Is Not Used,End."
exit
fi
echo "Check nginx Cant Be Empty!"
两台机启动keeplived
[root@gergergrehre]# systemctl enable --now keepalived
Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
启动完毕后ping 192.168.122.50 (VIP)
[root@hdththt ~]# ping 192.168.122.50
PING 192.168.122.50 (192.168.122.50) () bytes of data.
bytes from 192.168.122.50: icmp_seq= ttl= time=1.37 ms
bytes from 192.168.122.50: icmp_seq= ttl= time=0.515 ms
bytes from 192.168.122.50: icmp_seq= ttl= time=0.594 ms
bytes from 192.168.122.50: icmp_seq= ttl= time=0.831 ms
^C
--- 192.168.122.50 ping statistics ---
packets transmitted, received, % packet loss, time 3001ms
rtt min/avg/max/mdev = 0.515/0.829/1.376/0.336 ms #如果没有启动,请检查原因。 ps -ef|grep keep 检查是否启动成功
#没有启动成功,请执行下面命令,从新启动。启动成功vip肯定就通了
systemctl start keepalived
KeepLived + nginx 高可用的更多相关文章
- keepalived对nginx高可用演练脚本
keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...
- Keepalived保证Nginx高可用配置
Keepalived保证Nginx高可用配置部署环境 keepalived-1.2.18 nginx-1.6.2 VM虚拟机redhat6.5-x64:192.168.1.201.192.168.1. ...
- linux中keepalived实现nginx高可用配置
linux中keepalived实现nginx高可用配置 安装keepalived 运行如下命令即可 tar -zxvf keepalived-2.0.8.tar.gz -C /usr/src cd ...
- 配置keepalived支持nginx高可用
实验环境 序号 主机名 IP地址 1 nginx1 192.168.204.11 2 nginx2 192.168.204.12 安装nginx 安装nginx yum install -y epel ...
- 面试中的nginx高可用高并发!
本文转自:91博客:原文地址:http://www.9191boke.com/439923471.html 面试题: nginx高可用?nginx 是如何实现并发的?为什么nginx不使用多线程?ng ...
- 001/Nginx高可用模式下的负载均衡与动静分离(笔记)
Nginx高可用模式下的负载均衡与动静分离 Nginx(engine x)是一个高性能的HTTP和反向代理服务器,具有内存少,并发能力强特点. 1.处理静态文件.索引文件以及自动索引:打开文件描述符缓 ...
- Nginx(四):Keepalived+Nginx 高可用集群
Keepalived+Nginx 高可用集群 (主从模式) 集群架构图 安装keepalived [root@localhost ~]# yum install -y keepalived 查看状态 ...
- Docker下配置KeepAlive支持nginx高可用
案例子任务一.安装配置keepalived 步骤1:使用nginx镜像生成nginx-keep镜像 1) 启动nginx容器并进入 docker run -d --privileged nginx / ...
- 3.keepalived+脚本实现nginx高可用
标题 : 3.keepalived+脚本实现nginx高可用 目录 : Nginx 序号 : 3 else exit 0 fi else exit 0 fi - 需要保证脚本有执行权限,可以使用chm ...
随机推荐
- 属性.native用于解决第三方el组件库@click事件无效
描述 有时发现用一些第三方的组件库时,例如一个封装好的button按钮<el-butten>,绑定点击事件却没有任何作用,这时便需要加 .native 原因: v-on 是对 Vue 的事 ...
- Map、Filter和Reduce函数(Python)
Map map(function_to_apply, list_of_inputs) 设有以下代码: >>> items = [1, 2, 3, 4, 5] >>> ...
- PHP curl_reset函数
curl_reset— 重置libcurl会话句柄的所有选项. 说明 void curl_reset ( resource $ch ) 该函数将重新初始化cURL的所有选项值(默认值). 注意:cur ...
- BZOJ 3531: [Sdoi2014]旅行(树链剖分+线段树)
传送门 解题思路 以每个颜色为根开一棵权值线段树,下标就是\(dfs\)序,其余都是基本操作,要动态开点. 代码 #include<iostream> #include<cstdio ...
- 前端每日实战:73# 视频演示如何用纯 CSS 创作一只卡通狐狸
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OEKZed 可交互视频 此视频是可 ...
- 大数据学习之BigData常用算法和数据结构
大数据学习之BigData常用算法和数据结构 1.Bloom Filter 由一个很长的二进制向量和一系列hash函数组成 优点:可以减少IO操作,省空间 缺点:不支持删除,有 ...
- Jmeter beanshell断言 org.json.jar包下载
链接:https://pan.baidu.com/s/1O01ODjlKyqmz2NyDT0MCww 提取码:a5va 欢迎关注微信公众号:软件测试汪,qq技术交流群:809111560
- 【lua学习笔记】——环境配置
1 开发平台 windows7 64位 2 下载链接 http://www.lua.org/download.html 3 安装完成-环境配置 4 运行 WIN+R 运行 cmd 运行lua,显示配 ...
- ztree 数组和树结构互转算法
//树转化为数组transformToArrayFormat: function (setting, nodes) { if (!nodes) return []; var childKey = se ...
- docker volume持久化存储与数据分享
第一种 指定volume文件mysql存储,存储的位置为/var/lib/mysql -v mysql:/var/lib/mysql 第二种 同步文件,将容器中的skeleton文件夹的内容同步到宿主 ...