Chinaunix首页 | 论坛 | 博客
  • 博客访问: 439831
  • 博文数量: 237
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-12 14:40
个人简介

  每个人生的当口,都是会有一个孤独的时刻,四顾无人,只有自己,于是不得不看明白自己的脆弱,自己的欲望,自己的念想,自己的界限,还有,自己真正的梦想。

文章分类

全部博文(237)

文章存档

2017年(3)

2016年(234)

分类: LINUX

2016-05-11 11:17:19

     这文章是从别人的博客转过来的,链接忘了。真的很对不起这位博主。

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): <-- 此处不打passphrase..下次才不会询问password
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
11:22:33:44:55:66:77:88:99:00:11:22:33:44:55:66 root@mondeo.adj.idv.tw
[root@mondeo .ssh]#
……………………………………………………………………………………………………
这时会在系统下看到两个档案...id_dsa与id_dsa.pub 现在要把id_dsa.pub丢到192.168.0.1 并且更名为 authorized_keys2
……………………………………………………………………………………………………
[root@mondeo .ssh]# scp id_dsa.pub 192.168.0.1:/root/.ssh/authorized_keys2
root@192.168.0.1's password:
id_dsa.pub 100% |*****************************************************| 612 00:00
[root@mondeo .ssh]#
……………………………………………………………………………………………………
现在您可以执行ssh 192.168.0.1 看看能否登入而不需要输入密码...
2.使用rsync 做Remote sync﹕
rsync特性简介 :
rsync是unix-like系统下的数据镜像备份工具,从命名上就可以看出来了remote sync。它的特性如下:
1、可以镜像保存整个目录树和文件系统。
2、可以很容易做到保持原来文件的权限、时间等等。
3、无须特殊权限即可安装。
4、优化的流程,文件传输效率高。
5、可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。
6、支持匿名传输。
首先要先对B(192.168.0.1)把Rsync的Server on起来...
……………………………………………………………………………………………………
[root@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过来就没问题啰....当然你可以把远程的数据做个变动...看是否真有同步啦....
2. 使用crontab 来做自动排程﹕

现在设好之后...我希望每天的0点0分...夜深人静的时后再来帮我做sync....当然您想要多久做 sync 看个人需求啰...
……………………………………………………………………………………………………
[root@mondeo backup]# crontab -e
0 0 * * * /backup/sync
……………………………………………………………………………………………………


阅读(464) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~