实验环境

序号 主机名 IP地址
1 nginx1 192.168.204.11
2 nginx2 192.168.204.12

安装nginx

安装nginx

yum install -y epel-*
yum install -y nginx

编写HTML文件

nginx1上

echo -e "nginx1" > /usr/share/nginx/html/index.html

nginx2上

echo -e "nginx2" > /usr/share/nginx/html/index.html

启动nginx

systemctl start nginx
systemctl enable nginx
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

访问浏览器

安装配置keepalived

1.安装keepalived

yum install keepalived -y

2.在nginx1上配置keepalived

修改配置文件

vim /etc/keepalived/keepalived.conf

启动

systemctl start keepalived
systemctl enable keepalived

3.在nginx2上配置keepalived

修改配置文件

vim /etc/keepalived/keepalived.conf

启动

systemctl start keepalived
systemctl enable keepalived

4.在宿主机ping 192.168.204.10,使用arp -a查看缓存

5.浏览器访问虚拟地址

6.在nginx1上宕掉ens33网卡

在宿主机使用arp -a查看缓存

在主机使用浏览器访问虚拟地址

可以看到,对192.168.204.10的请求已从nginx1节点转移到了nginx2节点

配置keepalived支持nginx高可用

1.编写NGINX状态监测脚本

编写脚本/etc/keepalived/nginx_check.sh

#!/bin/bash
# file:/etc/keepalived/nginx_check.sh
N=`ps -C nginx --no-header | wc -l`
if [ $N -eq 0 ]; then
systemctl restart nginx
sleep 2
if [ `ps -C nginx --no-header | wc -l` -eq 0 ]; then
killall keepalived
fi
fi

赋予可执行权限

chmod +x /etc/keepalived/nginx_check.sh

测试脚本

2.配置keepalived支持NGINX高可用

在nginx1节点上编辑/etc/keepalived/keepalived.conf

vim /etc/keepalived/keepalived.conf

重新启动keepalived

systemctl restart keepalived

3.测试高可用

浏览器访问虚拟地址

在nginx1节点运行stop.sh脚本,然后使用浏览器访问虚拟地址

#!/bin/bash
# file:stop.sh
for ((i=0; i<=100; i++))
do
systemctl stop nginx
echo 'stoped. sleep 1s...'
sleep 1
done

本文链接: https://www.cnblogs.com/connect/p/nginx-keepalived-high-availability.html

配置keepalived支持nginx高可用的更多相关文章

  1. Docker下配置KeepAlive支持nginx高可用

    案例子任务一.安装配置keepalived 步骤1:使用nginx镜像生成nginx-keep镜像 1) 启动nginx容器并进入 docker run -d --privileged nginx / ...

  2. Keepalived保证Nginx高可用配置

    Keepalived保证Nginx高可用配置部署环境 keepalived-1.2.18 nginx-1.6.2 VM虚拟机redhat6.5-x64:192.168.1.201.192.168.1. ...

  3. linux中keepalived实现nginx高可用配置

    linux中keepalived实现nginx高可用配置 安装keepalived 运行如下命令即可 tar -zxvf keepalived-2.0.8.tar.gz -C /usr/src cd ...

  4. keepalived对nginx高可用演练脚本

    keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...

  5. Nginx配置upstream实现负载均衡及keepalived实现nginx高可用

    (原文链接:http://www.studyshare.cn/blog-front//blog/details/1159/0 ) 一.准备工作 1.准备两个项目,发布到不同的服务器上,此处使用2个虚拟 ...

  6. keepalived实现nginx高可用

    keepalived是什么 keepalived直译就是保持存活,在网络里面就是保持在线了,也就是所谓的高可用或热备,用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用)的发 ...

  7. 基于keepalived的nginx高可用

    #nginx,keepalived安装略过 MASTER 节点配置文件(192.168.1.11) vi /etc/keepalived/keepalived.conf global_defs { # ...

  8. 使用Keepalived实现Nginx高可用

    Keepalived是一个路由软件,可以提供linux系统和linux系统上的组件的负载均衡和高可用,高可用基于VRRP(Virtual Router Redundancy Protocol,虚ip) ...

  9. Keepalived+LVS-DR+Nginx高可用故障切换模式

    LVS架构中,不管是NAT模式还是DR模式,当后端的RS宕掉后,调度器依然会把请求转发到宕掉的RS上,这样的结果并不是我们想要的.其实,keepalived就可以解决问题,它不仅仅有高可用的功能,还有 ...

随机推荐

  1. 使用VS Code远程开发

    今天看到园子里的一篇文章:VS Code Remote 发布!开启远程开发新时代,简单的看了一下,它可以直接利用本地的环境远程开发,最直接的好处有: 在部署相同的操作系统上进行开发,或者使用更大或更专 ...

  2. 2019-11-29-WPF-开启-ScrollViewer-的触摸滚动

    原文:2019-11-29-WPF-开启-ScrollViewer-的触摸滚动 title author date CreateTime categories WPF 开启 ScrollViewer ...

  3. layui 动态表格设置单元格样式

    col.push({ field: , templet: function (d) { ") { return '<span style="color:white;backg ...

  4. Exceptionless - 本地搭建

    搭建环境:Windows 10 参与文档:https://github.com/exceptionless/Exceptionless/wiki/Self-Hosting 运行环境: .NET 4.6 ...

  5. [Silverlight 4] Textbox style模擬Textblock 使可以選取、複製

    childwindow 做為訊息視窗,使用textblock,可是textbloc無法選取內容及複製, 就改用textbox假裝成textblock ---原本的textblock <contr ...

  6. 我是如何一步步编码完成万仓网ERP系统的(十一)产品库设计 7.发布商品

    https://www.cnblogs.com/smh188/p/11533668.html(我是如何一步步编码完成万仓网ERP系统的(一)系统架构) https://www.cnblogs.com/ ...

  7. .NET Core的依赖注入

    转自[大内老A] 依赖注入[1]: 控制反转依赖注入[2]: 基于IoC的设计模式依赖注入[3]: 依赖注入模式依赖注入[4]: 创建一个简易版的DI框架[上篇]依赖注入[5]: 创建一个简易版的DI ...

  8. 关于在linux上部署scrapy的爬虫

    1.在服务器中安装chrome sudo apt-get install libxss1 libappindicator1 libindicator7 wget https://dl.google.c ...

  9. Spring Cloud Gateway转发Spring WebSocket

    Spring Cloud Gateway转发Spring WebSocket 源码:https://github.com/naah69/SpringCloud-Gateway-WebSocket-De ...

  10. PHP生成唯一用户标识GUID

    代码如下: //生成唯一用户标识id function create_guid() { $charid = strtoupper(md5(uniqid(mt_rand(), true))); $hyp ...