rsync同步远程服务器数据(实战)

1.分别在服务器和客户机上下载rsync的源码包,然后执行下面的命令

[root@offserver dzy]# tar zxvf rsync-3.0.8
[root@offserver dzy]# cd rsync-3.0.8
[root@offserver rsync-3.0.8]# ./configure && make && make install

2.然后服务器上创建/etc/rsyncd.conf文件

uid=nobody
gid=nobody
use chroot=no
read only=yes
timeoutj=600
max connections=10
motd file=/etc/rsyncd.motd
secrets file=/etc/rsync.pas
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/var/log/rsyncd.log
[tomcat_logs]
comment tomcat_logs
path=/opt/apache-tomcat-6.0.18/logs
uid=root
gid=root
ignore errors
read only=no
auth users=root
secrets file=/etc/rsync.pas
保存退出

创建/etc/rsync.pas

root:123123123123

创建/etc/rsyncd.motd

please don't try to access our Server!

然后在客户机上创建一个空的/etc/rsyncd.conf或者加个注释符号

创建rsync.pas

vim /etc/rsync.pas

123123123123                      密码和服务器上rsync.pas中的密码一样

两边都启动rsync

 /usr/local/bin/rsync  --daemon

先查看一下服务器上的

[root@nj23 logs]# cd /opt/apache-tomcat-6.0.18/logs/
[root@nj23 logs]# ls
admin.2011-04-26.log     catalina.2011-09-01.log      host-manager.2011-09-01.log  localhost.2011-09-02.log  test
admin.2011-09-01.log     catalina.2011-09-02.log      host-manager.2011-09-02.log  manager.2011-04-26.log    test2
admin.2011-09-02.log     catalina.out                 localhost.2011-04-26.log     manager.2011-09-01.log
catalina.2011-04-26.log  host-manager.2011-04-26.log  localhost.2011-09-01.log     manager.2011-09-02.log
 

现在客户端开始同步

/usr/local/bin/rsync -auzv --progress --password-file=/etc/rsync.pas root@nj23::tomcat_logs /opt/tomcat_backup1 1> /opt/nj23_tomcat_backup_success.log 2> /opt/nj23_tomcat_backup_failed.log

在客户端的/opt/中就能看到一个tomcat_backup1的目录进入

[root@offserver tomcat_backup1]# cd /opt/tomcat_backup1/
[root@offserver tomcat_backup1]# ls
admin.2011-04-26.log     catalina.2011-09-02.log      localhost.2011-04-26.log  manager.2011-09-02.log
admin.2011-09-01.log     catalina.out                 localhost.2011-09-01.log  test
admin.2011-09-02.log     host-manager.2011-04-26.log  localhost.2011-09-02.log  test2
catalina.2011-04-26.log  host-manager.2011-09-01.log  manager.2011-04-26.log
catalina.2011-09-01.log  host-manager.2011-09-02.log  manager.2011-09-01.log
 

对比一下看看是不是同步过来了?这里的root和密码只是测试用的具体的要使用其他的用户去测试,这样能防止别人来偷袭哦

你可能感兴趣的:(职场,实例,rsync,休闲,同步远程服务器数据)