配置高可用的准备工作
(1)需要两台服务器 192.168.17.129 和 192.168.17.131
(2)在两台服务器安装 nginx
(3)在两台服务器安装 keepalived
在两台服务器安装 keepalived
(1)使用 yum 命令进行安装 yum install keepalived –y
(2)安装之后,在 etc 里面生成目录 keepalived,有文件 keepalived.conf
完成高可用配置(主从配置)
(1)修改/etc/keepalived/keepalivec.conf 配置文件
(2)在/usr/local/src 添加检测脚本nginx_check.sh
#!/bin/bash
A=`ps -C nginx 每no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/nginx/sbin/nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
fi
(3)把两台服务器上 nginx 和 keepalived 启动
- 启动 nginx:./nginx
- 启动 keepalived:systemctl start keepalived.service
最终测试
(1)在浏览器地址栏输入 虚拟 ip 地址 192.168.17.50
(2)把主服务器(192.168.17.129)nginx 和 keepalived 停止,再输入 192.168.17.50
配置高可用的准备工作
(1)需要两台服务器 192.168.17.129 和 192.168.17.131
(2)在两台服务器安装 nginx
(3)在两台服务器安装 keepalived
在两台服务器安装 keepalived
(1)使用 yum 命令进行安装 yum install keepalived –y
(2)安装之后,在 etc 里面生成目录 keepalived,有文件 keepalived.conf
完成高可用配置(主从配置)
(1)修改/etc/keepalived/keepalivec.conf 配置文件
(2)在/usr/local/src 添加检测脚本nginx_check.sh
#!/bin/bash
A=`ps -C nginx 每no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/nginx/sbin/nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
fi
(3)把两台服务器上 nginx 和 keepalived 启动
- 启动 nginx:./nginx
- 启动 keepalived:systemctl start keepalived.service
最终测试
(1)在浏览器地址栏输入 虚拟 ip 地址 192.168.17.50
(2)把主服务器(192.168.17.129)nginx 和 keepalived 停止,再输入 192.168.17.50