欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

shell脚本-LVS客户端自动配置脚本

程序员文章站 2022-06-06 08:41:35
...
#/bin/bash
VIP=(202.106.195.111 202.106.195.222)
[ -e /etc/sysctl.conf ]&&rm -f /etc/sysctl.conf
[ -e /etc/sysconfig/network-scripts/ifcfg-lo:0 ]&&rm -f /etc/sysconfig/network-scripts/ifcfg-lo:0
[ -e /etc/sysconfig/network-scripts/ifcfg-lo:1 ]&&rm -f /etc/sysconfig/network-scripts/ifcfg-lo:1
 
echo "net.ipv4.conf.all.arp_ignore = 1">/etc/sysctl.conf
echo "net.ipv4.conf.all.arp_announce = 2">>/etc/sysctl.conf
echo "net.ipv4.conf.default.arp_ignore = 1">>/etc/sysctl.conf
echo "net.ipv4.conf.default.arp_announce = 2">>/etc/sysctl.conf
echo "net.ipv4.conf.lo.arp_ignore = 1">>/etc/sysctl.conf
echo "net.ipv4.conf.lo.arp_announce = 2">>/etc/sysctl.conf
sysctl -p &>/dev/null
 
cd /etc/sysconfig/network-scripts
for ((i=0;i<`echo ${#VIP[*]}`;i++))
do
  cp ifcfg-lo ifcfg-lo:$i
  echo "DEVICE=lo:$i">ifcfg-lo:$i
  echo "IPADDR=${VIP[$i]}">>ifcfg-lo:$i
  echo "NETMASK=255.255.255.255">>ifcfg-lo:$i
  echo "ONBOOT=yes">>ifcfg-lo:$i
  ifup ifcfg-lo:$i
  /usr/sbin/route add -host ${VIP[$i]} dev lo:$i &>/dev/null
done