1.关闭防火墙
停止防火墙服务
systemctl stop firewall.service
关闭开机自启
systemctl disable firewall.service
2.ip 准备
两台虚拟机 IP地址 需要不一样
例:主机:192.168.96.122
备用机:192.168.96.154
vip:192.168.96.155
vip 的ip地址后面的操作需要用到
3.关闭 selinux(安全子系统)
setenforce 0
编辑配置文件,关闭开机自启
vi /etc/selinux/config 将selinux=enforcing改为selinux=disabled
4.同时给主机安装keepalived
下载
wget https://www.keepalived.org/software/keepalived-1.4.5.tar.gz
解压
tar -zxvf keepalived-1.4.5.tar.gz
进入文件夹
cd keepalived-1.4.5
预编译
./configure --prefix=usr/local/keepalived
安装
make && make install
5.将keepalived 注册为服务系统
cp keepalived/etc/init.d/keepalived /etc/init.d cp keepalived/etc/sysconfig/keepalived /etc/sysconfig/
6.编辑配置文件
mkdir -p /etc/keepalived cp/usr/local/keepalived/etc/keepalived/keepal/etc/keepalived/keepalived.conf vi /etc/keepalived/keepalived.conf
主机
输入这两块内容
备用机
7.双机创建监控双机的nginx脚本
vi /opt/check_nginx.sh
9.双机安装psmisc
yum -y install psmisc
10.双机再次编译keepalived配置文件
vi /etc/keepalived/keepalived.conf
添加上如图代码
11.启动keepalived服务,并开机自启
systemctl start keepalived.service systemctl enable keepalived.service
12.测试
修改主机欢迎界面 区分
vi /usr/local/nginx/html/index.html
在如图位置上加入Master
按照以上操作 仅只能实现分别使用ip地址进入网页界面无法使用vip:端口 进入欢迎界面
希望大家帮我看看,哪儿出错了!