Rsync同步

實現(xiàn)rsync文件同步,且不需要手工輸入密碼,思路如下
測試環(huán)境:
服務端:Centos7
客戶端:MacOS 10.15.7

1、配置服務器端需要將rsync程序以 daemon 模式運行

1,編輯同步配置文件

vim /etc/rsyncd.conf

寫入以下內(nèi)容:

uid = root
gid = root
port = 873
read only = no
# 允許訪問的客戶端ip,多個用逗號分隔
hosts allow = 222.128.9.86

# 運行同步的模塊,可配置多個
[epwxWork]
       comment = this is module for backup    
       path = /usr/local/src/
       auth users = root
       secrets file = /etc/rsyncd.pass

2,創(chuàng)建密碼文件

vim /etc/rsyncd.pass

寫入以下內(nèi)容(格式為用戶名:密碼,用戶名與模塊的auth users相同):

root:eplugger123

設置密碼文件權(quán)限(必須做)

chmod 600 /etc/rsyncd.pass

3,查看當前rsync進程,殺掉并重啟啟動。

ps -ef|grep rsync  |grep -v grep
kill 進程號
rsync  --daemon
#再次查看是否已運行
ps -ef|grep rsync  |grep -v grep

4,添加防火墻服務端口

firewall-cmd --permanent --zone=public --add-service=rsyncd
systemctl restart firewalld.service
# 確認已啟用
firewall-cmd --list-all

2、客戶機

1,創(chuàng)建密碼文件rsyncd.pass(為了免手工輸入密碼)
/路徑/rsyncd.pass
寫入密碼(無用戶名),密碼與服務端配置相同

設置密碼文件權(quán)限(必須做)

chmod 600 /路徑/rsyncd.pass

2,執(zhí)行同步

# 其中 epwxWork 為模塊名
# 其中 root 與服務端的用戶名配置相同
rsync -rltzuq --delete --exclude='.*' 本地路徑 root@服務端ip::epwxWork --password-file=/路徑/rsyncd.pass

如果沒有很多模塊,也可設置全局rsync密碼,這樣就不需要創(chuàng)建密碼文件了,也不需要--password-file參數(shù)了:

export  RSYNC_PASSWORD=密碼

取消環(huán)境變量:

unset   RSYNC_PASSWORD
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容