1、iptables的配置文件位置:/etc/sysconfig/iptables
主控機(jī):即業(yè)務(wù)運(yùn)行中的機(jī)子;備份機(jī):即主控機(jī)故障時(shí),切換到備份的機(jī)子
--在主控機(jī)上的操作-------------------
2、建立目錄:
mkdir -p /bak/iptables//p>
p> mkdir /root/script/
3、在/root/script/目錄下建立腳本:
vi backup.sh/p>
p> cp /etc/sysconfig/iptables /bak/iptables/iptables_$(date +%Y%m%d%H)
4、定制自動(dòng)任務(wù):
crontab -e/p>
p> */10 * * * * /usr/sbin/ntpdate 210.72.145.44/p>
p> 10 * * * * sh /root/script/backup.sh
--在備份機(jī)上操作---------------------
5、建立目錄:
mkdir -p /bak/iptables/{lt,yd} #lt目錄放聯(lián)通跳轉(zhuǎn)的備份,yd目錄放移動(dòng)跳轉(zhuǎn)的備份/p>
p> mkdir /root/script/
6、在/root/script/目錄下建立腳本:
vi scp_lt.sh/p>
p> #!/usr/bin/expect -f/p>
p> set password gst/p>
p> spawn scp -P 22 root@202.105.135.52:/etc/sysconfig/iptables /bak/iptables/lt/iptables/p>
p> set timeout 300/p>
p> expect "root@202.105.135.52's password:"/p>
p> set timeout 300/p>
p> send "$passwordr"/p>
p> set timeout 300/p>
p> send "exitr"/p>
p> expect eof
7、在/root/script/目錄下建立腳本:
vi scp_yd.sh/p>
p> #!/usr/bin/expect -f/p>
p> set password gst/p>
p> spawn scp -P 22 root@183.62.178.91:/etc/sysconfig/iptables /bak/iptables/yd/iptables/p>
p> set timeout 300/p>
p> expect "root@183.62.178.91's password:"/p>
p> set timeout 300/p>
p> send "$passwordr"/p>
p> set timeout 300/p>
p> send "exitr"/p>
p> expect eof
8、在/root/script/目錄下建立腳本:
vi backup.sh/p>
p> expect /root/script/scp_lt.sh/p>
p> expect /root/script/scp_yd.sh/p>
p> sed -i 's/202.105.135.52/183.62.178.85/g' /bak/iptables/lt/iptables/p>
p> sed -i 's/58.251.49.18/58.250.56.154/g' /bak/iptables/lt/iptables/p>
p> cp /bak/iptables/lt/iptables /etc/sysconfig/iptables/p>
p> /etc/init.d/iptables restart/p>
p> /etc/init.d/iptables save/p>
p> mv /bak/iptables/lt/iptables /bak/iptables/lt/iptables_$(date +%Y%m%d%H)/p>
p> mv /bak/iptables/yd/iptables /bak/iptables/yd/iptables_$(date +%Y%m%d%H)
9、注意,要在備份機(jī)上手動(dòng)遠(yuǎn)程登陸一次,以獲得RSA的公鑰,之后就不用這樣登陸了,否則腳本會(huì)執(zhí)行錯(cuò)誤
10、定制自動(dòng)任務(wù):
crontab -e/p>
p> */10 * * * * /usr/sbin/ntpdate 210.72.145.44/p>
p> 20 * * * * sh /root/script/backup.sh