moneyslow.com

rsync同步错误failed: Read-only file system (30)

rsync技巧

rsync技巧

你可能会碰到如下错误,检查文件和目录权限没有问题,rsync的ip授权也没有问题

sending incremental file list
moneyslow.cn.fullchain.cer
          2,832 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=1/2)
moneyslow.cn.key
            227 100%  221.68kB/s    0:00:00 (xfr#2, to-chk=0/2)
rsync: [receiver] mkstemp "/.moneyslow.cn.fullchain.cer.W4Lkw0" (in key) failed: Read-only file system (30)
rsync: [receiver] mkstemp "/.moneyslow.cn.key.af103y" (in key) failed: Read-only file system (30)

sent 2,344 bytes  received 268 bytes  1,741.33 bytes/sec
total size is 3,059  speedup is 1.17
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) [sender=3.2.7]

提示目标文件系统只读,这是因为被systemd的配置限制了服务对系统文件的访问权限

更改文件/lib/systemd/system/rsync.service配置,默认是full,改为none

[Service]
ProtectSystem=none

参数解释:

ProtectSystem=none:没有特别的保护,服务可以自由地访问系统文件。
ProtectSystem=full:会使/usr、/boot和/etc目录对服务来说是只读的,从而提供一定程度的保护。
ProtectSystem=strict:除了full提供的保护外,这个设置还会将整个文件系统(包括/home、/root和运行时目录)都设置为只读。

然后重新载入配置即可
systemctl daemon-reload
systemctl restart rsync


还有一个选择,那就是用ReadWritePaths参数开放指定某个目录的权限,这样更符合安全守则

[Service]
ProtectSystem保持默认配置

ProtectSystem=full
ReadWritePaths=/data3/web

Exit mobile version