【服务端配置】
系统版本
# lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 18.04.2 LTSRelease: 18.04Codename: bionic
官方文档:
安装
sudo apt install rsync xinetd
在 /etc/default/rsync 文件内修改或添加
RSYNC_ENABLE=inetd
创建 /etc/xinetd.d/rsync 文件,添加如下内容:
service rsync{ disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += 0 # user ID}
创建 /etc/rsyncd.conf 文件,添加如下内容:
max connections = 5log file = /var/log/rsync.loglock file = /var/lock/rsyncd.locktimeout = 300charset = GB18030 # 用于避免中文乱码[share] # 模块名comment = Public Share# path为需要同步的文件夹路径path = /var/testhosts allow = 192.168.0.0/16hosts deny = *read only = nolist = yesuid = rootgid = root# 必须和 rsyncd.secrets中的用户名对应auth users = walkersecrets file = /etc/rsyncd.secrets
创建 /etc/rsyncd.secrets 文件,添加如下内容:
# 配置用户名和密码,密码可以任意设置walker:test
修改 rsyncd.secrets 文件权限
sudo chmod 600 /etc/rsyncd.secrets
启动/重启 xinetd
sudo /etc/init.d/xinetd restart
如果端口未被监听,可尝试重启系统
# netstat -anop | grep 873tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 929/rsync off (0.00/0/0)tcp6 0 0 :::873 :::* LISTEN 929/rsync off (0.00/0/0)
【客户端测试】
系统版本(Windows 10 x64 1803)
winver
客户端软件版本
cwRsyncServer 4.0.5.0
将服务端文件同步至本地
rsync -cvazu --progress walker@192.168.136.131::share ./test# --iconv=locale_charset,remote_charset 用于避免中文乱码rsync -cvazu --progress --iconv=UTF-8,GB18030 walker@192.168.136.131::share ./test
若报以下错误,查看服务器端口是否开放(检查防火墙,重启服务器...)
rsync: failed to connect to 218.107.243.2: No route to host (113)rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]
【名词解释】
xinetd: eXtended InterNET services daemon
【相关阅读】
*** ***