Debian 64位環境下面的Rsync配置詳解

Rsync 配置 詳細
測試環境:
 A:debian 6.0 64位操作系統 (服務器端) IP:192.168.1.100
 B:debian 6.0 64位操作系統 (客戶機端) IP:192.168.1.97
 
一、服務器端配置
 1、安裝Rsync
  aptitude install rsync
 2、mkdir /etc/rsyncd  注:在/etc目錄下創建一個rsyncd的目錄,我們用來存放rsyncd.conf 和rsyncd.secrets文件; 
 3、touch /etc/rsyncd/rsyncd.conf  注:創建rsyncd.conf ,這是rsync服務器的配置文件;
 4、touch /etc/rsyncd/rsyncd.secrets  注:創建rsyncd.secrets ,這是用戶密碼文件;
 5、chmod 600 /etc/rsyncd/rsyncd.secrets  注:爲了密碼的安全性,我們把權限設爲600;
 6、ls -lh /etc/rsyncd/rsyncd.secrets
  -rw------- 1 root root 0  8月 26 11:44 /etc/rsyncd/rsyncd.secrets
 7、touch /etc/rsyncd/rsyncd.motd
 我們來個簡單的示例;比如我們要備份服務器上的 /data目錄 ,在/data目錄中,我想把program和temp目錄排除在外;
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid 
port = 873 #注:指定運行端口,默認是873,您可以自己指定;
address = 192.168.1.100 #注:指定服務器IP地址;
uid = root 
gid = root 

use chroot = yes
read only = yes
#注:用chroot,在傳輸文件之前,服務器守護程序在將chroot 到文件系統中的目錄中,這樣做的好處是可能保護系統被安裝漏洞侵襲的可能。缺點是需要超級用戶權限。另外對符號鏈接文件,將會排除在外。也就是說,你在 rsync服務器上,如果有符號鏈接,你在備份服務器上運行客戶端的同步數據時,只會把符號鏈接名同步下來,並不會同步符號鏈接的內容;這個需要自己來嘗試;
#注:read only 是隻讀選擇,也就是說,不讓客戶端上傳文件到服務器上。還有一個 write only選項,自己嘗試是做什麼用的吧;
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
#注:在您可以指定單個IP,也可以指定整個網段,能提高安全性。格式是ip 與ip 之間、ip和網段之間、網段和網段之間要用空格隔開;
max connections = 5
#注:客戶端最多連接數;
motd file = /etc/rsyncd/rsyncd.motd
#注:motd file 是定義服務器信息的,要自己寫 rsyncd.motd 文件內容。
#This will give you a separate log file
log file = /var/log/rsync.log
#注:rsync 服務器的日誌;
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
#注:這是傳輸文件的日誌;
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[data] 
#注:模塊,它爲我們提供了一個鏈接的名字,鏈接到哪呢,在本模塊中,鏈接到了/data目錄;要用[name] 形式;
path = /opt   #注:指定文件目錄所在位置,這是必須指定的;
list=yes #注:list 意思是把rsync 服務器上提供同步數據的目錄在服務器上模塊是否顯示列出來。默認是yes 。如果你不想列出來,就no ;如果是no是比較安全的,至少別人不知道你的服務器上提供了哪些目錄。你自己知道就行了;
ignore errors #注:忽略IO錯誤,詳細的請查文檔;
auth users = root #注:認證用戶是 root  ,是必須在 服務器上存在的用戶;
secrets file = /etc/rsyncd/rsyncd.secrets  #注:密碼存在哪個文件;
comment = linuxsir home # 注:註釋可以自己定義,寫什麼都行,寫點相關的內容就行;
exclude =   program/  temp/     #注:exclude 是排除的意思,也就是說,要把/opt目錄下的program和temp 排除在外; program/和temp/目錄之間有空格分開 ; 
#注: 關於 auth users 是必須在服務器上存在的真實的系統用戶,如果你想用多個用戶,那就以,號隔開;比如 auth users = root , root1
#
#
#
2、密碼文件:/etc/rsyncd/rsyncd.secrets的內容格式:用戶名:密碼
rsyncd.secrets文件權限對其它用戶組是不可讀的。如果設置錯誤,可能rsync不工作。
這裏的密碼和系統密碼無任何關係
如:root:123456
3、/etc/rsyncd/rsyncd.motd

+++++++++++++++++++++++++++
+ Tianbymy  rsync  2010-2011 +
++++++++++++++++++++++++++


