keepalived安装配置

keepalived安装配置

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"
01-17 20:32