名稱 |
角色 |
IP地址 |
Windows server 2003 |
伺服器 |
Eth0:192.168.1.1 |
RHEL5.5 |
用戶端 |
Eth0:192.168.1.2 |
一、cwRsyncServer服務端配置下載服務端cwRsyncServer解壓cwRsyncServer_4.0.3_Installer.zip,雙擊cwRsyncServer_4.0.3_Installer.exe
我的電腦—右鍵管理---服務和應用—服務找到RsyncSever,雙擊—啟動
提供案頭互動
開啟E盤,建立要備份的檔案夾,此處取名為benet(此處是檔案夾,不是檔案)按右鍵benet檔案夾,選擇屬性,切換到安全選項,點添加輸入:SvcCWRSYNC
開啟C:\Program Files\ICW目錄用記事本開啟rsyncd.conf,修改添加以下內容(修改之前先備份,以防出錯重改)
編輯rsyncd.conf檔案use chroot = falsestrict modes = falsehosts allow = *log file = rsyncd.log # Module definitions# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work#
[benet] #備份模版path = /cygdrive/e/benetread only = true #用戶端唯讀hosts allow = 192.168.1.2 #允許串連IP,多個IP中間用英文狀態下逗號隔,不限制IP填寫 *即可auth users = benet #允許串連的使用者名稱secrets file = etc/rsyncd.secrets #存放使用者名稱密碼的認證檔案路徑
在C:\Program Files\ICW目錄下面建立/etc/rsyncd.secrets檔案用記事本開啟,輸入使用者名稱和密碼benet:123
二、Rsync用戶端配置1、查看selinux機制,關閉selinux[root@localhost ~]# getenforceDisabled2、開啟防護牆tcp 873連接埠,以便日後改為伺服器使用[root@localhost ~]# vi /etc/sysconfig/iptables #編輯防火牆設定檔-A INPUT -m state –state NEW -m tcp -p tcp –dport 873 -j ACCEPT
3、安裝Rsync用戶端軟體[root@localhost ~]# yum install rsync xinetd[root@localhost ~]# vi /etc/xinetd.d/rsync #編輯設定檔,設定開機啟動rsync ,Centos上的rsync使用xinetd啟用的將disable=yes,改為noservice rsync{ disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID}/etc/init.d/xinetd start #啟動
4、測試遠程一下測試一下是否可以正常通訊,安裝telnet[root@localhost ~]# telnet 192.168.1.1 873 #成功Trying 192.168.1.1...Connected to 192.168.1.1 (192.168.1.1).Escape character is '^]'.@RSYNCD: 30.0
同步資料為了輸入時不手動輸入密碼,我們在用戶端也建立一個和服務端一樣的密碼檔案(此檔案路徑和密碼要與伺服器端的一樣,用戶端不用寫名字)[root@localhost ~]# echo “123”> /etc/rsyncd.secrets #檔案名稱可以不一樣,但要在/etc下[root@localhost ~]# cat /etc/rsyncd.secrets123[root@localhost ~]# chmod 600 /etc/rsyncd.secrets
在用戶端同步資料注意:此處的密碼為cwRsyncServer服務端C:\Program Files\ICW\etc\rsyncd.secrets檔案配置的密碼[root@localhost ~]# rsync -avz --password-file=/etc/rsyncd.secrets benet@192.168.1.1::benet /opt/receiving file list ... done./11.txt sent 91 bytes received 192 bytes 51.45 bytes/sectotal size is 52 speedup is 0.18
5.實現自動同步資料,手動編寫一個小指令碼。冒號後面的為在伺服器端定義的模版[root@localhost ~]# vim rsync.sh#!/bin/bash/usr/bin/rsync -avz --password-file=/etc/rsyncd.secrets benet@192.168.1.1::benet /opt加入自動化備份[root@localhost ~]# chmod +x /root/rsync.sh[root@localhost ~]# crontab -e* * * * * /root/rsync.sh
附,rsync使用時的常見問題:
錯誤1: rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receiver=3.0.2]
解決:很大可能是伺服器端沒有開啟 rsync 服務。開啟服務。 或者開啟了防火牆指定的連接埠無法訪問。
錯誤2:@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:伺服器端同步處理目錄沒有許可權,cwrsync預設使用者是Svcwrsync。為同步目錄添加使用者Svcwrsync許可權。
錯誤3:@ERROR: failed to open lock file
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:伺服器端設定檔 rsyncd.conf中添加 lock file = rsyncd.lock 即可解決。
錯誤4:@ERROR: invalid uid nobody
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.2]
解決:在rsyncd.conf檔案中添加下面兩行即可解決問題
UID = 0
GID = 0
錯誤5:@ERROR: auth failed on module test2
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=3.0.2]
解決:服務端沒有指定正確的secrets file,請在 [test2]配置段添加如下配置行:
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼檔案
錯誤6:password file must not be other-accessible
解決:用戶端的pass檔案要求許可權為600, chmod 600 /etc/rsync.pass 即可。