您好,登錄后才能下訂單哦!
keepalived采用vrrp熱備份協(xié)議,實現(xiàn)Linux服務(wù)器的多機熱備功能
vrrp,虛擬路由冗余協(xié)議,是針對路由器的一種備份解決方案
keepalived可實現(xiàn)多機熱備,每個熱備組有多臺服務(wù)器,最常用的就是雙機熱備
雙機熱備的故障切換是由虛擬IP地址的漂移來實現(xiàn),適用于各種應(yīng)用服務(wù)器
CentOS7系統(tǒng):
DR1 主: 192.168.100.2
DR2 備: 192.168.100.20
虛擬IP:192.168.100.10
web1:192.168.100.221
web2:192.168.100.222
win10系統(tǒng):
client:192.168.100.100
DR1主:
[root@localhost ~]# yum install ipvsadm keepalived -y
DR2從:
[root@localhost ~]# yum install ipvsadm keepalived -y
web1:
[root@localhost ~]# yum install httpd -y
web2:
[root@localhost ~]# yum install httpd -y
DR1主:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dhcp改為static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3ceed540-b04c-48d6-a4f7-79951f09ea1d
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.201 #IP地址
NETMASK=255.255.255.0 #子網(wǎng)掩碼
GATEWAY=192.168.100.1 #網(wǎng)關(guān)
[root@localhost ~]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost ~]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.201 netmask 255.255.255.0 broadcast 192.168.100.255 #IP地址配置成功
inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:95:9b:1b txqueuelen 1000 (Ethernet)
RX packets 10373 bytes 13584878 (12.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4285 bytes 277473 (270.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
DR2從:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dhcp改為static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3ceed540-b04c-48d6-a4f7-79951f09ea1d
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.202 #IP地址
NETMASK=255.255.255.0 #子網(wǎng)掩碼
GATEWAY=192.168.100.1 #網(wǎng)關(guān)
[root@localhost ~]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost ~]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.202 netmask 255.255.255.0 broadcast 192.168.100.255 #IP地址配置成功
inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20<link>
inet6 fe80::2558:848e:ba08:4183 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:27:1c:3f txqueuelen 1000 (Ethernet)
RX packets 10470 bytes 13593710 (12.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4240 bytes 273794 (267.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
web1:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dhcp改為static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=8ecd53ce-afdb-46f8-b7ff-b2f428a3bc8f
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.221 #IP地址
NETMASK=255.255.255.0 #子網(wǎng)掩碼
GATEWAY=192.168.100.1 #網(wǎng)關(guān)
[root@localhost ~]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost ~]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.221 netmask 255.255.255.0 broadcast 192.168.100.255 #IP地址配置成功
inet6 fe80::c776:9d00:618:88f2 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:eb:34:07 txqueuelen 1000 (Ethernet)
RX packets 11508 bytes 14937643 (14.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3932 bytes 254623 (248.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
web2:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dhcp改為static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=09073596-a7cf-404c-a098-28c3ff58c44b
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.222 #IP地址
NETMASK=255.255.255.0 #子網(wǎng)掩碼
GATEWAY=192.168.100.1 #網(wǎng)關(guān)
[root@localhost ~]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost ~]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.222 netmask 255.255.255.0 broadcast 192.168.100.255 #IP地址配置成功
inet6 fe80::5134:22f5:842b:5201 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:0d:f1:75 txqueuelen 1000 (Ethernet)
RX packets 11425 bytes 14931323 (14.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4454 bytes 286016 (279.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward=1 #配置路由轉(zhuǎn)發(fā)功能
#proc響應(yīng)關(guān)閉重定向功能
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects=0
[root@localhost ~]# sysctl -p #加載生效
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@localhost ~]#
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens33:0 #復(fù)制虛擬網(wǎng)卡的配置文件
[root@localhost network-scripts]# vim ifcfg-ens33:0
#添加配置文件信息,原有的信息刪除
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost network-scripts]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.201 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:95:9b:1b txqueuelen 1000 (Ethernet)
RX packets 11455 bytes 13700437 (13.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4713 bytes 330899 (323.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255 #虛擬網(wǎng)卡配置成功
ether 00:0c:29:95:9b:1b txqueuelen 1000 (Ethernet)
[root@localhost network-scripts]# cd /etc/init.d/
[root@localhost init.d]# vim dr.sh
#!/bin/bash
GW=192.168.100.1 #網(wǎng)關(guān)
VIP=192.168.100.10 #虛擬ip
RIP1=192.168.100.221 #真實web1服務(wù)器ip
RIP2=192.168.100.222 #真實web2服務(wù)器ip
case "$1" in
start)
/sbin/ipvsadm --save > /etc/sysconfig/ipvsadm #保存配置
systemctl start ipvsadm #啟動服務(wù)
/sbin/ifconfig ens33:0 $VIP broadcast $VIP netmask 255.255.255.255 broadcast $VIP up
#設(shè)置ens33:0地址,廣播地址,子網(wǎng)掩碼,并開啟
/sbin/route add -host $VIP dev ens33:0 #添加路由網(wǎng)段信息
/sbin/ipvsadm -A -t $VIP:80 -s rr #指定虛擬服務(wù)訪問入口,指定輪詢算法
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g #指定真實服務(wù)器web1,dr模式
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g #指定真實服務(wù)器web2,dr模式
echo "ipvsadm starting ---------------------[ok]"
;;
stop)
/sbin/ipvsadm -C #清空緩存
systemctl stop ipvsadm #關(guān)閉服務(wù)
ifconfig ens33:0 down #關(guān)閉接口
route del $VIP #刪除路由信息
echo "ipvsadm stoped--------------------[ok]"
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ];then #判斷文件存在與否決定狀態(tài)
echo "ipvsadm stoped--------------"
exit 1
else
echo "ipvsadm Runing-----------[ok]"
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x dr.sh #給執(zhí)行權(quán)限
[root@localhost init.d]# service dr.sh start #開啟服務(wù)
ipvsadm starting ---------------------[ok]
[root@localhost init.d]# systemctl stop firewalld.service #關(guān)閉防火墻
[root@localhost init.d]# setenforce 0 #關(guān)閉增強型安全功能
[root@localhost init.d]#
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# ls
keepalived.conf
[root@localhost keepalived]# vim keepalived.conf
smtp_server 127.0.0.1 #指向本地
router_id LVS_01 #指定名稱,備份服務(wù)器不同名稱
vrrp_instance VI_1 {
state MASTER #主服務(wù)器,備份服務(wù)器是BACKUP
interface ens33
virtual_router_id 10 #組號相同
priority 100 #優(yōu)先級,主服務(wù)器優(yōu)先級應(yīng)大于備份服務(wù)器
advert_int 1
authentication {
auth_type PASS #驗證類型
auth_pass 1111 #驗證密碼
}
virtual_ipaddress {
192.168.100.10 #虛擬IP地址
}
}
virtual_server 192.168.100.10 80 { #虛擬服務(wù)器
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.100.221 80 { #真實服務(wù)器
weight 1
TCP_CHECK {
connect_port 80 #連接端口
connect_timeout 3 #連接超時
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.222 80 { #真實服務(wù)器
weight 1
TCP_CHECK {
connect_port 80 #連接端口
connect_timeout 3 #連接超時
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@localhost keepalived]# systemctl start keepalived.service #開啟服務(wù)
[root@localhost keepalived]#
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward=1 #配置路由轉(zhuǎn)發(fā)功能
#proc響應(yīng)關(guān)閉重定向功能
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects=0
[root@localhost ~]# sysctl -p #加載生效
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@localhost ~]#
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens33:0 #復(fù)制虛擬網(wǎng)卡的配置文件
[root@localhost network-scripts]# vim ifcfg-ens33:0
#添加配置文件信息,原有的信息刪除
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network #重啟網(wǎng)絡(luò)服務(wù)
[root@localhost network-scripts]# ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.202 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20<link>
inet6 fe80::2558:848e:ba08:4183 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:27:1c:3f txqueuelen 1000 (Ethernet)
RX packets 15720 bytes 14706442 (14.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6289 bytes 1113172 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255 #虛擬網(wǎng)卡配置成功
ether 00:0c:29:27:1c:3f txqueuelen 1000 (Ethernet)
[root@localhost network-scripts]# cd /etc/init.d/
[root@localhost init.d]# vim dr.sh
#!/bin/bash
GW=192.168.100.1 #網(wǎng)關(guān)
VIP=192.168.100.10 #虛擬ip
RIP1=192.168.100.221 #真實web1服務(wù)器ip
RIP2=192.168.100.222 #真實web2服務(wù)器ip
case "$1" in
start)
/sbin/ipvsadm --save > /etc/sysconfig/ipvsadm #保存配置
systemctl start ipvsadm #啟動服務(wù)
/sbin/ifconfig ens33:0 $VIP broadcast $VIP netmask 255.255.255.255 broadcast $VIP up
#設(shè)置ens33:0地址,廣播地址,子網(wǎng)掩碼,并開啟
/sbin/route add -host $VIP dev ens33:0 #添加路由網(wǎng)段信息
/sbin/ipvsadm -A -t $VIP:80 -s rr #指定虛擬服務(wù)訪問入口,指定輪詢算法
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g #指定真實服務(wù)器web1,dr模式
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g #指定真實服務(wù)器web2,dr模式
echo "ipvsadm starting ---------------------[ok]"
;;
stop)
/sbin/ipvsadm -C #清空緩存
systemctl stop ipvsadm #關(guān)閉服務(wù)
ifconfig ens33:0 down #關(guān)閉接口
route del $VIP #刪除路由信息
echo "ipvsadm stoped--------------------[ok]"
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ];then #判斷文件存在與否決定狀態(tài)
echo "ipvsadm stoped--------------"
exit 1
else
echo "ipvsadm Runing-----------[ok]"
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x dr.sh #給執(zhí)行權(quán)限
[root@localhost init.d]# service dr.sh start #開啟服務(wù)
ipvsadm starting ---------------------[ok]
[root@localhost init.d]# systemctl stop firewalld.service #關(guān)閉防火墻
[root@localhost init.d]# setenforce 0 #關(guān)閉增強型安全功能
[root@localhost init.d]#
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# ls
keepalived.conf
[root@localhost keepalived]# vim keepalived.conf
smtp_server 127.0.0.1 #指向本地
router_id LVS_02 #指定名稱,備份服務(wù)器不同名稱
vrrp_instance VI_1 {
state BACKUP #備份服務(wù)器BACKUP,主服務(wù)器是MASTER
interface ens33
virtual_router_id 10 #組號相同
priority 90 #優(yōu)先級,備份服務(wù)器應(yīng)小于主服務(wù)器優(yōu)先級
advert_int 1
authentication {
auth_type PASS #驗證類型
auth_pass 1111 #驗證密碼
}
virtual_ipaddress {
192.168.100.10 #虛擬IP地址
}
}
virtual_server 192.168.100.10 80 { #虛擬服務(wù)器
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.100.221 80 { #真實服務(wù)器
weight 1
TCP_CHECK {
connect_port 80 #連接端口
connect_timeout 3 #連接超時
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.222 80 { #真實服務(wù)器
weight 1
TCP_CHECK {
connect_port 80 #連接端口
connect_timeout 3 #連接超時
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@localhost keepalived]# systemctl start keepalived.service #開啟服務(wù)
[root@localhost keepalived]#
[root@localhost ~]# systemctl stop firewalld.service #關(guān)閉防火墻
[root@localhost ~]# setenforce 0 #關(guān)閉增強型安全功能
[root@localhost ~]# systemctl start httpd.service #開啟httpd服務(wù)
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is abc web" > index.html #創(chuàng)建網(wǎng)站頁面
[root@localhost html]#
[root@localhost html]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0 #復(fù)制回環(huán)網(wǎng)卡配置文件
[root@localhost network-scripts]# vim ifcfg-lo:0
#添加配置文件信息,原有的信息刪除
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ONBOOT=yes
[root@localhost network-scripts]# cd /etc/init.d/
[root@localhost init.d]# vim web.sh
#!/bin/bash
VIP=192.168.100.10
case "$1" in
start)
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add -host $VIP dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
sysctl -p > /dev/null 2>&1
echo "RealServer Start OK "
;;
stop)
ifconfig lo:0 down
route del $VIP /dev/null 2>&1
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x web.sh #添加執(zhí)行權(quán)限
[root@localhost init.d]# service web.sh start #開啟服務(wù)
RealServer Start OK
[root@localhost init.d]# ifup lo:0 #開啟網(wǎng)卡
[root@localhost init.d]#ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.221 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::c776:9d00:618:88f2 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:eb:34:07 txqueuelen 1000 (Ethernet)
RX packets 13293 bytes 15122368 (14.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4692 bytes 360484 (352.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 192.168.100.10 netmask 255.255.255.255
loop txqueuelen 1 (Local Loopback)
[root@localhost ~]# systemctl stop firewalld.service #關(guān)閉防火墻
[root@localhost ~]# setenforce 0 #關(guān)閉增強型安全功能
[root@localhost ~]# systemctl start httpd.service #開啟httpd服務(wù)
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is xyz web" > index.html #創(chuàng)建網(wǎng)站頁面
[root@localhost html]#
[root@localhost html]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0 #復(fù)制回環(huán)網(wǎng)卡配置文件
[root@localhost network-scripts]# vim ifcfg-lo:0
#添加配置文件信息,原有的信息刪除
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ONBOOT=yes
[root@localhost network-scripts]# cd /etc/init.d/
[root@localhost init.d]# vim web.sh
#!/bin/bash
VIP=192.168.100.10
case "$1" in
start)
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add -host $VIP dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
sysctl -p > /dev/null 2>&1
echo "RealServer Start OK "
;;
stop)
ifconfig lo:0 down
route del $VIP /dev/null 2>&1
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x web.sh #添加執(zhí)行權(quán)限
[root@localhost init.d]# service web.sh start #開啟服務(wù)
RealServer Start OK
[root@localhost init.d]# ifup lo:0 #開啟網(wǎng)卡
[root@localhost init.d]#ifconfig #查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.222 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::5134:22f5:842b:5201 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:0d:f1:75 txqueuelen 1000 (Ethernet)
RX packets 16771 bytes 15510870 (14.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7516 bytes 783039 (764.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 192.168.100.10 netmask 255.255.255.255
loop txqueuelen 1 (Local Loopback)
[root@localhost keepalived]# ifdown ens33:0
#在DR1主服務(wù)器上,關(guān)閉虛擬網(wǎng)卡,模擬故障
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。