rsync 跨服务器同步

rsync 跨服务器同步

  • 所在机器:192.168.6.1

  • 目标:将192.168.6.1上/www/cookie.com/pic.cookie.com/目录下所有内容同步到192.168.6.2上


操作:

1.在/etc/rsync.conf文件中新增模块[rsync_pic]

cat /etc/rsyncd.conf   
uid = root  
gid = root  
use chroot = no  
max connections = 8  
pid file = /var/run/rsyncd.pid  
lock file = /var/run/rsync.lock  
log file = /var/log/rsyncd.log  

hosts deny=*  
hosts allow=192.168.2.0/255.255.255.0 192.168.6.2  

[rsync_pic]  
    uid = www  
    gid = www  
    path = /www/cookie.com  
    ignore errors  
    read only = no  
    list = no  
    auth users = pic  
    secrets file = /etc/rsyncd.passwd

2.编辑密码文件

cat /etc/rsyncd.passwd   
pic:centos  

3.重启rsync

/etc/init.d/xinetd restart  
Stopping xinetd:                                           [  OK  ]  
Starting xinetd:                                           [  OK  ] 

4.检查端口是否OK

telnet 192.168.6.2 873  
Trying 192.168.6.2...  
Connected to 192.168.6.2.  
Escape character is '^]'.  
@RSYNCD: 30.0  
^C  
Connection closed by foreign host.

5.新增密码文件/www/rspic.passwd (密码文件权限为600)

cat /www/rspic.passwd   
centos 

6.编写脚本pic.sh (脚本权限为755)

cat /www/pic.sh  
rsync -auzv /www/cookie.com/pic.cookie.com/ pic@192.168.6.2::rsync_pic/pic.cookie.com/ --password-file=/www/rspic.passwd  

7.同步脚本定时执行(每一分钟执行一次)

crontab -l -u www  
*/1 * * * * bash /www/pic.sh  

你可能感兴趣的:(rsync)