本文主要梳理 rsync server 的基本配置与使用方式;

rsync server 的几个关键配置文件

  1. /etc/rsyncd.conf: 主配置文件;
  2. /etc/rsyncd.password/rsyncd.secrets: 秘钥文件;
  3. /etc/rsyncd.motd: rysnc 服务器元信息, 非必须;

其中, rsyncd.password 秘钥文件的掩码必须是 600:

1
2
3
> ll /etc/ | grep rsyncd
-rw-r--r-- 1 root root 361 Apr 6 2017 rsyncd.conf
-rw------- 1 root root 24 Apr 6 2017 rsyncd.password

rsyncd.conf 配置说明

一个典型的 rsyncd.conf 文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# rsyncd 守护进程运行系统用户全局配置, 可在具体的块中配置
uid=nobody
gid=nobody

# 是否需要 chroot, 若为 yes, 当客户端连接某模块时, 首先 chroot 到 模块的 path 目录下
user chroot = no

max connections = 200
timeout = 600

pid file = /data1/trans_file/rsyncd.pid
lock file = /data1/trans_file/rsyncd.lock
log file = /data1/trans_file/rsyncd.log
# 用户秘钥文件, 可在具体的模块中配置
secrets file = /etc/rsyncd.password
# 服务器元信息, 非必选
# motd file = /etc/rsyncd/rsyncd.motd
# 指定不需要压缩就可以直接传输的文件类型
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# 模块配置
[wireless_log]
# 模块使用的 user, 此模块将使用 rsyncd.password 文件中 sync 用户对应的秘钥进行文件传输
auth users = sync
path = /data1/trans_file/files/wireless_log
ignore errors
# 是否只读
read only = no
# 是否允许列出模块里的内容
list = no

rsyncd.password / rsyncd.secrets 配置说明

: 分隔, 用户名和密码, 每行一个:

1
2
user1:password1
user2:password2

rsyncd 启动方式

1
2
# 当负载高时, 以守护进程的方式运行 rsyncd
sudo /usr/bin/rsync --daemon --config=/etc/rsyncd.conf

参考链接