啓動 Rsync
/usr/bin/rsync --daemon  --config=/etc/rsyncd/rsyncd.conf
防火牆設置
Linux 防火牆是用iptables,所以我們至少在服務器端要讓你所定義的rsync 服務器端口通過,客戶端上也應該讓通過。

iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT
iptables -L  #查看一下防火牆是不是打開了 873端口;

######################################
客戶機配置
######################################
1、首先:我們看看rsync服務器上提供了哪些可用的數據源;

rsync  --list-only  [email protected]::
返回:
 +++++++++++++++++++++++++++
 + Tianbymy  rsync  2010-2011 +
 +++++++++++++++++++++++++++

 data            linuxsir home # 注:註釋可以自己定義,寫什麼都行,寫點相關的內容就行;
注: 前面是rsync 所提供的數據源,也就是我們在rsyncd.conf 中所寫的[data]模塊。而“linuxsir home”是由[data]模塊中的 comment = linuxsir home 提供的;//爲什麼沒有把beinan 數據源列出來呢?因爲我們在[beinan]中已經把list=no了。 
再:試試這個?
rsync  --list-only  [email protected]::linuxsirhome

2、 rsync 客戶端同步數據;
rsync -avzP [email protected]::data   data
注: 這個命令的意思就是說,用root 用戶登錄到服務器上,把data數據,
同步到本地目錄data上。當然本地的目錄是可以你自己定義的,比如 其他任意目錄也是可以的;
當你在客戶端上,當前操作的目錄下沒有data這個目錄時,系統會自動爲你創建一個;
當存在 data這個目錄中,你要注意它的寫權限。
說明:
-a 參數,相當於-rlptgoD,-r 是遞歸 -l 是鏈接文件,意思是拷貝鏈接文件;-p 表示保持文件原有權限;-t 保持文件原有時間;-g 保持文件原有用戶組;-o 保持文件原有屬主;-D 相當於塊設備文件;
-z 傳輸時壓縮;
-P 傳輸進度;
-v 傳輸時的進度等信息,和-P有點關係,自己試試
rsync -avzP  --delete [email protected]::data   data
#這回我們引入一個 --delete 選項,表示客戶端上的數據要與服務器端完全一致,如果 linuxsirhome目錄中有服務器上不存在的文件,則刪除。最終目的是讓linuxsirhome目錄上的數據完全與服務器上保持一致;用的時候要小心點,最好不要把已經有重要數所據的目錄,當做本地更新目錄,否則會把你的數據全部刪除;
rsync -avzP  --delete  --password-file=rsync.password  [email protected]::data   data
這次我們加了一個選項 --password-file=rsync.password ,這是當我們以linuxsir用戶登錄rsync服務器同步數據時,密碼將讀取 rsync.password 這個文件。這個文件內容只是linuxsir用戶的密碼。我們要如下做;

touch rsync.password
chmod 600 rsync.passwod
echo "222222"> rsync.password
rsync -avzP  --delete  --password-file=rsync.password  [email protected]::data  data


##################################################################
RSYNC常見問題
問題一:

@ERROR: chroot failed

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服務器端的目錄不存在或無權限。創建目錄並修正權限可解決問題。

 

問題二:

@ERROR: auth failed on module tee

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服務器端該模塊(tee)需要驗證用戶名密碼,但客戶端沒有提供正確的用戶名密碼,認證失敗。提供正確的用戶名密碼解決此問題。

 

問題三:

@ERROR: Unknown module ‘tee_nonexists’

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服務器不存在指定模塊。提供正確的模塊名或在服務器端修改成你要的模塊以解決問題。

 

問題四:

password file must not be other-accessible

continuing without password file

Password:

原因:

這是因爲rsyncd.pwd rsyncd.secrets的權限不對,應該設置爲600。如:chmod 600 rsyncd.pwd

 

問題五:

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]

原因:

對方沒開機、防火牆阻擋、通過的網絡上有防火牆阻擋,都有可能。關閉防火牆,其實就是把tcp udp的873端口打開。

 

問題六:

rsync error: error starting client-server protocol (code 5) at main.c(1524) [Receiver=3.0.7]

原因:

/etc/rsyncd.conf配置文件內容有錯誤。請正確覈對配置文件。

 

問題七:

rsync: chown "" failed: Invalid argument (22)

原因:

權限無法複製。去掉同步權限的參數即可。(這種情況多見於Linux向Windows的時候)

 


 

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