- 论坛徽章:
- 0
|
Rsync + SSH --让Server自动异地备援也加密
一.前言
自从911事件之后...异地备援这个名称就常听人提起...不过就是满少看到大家在讨论...刚好这次因为有需要...不得不研究这个东西...顺便看看大家都是怎样实作异地备援的...底下是个人的一点点心得...
这次主要分成三个部份...单向Trusted SSH Authorized...Rsync...Crontab....姑且不论传输速度为何...以及无时差的异地备援...相信这样的Solutions应该可以满足一般人的需求吧
二.准备
测试系统: Red Hat Linux 7.3 to Red Hat 7.3 ...
Local端需要启动Rsync...套件openssh-3.4p1-1
**假设: A (10.0.0.1)要对B (192.168.0.1)做异地备援
PS:角色定位要明确...当然您要巅倒的来做也行...
参考网站: http://www.fanqiang.com/a6/b7/20010908/1305001258_b.html
三.开始实作
1.完成单向Trusted SSH Authorized﹕
我要A (10.0.0.1)要对B (192.168.0.1)做异地备援...所以我针对A让它使用SSH连到B时...不需要输入密码...User是Root.. .SSH Version2的版本..首先要先在A(10.0.0.1)产生public/private dsa key pair..
[root@mondeo home]# cd /root/.ssh/
[root@mondeo .ssh]# ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase): linux /]#chkconfig --list rsync
rsync off
[root@linux /]#chkconfig rsync on
现在我先在A(10.0.0.1)上建一个Backup directory...然后对B(192.168.0.1)的mysql跟html的目录做异地备援...偶写一个简单的script如下:
[root@mondeo /]# mkdir backup
[root@mondeo backup]#vi sync
rsync -avlR --delete -e ssh 192.168.0.1:/var/lib/mysql /backup/
rsync -avlR --delete -e ssh 192.168.0.1:/var/www/html /backup/
[root@mondeo backup]#chmod 700 sync
参数意义如下﹕
-a, --archive
It is a quick way of saying you want recursion and want to preserve almost everything.
-v, --verbose
This option increases the amount of information you are given during the transfer.
-l, --links
When symlinks are encountered, recreate the symlink on the destination.
-R, --relative
Use relative paths.保留相对路径...才不会让子目录跟parent挤在同一层...
--delete
是指如果Server端删除了一文件,那客户端也相应把这一文件删除,保持真正的一致。
-e ssh
建立起加密的连接。
参数的使用因人而异...您可以man rsync来使用更多的参数...
测试看看:
[root@mondeo backup]# ./sync
receiving file list ... done
.
.
.
done
wrote 16 bytes read 107 bytes 82.00 bytes/sec
total size is 0 speedup is 0.00
receiving file list ... done
.
.
.
done
wrote 16 bytes read 921 bytes 624.67 bytes/sec
total size is 308331 speedup is 329.06
[root@mondeo backup]#
看到没询问密码....以及有把档案copy过来就没问题啰....当然你可以把远端的资料做个变动...看是否真有同步啦....
3.使用crontab来做自动排程﹕
现在设好之后...我希望每天的0点0分...夜深人静的时后再来帮我做sync....当然您想要多久做sync看个人需求啰...
[root@mondeo backup]# crontab -e0 0 * * * /backup/sync
如此一来..算是大功告成了...原则上您已具备自动加密异地备援啰....赶紧找两台机器来试试吧...
以上只是个人测试结果...如有错误...烦请指教!!!
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56508/showart_498110.html |
|