keepalived双活高可用部署

环境:本地虚拟机中安装两台centos7
在centos7中安装keepalived
安装命令

yum install -y keepalived
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

提示错误
解决方案
这是由于yum没有配置源的问题引起的
删除原有的文件重新配置yum的源即可

删除
rm -f /etc/yum.repos.d/CentOS-Base.repo  
配置成阿里的源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

清除缓存
yum clean all

可能会出现的问题
make: *** 没有指明目标并且找不到 makefile。 停止。

yum install gcc

如果没有问题查看是否安装成功

keepalived  -v

修改配置文件

/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  router_id kepp130  
}


vrrp_script chk_nginx {
  script "/etc/keepalived/nginx_check.sh"
 interval 2
  weight -20
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33 这是网卡
    virtual_router_id 100  这个id必须 相同
    mcast_src_ip 192.168.220.130  当前id地址
    priority 100
    advert_int 1 
    authentication {
        auth_type PASS  这里要和备用服务器相同
        auth_pass 1111  这里也要和备用服务器项目
    }

    track_script {
     chk_nginx
    }
    virtual_ipaddress {
        192.168.220.168  这个是虚拟ip 随便填都可以
    }
}

cript chk_nginx {
  interval 2
  weight -20
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 100
    mcast_src_ip 192.168.220.130
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    track_script {
     chk_nginx
    }
    virtual_ipaddress {
        192.168.220.2
    }
}

重启keepalived

systemctl restart keepalived

修改虚拟机名称
vim /etc/hosts
在这里插入图片描述
在这里插入图片描述

#!/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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值