keepalived安装配置 centos 7

混江龙づ霸主 提交于 2019-12-01 19:07:19

keepalived安装配置 centos 7

###centos 7.4
###三台keepalived节点,两台也可以
###所有节点运行
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux  
setenforce 0 

systemctl stop firewalld.service 
systemctl disable firewalld.service 

hostnamectl --static set-hostname  l_$(ip addr |grep brd |grep global |head -n1 |cut -d '/' -f1 |cut -d '.' -f4)

yum install -y keepalived

##################master1 运行配置
cat >/etc/keepalived/keepalived.conf <<EOF
global_defs {
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33

    virtual_router_id 157
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 2829
    }

    virtual_ipaddress {
    172.16.3.228/24 dev ens33
    }

}
EOF
systemctl enable keepalived.service 
systemctl restart keepalived.service
systemctl status keepalived.service 
ip address show  ens33

##################master2 运行配置
cat >/etc/keepalived/keepalived.conf <<EOF
global_defs {
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33

    virtual_router_id 157
    priority 99
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 2829
    }
    virtual_ipaddress {
    172.16.3.228/24 dev ens33
    }

}
EOF


systemctl enable keepalived.service 
systemctl restart keepalived.service
systemctl status keepalived.service 
ip address show  ens33

##################master3 运行配置
cat >/etc/keepalived/keepalived.conf <<EOF
global_defs {
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33

    virtual_router_id 157
    priority 98
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 2829
    }
    virtual_ipaddress {
    172.16.3.228/24 dev ens33
    }
}
EOF
#########
systemctl enable keepalived.service 
systemctl restart keepalived.service
systemctl status keepalived.service 
ip address show  ens33


####切换主执行脚本
#notify_master "sleep 1 ;systemctl restart haproxy.service"
####切换备执行脚本
#notify_backup "pkill haproxy"

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!