rsync服务端:172.31.97.106
rsync客户端:172.31.97.28
一、服务端安装配置
1、安装rsync服务
rpm -qa |grep rsync #查看是否已安装rsync
yum -y install rsync
#启动rsync服务
systemctl start rsyncd.service #rsync –daemon 这种方式启动也可
systemctl enable rsyncd.service #echo "rsync --daemon" >> /etc/rc.local加入开机自启
#检查是否已经成功启动
netstat -lnp|grep :873 #默认是873端口,我这里把服务端改成878
2、配置rsync服务
[root@master-1 video]# cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# 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
port = 878 #修改默认端口
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 300
motd file = /var/rsyncd/rsync.motd
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
dont compress = *.gz *.tgz *.z *.Z *.rpm *.deb *.bz2 *.zip #这类文件不做二次压缩
[ats]
path = /data/ats/video #需要同步资源的存放目录
ignore errors
read only = false
write only = false
list = false
hosts allow = 172.31.97.0/24
hosts deny = 0.0.0.0/32
auth users = root #增加同步时用户认证,需要输入密码
secrets file = /etc/rsyncd.passwd
[root@master-1 video]#
3、给rsync定义身份
如下:
echo 'root:123456'>/etc/rsyncd.passwd //文件用户名和路径为上面定义,别写错,密码自己定
chmod 600 /etc/rsyncd.passwd //修改权限
最后重启:
systemctl restart rsyncd.service
二、客户端配置
yum -y install rsync #启动rsync服务 systemctl start rsyncd.service # rsync –daemon 这种方式启动也可 systemctl enable rsyncd.service # echo "rsync --daemon" >> /etc/rc.local加入开机自启 #检查是否已经成功启动 netstat -lnp|grep :873 创建密码 echo '123456' >>/etc/rsyncd.passwd //注意这里只需要服务器rsyncd.passwd 中的密码 chmod 600 /etc/rsyncd.passwd
三、测试验证
1、在客户端上进行验证
rsync -rlptD /root/bethune.zip rsync://root@172.31.97.106:878/ats/
在服务端进行查看,已同步完成
2、如果想同步时不加鉴权可在服务端/etc/rsyncd.conf将截图中注释然后重启rsync即可。
3、最后可将同步命令写成一个脚本,在添加到crontab定时任务中,让他定时同步就行
crontab -e
至此rsync同步工具部署完毕。