rsync使用小结
04-17
多台服务器使用,难免用到同步,工作中大量接触的是rsync,简单测试了一下其命令和应用。
rsync官方主页: http://samba.anu.edu.au/rsync/ 下载地址为:http://samba.anu.edu.au/ftp/rsync/rsync-3.0.7.tar.gz
安装:
- ./configure --prefix=/opt/rsync-3.0.7
- make
- make install
默认好像没有生成配置文件,创建
- vi /etc/rsync.conf
- //填入以下内容
- uid=nobody
- gid=nobody
- max connections=3
- use chroot=no
- log file=/var/log/rsyncd.log
- pid file=/var/run/rsyncd.pid
- lock file=/var/run/rsyncd.lock
测试的两台主机:192.168.0.20 192.168.0.30
在192.168.0.30的/etc/rsync.conf下增加以下代码
- [test] //定义一个域
- path=/root/test
- comment=test folder
- uid=root
- ignore errors
- read only=no
- list=no
然后测试两个命令
1、把192.168.0.20上的 /root/source 目录同步到 192.168.0.30 的 /root/test上
/opt/rsync-3.0.7/bin/rsync -vazu –progress /root/source 192.168.0.30::test
2、从192.168.0.30 的 /root/test 同步到 192.168.0.20上的/root/test
/opt/rsync-3.0.7/bin/rsync -vzrtopg –progress 192.168.0.30::test /root/test
配置权限:
在192.168.0.30上vi /etc/rsycnpass 然后 echo test:123456 >> /etc/rsycnpass
配置文件修改为
- secrets file = /etc/rsyncpass
- [test] //定义一个域
- path=/root/test
- comment=test folder
- uid=root
- ignore errors
- read only=no
- list=no
- auth users=test
则上边命令1修改为 /opt/rsync-3.0.7/bin/rsync -vazu –progress /root/source test@192.168.0.30::test
命令2改为 /opt/rsync-3.0.7/bin/rsync -vzrtopg –progress test@192.168.0.30::test /root/test