rsync 默认安装的
远端 192.168.1.123
本地 192.168.1.124
rsync + ssh
在本地主机执行
rsync -az [email protected]:/root /bak #目录
rsync -az [email protected]:/root/ /bak #目录里面的内容
或者
在远端主机
rsync -az /root [email protected]:/bak
rsync -az /root/ [email protected]:/bak
rsync客户端 + rsync服务端
服务端
建立同步账号文件(匿名则不需要)
echo "zongxuan:zongxuan" > /etc/rsyncd_users.db
权限必须严格,否则同步会失败
chmod 600 /etc/rsyncd_users.db
建立 /etc/rsyncd.conf 共享设置
uid = nobody #指定该模块以指定的 UID 传输文件,同步一些敏感的就root
gid = nobody #指定该模块以指定的 GID 传输文件。
use chroot = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[zongxuan]
path = /tmp
comment = rsync test
read only = yes
dont compress = *.gz *.bz2 *.tgz *.zip #不压缩
auth users = zongxuan
secrets file = /etc/rsyncd_users.db #指定账号文件的路径
启用 rsync --daemon 服务
追加到开机
echo “/usr/local/bin/rsync --daemon” >>/etc/rc.local
yum -y install xinetd
chkconfig rsync on
chkconfig xinetd on
service xinetd restart
客户端
浏览共享
rsync [email protected]::tools
同步
mkdir /root/mysrc
rsync -avz --delete [email protected]::zongxuan /bak/ #下行同步,删除mysrc中多余文件
客户端只要配置密码文件即可。
# cd /etc
vim rsyncd.secretes
echo "zongxuan" > /etc/rsyncd.secretes
chmod 600 /etc/rsyncd.secretes
/usr/bin/rsync --avz --password-file=/etc/rsyncd.secretes --progress [email protected]::zongxuan /bak/
rsync 实时同步(inotify监控及触发)
tar zxf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure
make && make install
inotifywait -mrq -e modify,move,create,delete,attrib /my | while read X Y Z ; /usr/bin/rsync --avz --password-file=/etc/rsyncd.secretes --progress
[email protected]::zongxuan /bak/ ; done