Linux配置Keepalived,实现nginx主备切换
2021/8/21 7:06:22
本文主要是介绍Linux配置Keepalived,实现nginx主备切换,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、下载Keepalived
1、下载依赖软件
yum install -y gcc yum install -y openssl-devel yum install -y libnl libnl-devel yum install -y libnfnetlink-devel yum install -y net-tools yum install -y vim wget
2、下载压缩包到/usr/local(我以keepalived-2.0.10为例),解压安装
cd /use/local/src tar -zxvf keepalived-2.0.10.tar.gz mv keepalived-2.0.10 keepalived # 修改文件名 cd /use/local/keepalived/ ./configure make && make install
3、将配置文件复制到默认路径
mkdir /etc/keepalived cp /usr/local/keepalived/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp /usr/local/keepalived/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/ # 启动文件,用于开机自启 cp /usr/local/keepalived/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/sbin/keepalived /usr/sbin/
4、设置开机自启
chkconfig keepalived on service keepalived start #启动服务 service keepalived stop #停止服务 service keepalived restart #重启服务
二、创建随Nginx服务停止而停止的脚本(主备两台都要配置)
1、在/etc/keeplived路径下创建check_nginx.sh脚本文件,内容如下:
#!/bin/bash A=`ps -C nginx --no-header | wc -l` if [ $A -eq 0 ];then service keepalived stop fi
2、修改该脚本的权限
chmod 777 check_nginx.sh
3、修改/etc/keepalived下的keepalived.conf如下(红色部分)
三、其他
1、keepalived配置文件参考:https://www.cnblogs.com/kevingrace/p/6248941.html
2、如果加入LVS,参考:https://lupengfei.blog.csdn.net/article/details/86514445
这篇关于Linux配置Keepalived,实现nginx主备切换的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享
- 2024-08-14nginx 让访问带有/relid的地址返回404 ,例子 /relid-x-0.36-y-131.html-icode9专业技术文章分享
- 2024-08-14nginx 判断地址有/statics/的路径,指向到/home/html/statics/目录-icode9专业技术文章分享