1. 程式人生 > >rsync 測試配置

rsync 測試配置

本文主要參考:

https://www.cnblogs.com/lemon-le/p/8395438.html

 

http://man.linuxde.net/rsync

 

實驗開始!

rsync 作用: 類似 由客戶機向伺服器上傳檔案進行備份的一個過程。

 

daemon模式下的具體配置

(daemon模式是以守護程序(socket)的方式傳輸資料)

1.伺服器端

(1)rsync以daemon方式執行的時候使用配置檔案為rsyncd.conf

(2) rsyncd.conf配置檔案

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

uid = root

gid = root

use chroot = no

max connections = 2

pid file = /var/run/rsyncd.pid

log file = /var/log/rsyncd.log

lock file = /var/run/rsyncd.lock



[test]

path = /captain/shell

read only = no

auth users = rsync

secrets file = /etc/rsyncd.secrets

list = no

解釋說明:

1)uid、gid:當使用非root賬號時,那麼一定要確保服務的的資料夾是否有該非root賬號寫入的許可權

2)use chroot = no :是否可以切換到root目錄,當chroot為yes的時候,客戶端連線模組的時候,先chroot到模組引數指定的目錄下,必須使用root許可權,埠號必須是1024以內,且不能備份path路徑外的連結檔案

3)max connections = 2 :表示同時最大的連線數,也就是同時只能有兩個客戶端對自己進行連線

4)path = /captain/shell:表示的是當客戶端把資料同步過來將儲存的路徑

5)read only = no :如果為只讀,那麼將不能進行寫同步,所以必須關閉

6)auth users = rsync :用來進行同步的使用者,不需要系統使用者中有,虛擬的就行

7)secrets file = /etc/rsyncd.secrets :表示的是賬號密碼檔案,此檔案可隨意指定,檔案裡必須以username:password的格式;檔案許可權必須為600,否則會報錯【chmod 600 filename】

rsyncd.secrets檔案內容:

rsync:123456

8)list = no :表示的是當服務端拒絕客戶端的請求時,是否是直接顯示許可權拒絕,還是現實模組不存在,一般與hosts allow 和hosts deny一起使用

(3)啟動方式

daemon模式執行必須啟動的時候加引數 --daemon

rsync --daemon

netstat -ano 命令發現伺服器開始監聽873埠

(4)開啟防火牆,開放873埠

 

2.客戶端

(1)配置檔案 rsyncd.conf

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:



#uid = root

#gid = root

#use chroot = yes

#max connections = 4

pid file = /var/run/rsyncd.pid

log file = /var/log/rsyncd.log

# exclude = lost+found/

# transfer logging = yes

# timeout = 900

# ignore nonreadable = yes

# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2



# [ftp]

# path = /home/ftp

# comment = ftp export area

(2)設定password檔案

 

同時該檔案許可權同樣為 600:

 

3. 同步命令(實驗)

3.1 伺服器啟動:rsync --daemon

本機傳到遠端伺服器:

rsync -avz --password-file=/etc/rsyncd.passwd filepath [email protected]::test

本機從遠端伺服器獲取:獲取遠端伺服器配置檔案中[test]配置的檔案(路徑),建立localfile路徑存放[test]中的所有檔案

rsync -avz --password-file=/etc/rsyncd.passwd [email protected]::test localfile

此時dport=873

 

3.2 通過SSH方式通訊,類似sftp,scap模式

(參考:http://man.linuxde.net/rsync

1.使用一個遠端shell程式(如rsh、ssh)來實現將本地機器的內容拷貝到遠端機器。當DST路徑地址包含單個冒號":"分隔符時啟動該模式。如:rsync -avz *.c foo:src

2.使用一個遠端shell程式(如rsh、ssh)來實現將遠端機器的內容拷貝到本地機器。當SRC地址路徑包含單個冒號":"分隔符時啟動該模式。如:rsync -avz foo:src/bar /data

此時dport=22