Ubuntu Server 18.04 配置 rsync(systemctl)

【服務端配置】

  • 系統版本

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic
sudo apt install rsync
  • 創建 /etc/rsyncd.conf 文件,添加如下內容:

max connections = 5
log file = /var/log/rsync.log
lock file = /var/lock/rsyncd.lock
timeout = 300
#charset = GB18030    # 某些情況下避免中文亂碼

[share] # 模塊名
comment = Public Share
# path爲需要同步的文件夾路徑
path = /var/test
hosts allow = 192.168.0.0/16
hosts deny = *
read only = no
list = yes
uid = root
gid = root
# 必須和 rsyncd.secrets中的用戶名對應
auth users = walker
secrets file = /etc/rsyncd.secrets
  • 關於主機訪問控制,allow 比 deny 優先級高,也就是說 rsync 不關注 allow 和 deny 的順序。如果主機既不在 hosts allow 也不在 hosts deny,則根據默認策略,允許連接。官方文檔【hosts allow】一節有詳細描述。

# 主機允許列表(空格或逗號分隔),高優先級
hosts allow = 【】
# 主機禁止列表(空格或逗號分隔),低優先級
# 建議總是加上一個*來禁止異常的任何連接
hosts deny = 【】

# 主機的格式有五種: ip、ip/netmask、ip/n、hostname、通配符hostname
  • 創建 /etc/rsyncd.secrets 文件,添加如下內容:

# 配置用戶名和密碼,密碼可以任意設置
walker:test
  • 修改 rsyncd.secrets 文件權限

sudo chmod 600 /etc/rsyncd.secrets
  • 啓動 rsync

sudo systemctl start rsync
  • 檢查端口,如果端口未被監聽,可嘗試重啓系統

# netstat -anop | grep 873
tcp    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)
  • 設置開機啓動

sudo systemctl enable rsync


【客戶端測試】

  • 系統版本(Windows 10 x64 1803)

winver
  • 客戶端軟件版本

cwRsyncServer 4.0.5.0
  • 將服務端文件同步至本地

rsync -cvazu --progress [email protected]::share ./test
# --iconv=locale_charset,remote_charset 某些情況下可避免中文亂碼
rsync -cvazu --progress --iconv=UTF-8,GB18030 [email protected]::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]


【相關閱讀】


*** walker *** 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章