rsync配置教程

本文默认服务器已经安装了 rsync !

本文默认服务器已经安装了 rsync !

本文默认服务器已经安装了 rsync !

切换到 /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

1、配置 rsyncd.conf

参考模板:

# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root                         
gid = root                                  

use chroot = no                             

read only = no                            

#limit access to private LANs
#hosts allow=
#hosts deny=*                                
max connections = 20             

pid file = /var/run/rsyncd.pid             

secrets file = /etc/rsyncd/rsyncd.secrets   
lock file = /var/run/rsync.lock           

#motd file = /etc/rsyncd/rsyncd.motd        

#This will give you a separate log file
log file = /var/log/rsync.log               

#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes                    

log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

# MODULE OPTIONS

[www]
path = /www/
list=yes
ignore errors
auth users = test
comment = test

2、配置完成之后要启动 rsync;如果已经重启的话,杀掉进程后再启动,运行:ps -aux | grep rsync,找到进程号,kill [进程号]

启动命令:

/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf

3、rsyncd.conf 配置项说明

######### 全局配置参数 ##########
port=888    # 指定rsync端口。默认873
uid = rsync # rsync服务的运行用户,默认是nobody,文件传输成功后属主将是这个uid
gid = rsync # rsync服务的运行组,默认是nobody,文件传输成功后属组将是这个gid
use chroot = no # rsync daemon在传输前是否切换到指定的path目录下,并将其监禁在内
max connections = 200 # 指定最大连接数量,0表示没有限制
timeout = 300         # 确保rsync服务器不会永远等待一个崩溃的客户端,0表示永远等待
motd file = /var/rsyncd/rsync.motd   # 客户端连接过来显示的消息
pid file = /var/run/rsyncd.pid       # 指定rsync daemon的pid文件
lock file = /var/run/rsync.lock      # 指定锁文件
log file = /var/log/rsyncd.log       # 指定rsync的日志文件,而不把日志发送给syslog
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2  # 指定哪些文件不用进行压缩传输
 
###########下面指定模块,并设定模块配置参数,可以创建多个模块###########
[www]        # 模块ID
path = /www/ # 指定该模块的路径,该参数必须指定。启动rsync服务前该目录必须存在。rsync请求访问模块本质就是访问该路径。
ignore errors      # 忽略某些IO错误信息
read only = false  # 指定该模块是否可读写,即能否上传文件,false表示可读写,true表示可读不可写。所有模块默认不可上传
write only = false # 指定该模式是否支持下载,设置为true表示客户端不能下载。所有模块默认可下载
list = false       # 客户端请求显示模块列表时,该模块是否显示出来,设置为false则该模块为隐藏模块。默认true
hosts allow = 10.0.0.0/24 # 指定允许连接到该模块的机器,多个ip用空格隔开或者设置区间
hosts deny = 0.0.0.0/32   # 指定不允许连接到该模块的机器
auth users = rsync_backup # 指定连接到该模块的用户列表,只有列表里的用户才能连接到模块,用户名和对应密码保存在secrts file中,
                          # 这里使用的不是系统用户,而是虚拟用户。不设置时,默认所有用户都能连接,但使用的是匿名连接
secrets file = /etc/rsyncd.passwd # 保存auth users用户列表的用户名和密码,每行包含一个username:passwd。由于"strict modes"
                                  # 默认为true,所以此文件要求非rsync daemon用户不可读写。只有启用了auth users该选项才有效。
[test]    # 以下定义的是第二个模块
path=/test/
read only = false
ignore errors
comment = anyone can access

4、rsyncd.secrets 权限配置,如果这个文件的权限给太高的话,可能无法正常启动,给“只读”权限就行

chmod 400 rsyncd.secrets

5、查看 rsync 是否正常运行以及网络状态

ps -ef | grep rsync  #查看进程
netstat -lntup | grep rsync        #查看网络状态

6、检查ECS服务器是否开发对应的端口,在服务器管理界面找到 “本实例安全组” -> "内网入方向全部规则",查看对应的 rsync 端口有没有开放,没有的话添加即可;在 “安全组列表” 的列表中选择你对应的安全组ID找到 “配置规则”,点进去,把你的 rsync 端口配置到 “入规则” 中

7、测试

rsync -avr composer.json rsync://www@[host]/www/

rsync -avr --delete --progress --password-file=rsyncd.secrets ./ --exclude '*.log' rsync://www@[host]/www/


参考:
https://blog.csdn.net/jsd2honey/article/details/78731637
https://www.cnblogs.com/zhangsubai/p/5194490.html
https://www.cnblogs.com/wang-xd/p/6551402.html

原文地址:https://www.cnblogs.com/lyc94620/p/10858010.html