rsync配置和使用

rsync的優缺點就不一一說明;

首先配置比較簡單 分爲:server端和client端

配置server端:

centos可以通過yum install rsync安裝

默認是沒有/etc/rsyncd.conf和密碼文件 rsync.pas自行創建

1.配置配置文件創建

uid = root 權限
gid = root 組權限
use chroot = no
max connections = 10 最大連接數
strict modes = yes
port = 873
address = 192.168.0.1 server端ip

[test] 模塊名字

path = /data/test/  模塊路徑
comment = this is a test
ignore errors
read only = yes
list = no
auth users = root
secrets file = /etc/rsync.pas
hosts allow = x.x.x.x允許的ip
hosts deny = 0.0.0.0/0 禁止的ip
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

2.創建密碼文件

vi /etc/rsync.pas

留意:密碼文件建議客戶端和服務端都是設置權限600

root:test 格式:用戶:密碼

3.啓動rsync

/usr/bin/rsync --daemon --config=配置文件路徑不一定一樣

配置client端

創建密碼文件

vi /etc/rsync.pas

test  格式:只寫密碼


啓動同步命令

rsync -auzv --progress --password-file=/etc/rsync.pas root@server端ip::test /data/test



rsync自啓動

crontab -e 腳本 定時執行

常用錯誤:

底下內容來自網絡,如有錯誤可以自行調整

配置過程問題:
問題1:
在client上遇到問題:
rsync -auzv --progress --password-file=/etc/rsync.pas [email protected]::backup /home/
rsync: could not open password file "/etc/rsync.pas": No such file or directory (2)
Password: 
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]
遇到這個問題:client端沒有設置/etc/rsync.pas這個文件,而在使用rsync命令的時候,加了這個參數--
password-file=/etc/rsync.pas

問題2:
rsync -auzv --progress --password-file=/etc/rsync.pas [email protected]::backup /home/
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]
遇到這個問題:client端已經設置/etc/rsync.pas這個文件,裏面也設置了密碼111111,和服務器一致,但是
服務器段設置有錯誤,服務器端應該設置/etc/rsync.pas  ,裏面內容root:111111 ,這裏登陸名不可缺少

問題3:
rsync -auzv --progress --password-file=/etc/rsync.pas [email protected]::backup /home/
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]
遇到這個問題,是因爲服務器端的/home/backup  其中backup這個目錄並沒有設置,所以提示:chdir failed

問題4:
rsync: write failed on "/home/backup2010/wensong": No space left on device (28)
rsync error: error in file IO (code 11) at receiver.c(302) [receiver=3.0.7]
rsync: connection unexpectedly closed (2721 bytes received so far) [generator]
rsync error: error in rsync protocol data stream (code 12) at io.c(601) [generator=3.0.7]
磁盤空間不夠,所以無法操作。
可以通過df /home/backup2010 來查看可用空間和已用空間

問題5:網絡收集問題
1、權限問題
類似如下的提示:rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)注意查看同步的目錄權限是否爲755
2、time out
rsync: failed to connect to 203.100.192.66: Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
檢查服務器的端口netstat –tunlp,遠程telnet測試。
3、服務未啓動
rsync: failed to connect to 10.10.10.170: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
啓動服務:rsync --daemon --config=/etc/rsyncd.conf
4、磁盤空間滿
rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
5、Ctrl+C或者大量文件
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [receiver=3.0.5]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [generator=3.0.5]
6、xnetid啓動
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]
查看rsync日誌
rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory
xnetid查找的配置文件位置默認是/etc下,根據具體情況創建軟鏈接。例如:
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf
或者更改指定默認的配置文件路徑,在/etc/xinetd.d/rsync配置文件中



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