Linux下使用rsync實現資料在不同伺服器之前增量自動備份

來源:互聯網
上載者:User

 A伺服器(伺服器一)ip:192.168.0.108

 B伺服器(伺服器二)ip:192.168.0.109

伺服器一的配置
1)編輯/etc/rsyncd.conf檔案,rsync的主要設定檔:
 #[globale]
 strict modes= yes
 #check passwd file
 port= 873
 #rsync工具預設使用的連接埠
 #default port
 logfile= /var/log/rsyncd.log #記錄檔存放路徑
 pidfile= /var/run/rsyncd.pid #記錄rsync運行時的進程ID
 max connections= 4 #同步最大的連結數
 #[modules] #同步模組的配置
 [appName] uid= root #該選項指定當該模組傳輸檔案時守護進程應該具有的uid
 gid= root #該選項指定當該模組傳輸檔案時守護進程應該具有的gid
 ignore errors #忽略一些無關的錯誤資訊
 #要備份的目錄
 path= /turbomail/accounts #需要同步的目錄
 read only= no #是否設定以唯讀方式運行
 host allow= 192.168.0.109  #同步資料的用戶端ip如有多個用戶端,以“,”隔開即可
 auth users= root  #同步用的使用者名稱
 secrets file= /etc/rsyncd.scrt #同步的密碼認證檔案

2)編輯/etc/rsyncd.scrt檔案,密碼認證檔案
 root:123456
更改許可權為600:chmod 600 /etc/rsyncd.scrt

3)運行rsync --daemon,並在/etc/rc.d/rc.local加入此語句,開機自動啟動。
 備忘:rsync預設連接埠873,若安裝了iptables,如需改動啟動時啟動rsync –port 873,請在iptables 中開放該連接埠,語句如下:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
若873連接埠沒有開放,會報一下異常:
rsync: failed to connect to X.X.X.X: No route to host (113) 
rsync error: error in socket IO (code 10) at clientserver.c(107) [sender=2.6.8]

 4)編輯/etc/xinetd.d/rsync
 rsync服務的監聽由xinet來統一分配:
 service rsync {
 disable = no #將此項改為no
 socket_type = stream
 wait = no
 user = root
 server = /usr/bin/rsync
 server_args = --daemon
 log_on_failure += USERID
 }
 重啟xinetd以啟動rsync服務
 service xinetd restart

 5)查看rsync事故正常運行 輸入命令:netstat –ant | grep :873若有顯示以下一條語句,則說明rsync服務已經正常啟動了。
 tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN

伺服器二的配置:  

1)編輯/etc/rsyncd.scrt檔案,密碼認證檔案
 root:123456
 更改許可權為600:chmod 600 /etc/rsyncd.scrt

 2)編輯指令碼vi /root/scrpit/rsync.sh並加入開機自動啟動。
 #!/bin/sh
/usr/bin/rsync -vazu --progress  root@192.168.0.108::appName  /oracle/app_backup/appName  -password-file=/etc/rsyncd.scrt
 修改許可權:chmod u+x /root/scrpit/rsync.sh
說明:root@192.168.7.108::appName    appName是伺服器一種配置的模組名

 3)定義為每天淩晨執行一次資料同步。
 crontab -e 加入
 0 0 * * * root /root/scrpit/rsync.sh start

 用戶端的配置到此就可以了,伺服器與用戶端的資料也會每天淩晨執行一次。

異常:

@ERROR: chdir failedrsync error: error starting client-server protocol (code 5) at main.c(1296) [sender=2.6.8]原因及解決方案:1、備份路徑未建立正確,建立後,同步成功。2、setsebool -P rsync_disable_trans on

@ERROR: auth failed on module appNamersync error: error starting client-server protocol (code 5) at main.c(1296) [sender=2.6.8]原因:     rsyncd裡面配置passwd是          username:password 這樣的格式     用戶端使用的時候,不能用這種格式,檔案裡面只能有password解決方案:    1. 檔案內容修改    2. rsync -av --password-file <(echo PASSWORD) src dest

@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
原因:
     伺服器一中的目錄不存在或者許可權不足,如果是用root進行備份的,一般是目錄不存在。


說明:有關rsyncd的使用參考 http://os.51cto.com/art/201009/225962.htm


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.