rsync服务的搭建和使用
***下载安装:
#wget https://download.samba.org/pub/rsync/src/rsync-3.1.2.tar.gz
#tar -zxvf rsync-3.1.2.tar.gz
#cd rsync-3.1.2
#./configure --prefix=/usr/local/rsync
#make
#make install
第一步:修改rsyncd的配置文件,增加测试目录test
#vim /etc/rsyncd.conf
uid = www-data
gid = www-data
use chroot = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[test_code]
path = /data/www/html
comment = web resources
read only = no
strict modes = yes
refuse options = delete
auth users = test
secrets file = /etc/rsyncd_auto_rsync_users
hosts allow = xxx.xxx.xxx.xxx
post-xfer exec = /data/sa/reload_nginx.sh //指定同步完成之后触发执行的脚本
[test]
path = /data/test
max connections = 5 //最大连接数
comment = test
read only = no
strict modes = yes
refuse options = delete //拒绝删除操作
auth users = test
secrets file = /etc/rsyncd_auto_rsync_users
hosts allow = xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx
transfer logging = yes
log format = %t %o %a %m %u %f %l %b
log file = /var/log/rsyncd_test.log
post-xfer exec = /data/sa/reload_nginx.sh
第二步:修改rsync密码文件,添加pic_test模块的用户和密码
root@localhost:/data/sa# cat /etc/rsyncd_auto_rsync_users
test:xxxxxxxxxxxxxx
test1:xxxxx
第三步:
重启rsyncd服务
/usr/bin/rsync --no-detach --daemon --config /etc/rsyncd.conf --port=873 &
命令同步示例:
从rsync服务器同步test_code模块文件到本地,除/home/huangjie1/pass_id.list目录以外的文件:
rsync -avuzt --exclude-from '/home/huangjie1/pass_id.list' test@rsync_ip::test_code/* /data/www/html/
扩展:一般和sersync,lrsync,inotify-tools等工具实现自动发现实时同步文件或者双向同步,各有优缺点,可自行查阅资料了解。