安装:yum -y install rsync
#检查是否已经成功启动
netstat -lnp|grep 873
否则开启873端口
配置文件:/etc/rsyncd.conf
rsyncd.conf:
# See rsyncd.conf man page for more options.
# configuration example:
# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[tslog]
path=/data/tslog
uid=haofei
gid=haofei
auth users=tslog
secrets file=/etc/rsyncd.password
read only = false
list = false
[gamelog]
path=/data/log
uid=haofei
gid=haofei
auth users=gamelog
secrets file=/etc/rsyncd.password
read only = false
list = false
密码文件:/etc/rsyncd.password 记录密码,需要赋予权限600:chmod 600 rsyncd.password
同步服务端:
#启动rsync服务
systemctl start rsyncd.service
systemctl enable rsyncd.service
防火墙 开端口
同步客户端:
创建同步的目录
创建密码文件,赋予权限600
如:rsync.pwd
使用脚本进行同步
如:
#!/bin/bash
rsync -avzP –no-owner –no-perms –password-file=rsync.pwd gamelog@172.18.133.137::gamelog /data/gamelog/QA/172.18.133.137
rsync -avzP –no-owner –no-perms –password-file=rsync.pwd gamelog@172.18.133.138::gamelog /data/gamelog/dev/172.18.133.138
定时执行脚本:在/var/spool/cron/路径下添加定时执行文件
如:root文件
*/5 * * * * cd /home/haofei/.rsync && ./rsync_tslog.sh >/dev/null 1>&1
*/5 * * * * cd /home/haofei/.rsync && ./rsync_gamelog.sh >/dev/null 2>&0