首先创建两个虚拟机:例如——192.168.213.4与192.168.213.5
其次在每一个虚拟机上安装keepalived
yum install keepalived
安装
keepalived yum:
联网安装
rpm -q -a keepalived
检查是否安装
keepalived ps -ef | grep keepalived
然后进入安装路径:cd /etc/keepalived
开启所有的
nignx
和
keepalived
命令:
./nginx
systemctl start keepalived.service
测试访问虚拟IP:192.168.213.50
此时显示页面为backup的虚拟机
让主机master宕机:
命令:
./nginx -s stop
systemctl stop keepalived.service
测试访问虚拟IP:192.168.213.50
此时显示页面为backup的虚拟机