1、拓扑如下:
2、通过rsync日志备份
1>ssh 免密钥登陆
确定发起方,从log-back-server_10.1.1.1 为中心发起方。因此,要实现从log-server到各主机之前的 免密登陆。在log-server 主机上,cd ~ && ssh-keygen -t rsa ,全部按空格结束。ls一下
将id_rsa.pub 全部传到其它主机上面。
[[email protected] ~]# scp -p ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
[[email protected] ~]# scp -p ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
[[email protected] ~]# scp -p ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
2>在每台主机上安装rsync,并且使用脚本做ssh免密测试
#! /bin/bash
#
for host in {1..xx}
do
ssh 10.1.1.$host
action=`echo &?`
if [ $action == 0 ];then
echo "the $host is ok" >> a.txt
else
echo "the $host is not ok" >> a.txt
fi
done
3>计划任务
可以针对不同的主机,/ 目录下做不同的文件夹存放不同主机的日志。
10.1.1.1-log 10.1.1.2-log 10.1.1.3-log
[[email protected] /]# mkdir 10.1.1.1-log && mkdir 10.1.1.2-log && mkdir 10.1.1.3-log
[[email protected] /]# ls
10.1.1.1-log bin dev lib media net root selinux tmp
10.1.1.2-log boot etc lib64 misc opt sbin srv usr
10.1.1.3-log cgroup home lost+found mnt proc script sys var
[[email protected] ~]# mkdir log-back-script
[[email protected] ~]# cd log-back-script/
[[email protected] log-back-script]# touch backup.sh
[[email protected] log-back-script]# pwd
/root/log-back-script
备份脚本:(脚本比较简单,只是实现个基础内容而已)
#! /bin/bash
# messages backup
rsync -avz /var/log/messages* 10.1.1.1:/10.1.1.1-log
date && echo "10.1.1.1 is ok" >> back_echo_history
rsync -avz /var/log/messages* 10.1.1.2:/10.1.1.2-log
date && echo "10.1.1.2 backup is ok" >> back_echo_history
rsync -avz /var/log/messages* 10.1.1.3:/10.1.1.3-log
date && echo "10.1.1.3 backup is ok" >> back_echo_history
exit
开始任务计划:
[[email protected] log-back-script]# crontab -e
其实以上还可以增强很多内容,有想法提出来一起讨论。
___________________________________________________________________________________________
Nothing is impossible , if you willing to .