灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:1959回复:0

linux iptables异机备份、恢复实例

楼主#
更多 发布于:2012-08-27 15:07


linux iptables异机备份、恢复实例



1、iptables的配置文件位置:/etc/sysconfig/iptables

    主控机:即业务运行中的机子;备份机:即主控机故障时,切换到备份的机子



--在主控机上的操作-------------------

2、建立目录:

mkdir -p /bak/iptables/

mkdir /root/script/



3、在/root/script/目录下建立脚本:

vi backup.sh

cp /etc/sysconfig/iptables /bak/iptables/iptables_$(date +%Y%m%d%H)



4、定制自动任务:

crontab -e

*/10 * * * * /usr/sbin/ntpdate 210.72.145.44

10 * * * * sh /root/script/backup.sh



--在备份机上操作---------------------

5、建立目录:

mkdir -p /bak/iptables/{lt,yd}    #lt目录放联通跳转的备份,yd目录放移动跳转的备份

mkdir /root/script/



6、在/root/script/目录下建立脚本:

vi scp_lt.sh



#!/usr/bin/expect -f

set password gst

spawn scp -P 22 root@202.105.135.52:/etc/sysconfig/iptables /bak/iptables/lt/iptables

set timeout 300

expect "root@202.105.135.52's password:"

set timeout 300

send "$passwordr"

set timeout 300

send "exitr"

expect eof



7、在/root/script/目录下建立脚本:

vi scp_yd.sh

#!/usr/bin/expect -f

set password gst

spawn scp -P 22 root@183.62.178.91:/etc/sysconfig/iptables /bak/iptables/yd/iptables

set timeout 300

expect "root@183.62.178.91's password:"

set timeout 300

send "$passwordr"

set timeout 300

send "exitr"

expect eof



8、在/root/script/目录下建立脚本:

vi backup.sh


expect /root/script/scp_lt.sh

expect /root/script/scp_yd.sh

sed -i 's/202.105.135.52/183.62.178.85/g' /bak/iptables/lt/iptables

sed -i 's/58.251.49.18/58.250.56.154/g' /bak/iptables/lt/iptables

cp /bak/iptables/lt/iptables /etc/sysconfig/iptables

/etc/init.d/iptables restart

/etc/init.d/iptables save

mv /bak/iptables/lt/iptables /bak/iptables/lt/iptables_$(date +%Y%m%d%H)

mv /bak/iptables/yd/iptables /bak/iptables/yd/iptables_$(date +%Y%m%d%H)



9、注意,要在备份机上手动远程登陆一次,以获得RSA的公钥,之后就不用这样登陆了,否则脚本会执行错误



10、定制自动任务:

crontab -e

*/10 * * * * /usr/sbin/ntpdate 210.72.145.44

20 * * * * sh /root/script/backup.sh




喜欢0 评分0
游客

返回顶部