標籤:shell
案例一:
【LVS用戶端節點】開發LVS用戶端設定VIP以及抑制ARP的管理指令碼
指令碼內容:
#!/bin/bash############################################################### File Name: lvs_client.sh# Version: V1.0# Author: da ya# Organization: [email protected]# Created Time : 2018# Description:##############################################################. /etc/init.d/functionsVip=`ip a s lo|grep 10.0.0.13|wc -l`function Start(){ if [ $Vip -eq 1 ];then action 'Vip is alreadly exists' /bin/true else ip addr add 10.0.0.13/32 dev lo echo -e 'net.ipv4.conf.all.arp_ignore = 1\nnet.ipv4.conf.all.arp_announce = 2\nnet.ipv4.conf.lo.arp_ignore = 1\nnet.ipv4.conf.lo.arp_announce = 2' >/etc/sysctl.conf sysctl -p &>/dev/null action 'Vip is started' /bin/true fi}function Stop(){ ip addr del 10.0.0.13/32 dev lo &>/dev/null action 'Vip is delete' /bin/true}case $1 instart) Start;;stop) Stop;;restart) Stop sleep 1 Start;;*) echo "Please Input $0 { start|stop|restart }";;esac
進行測試:
案例二:
【LVS主節點】類比keepalived健全狀態檢查功能管理LVS節點,
當節點掛掉(檢測2次,間隔2秒)從伺服器集區中剔除,好了(檢測2次,間隔2秒)加進來
提示:利用ipvsadm命令實現添加和減少LVS節點。
指令碼內容:
Shell之企業實際工作案例2