一、条件
(1)需要两台Nginx服务器
(2)需要keepalived
(3)需要虚拟ip
二、准备工作
(1)需要两台服务器
(2)在两台服务器安装nginx
(3)在两台服务器安装keepalived(如下使用yum安装)
cd /usr
yun install keepalived -y
rpm -q -a keepalived
安装之后在 /etc目录下有keepalived的配置文件 keepalived/keepalived.conf
三、完成高可用配置(主从配置)
(1)修改/etc/keepalived/kepalived.conf配置文件
(2)在/ust/local/nginx下添加检测脚本nginx_check.sh
(3)把两台服务器上的nginx和keepalived启动
keepalived:
systemctl start keepalived.server
ps -ef | grep keepalived
四、最终测试
(1)在浏览器地址栏输入虚拟ip地址
ip a
(2)把主服务器nginx和keepalived停止,再次输入
systemctl stop keepalived.server