如何保持Linux伺服器間的檔案同步

tonykorn97發表於2008-04-02

具體操作步驟:

配置/etc/rsyncd.conf檔案:


uid = nobody
gid = nobody
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log

[test01]
path = /front/test01
ignore errors
read only = true
list = false
hosts allow = 192.168.1.252
hosts deny = 192.168.1.0/24
auth users = test01
secrets file = /etc/rsync.secret

[back]
path = /front/back
ignore errors
read only = true
list = false
hosts allow = 192.168.1.252
hosts deny = 192.168.1.0/24

配置test01目錄需要密碼,back使用者不需要
建立密碼檔案
[root@tonykorn front]# cat /etc/rsync.secret
test01:test01
[root@tonykorn front]#

修改啟動rsync檔案
[root@tonykorn etc]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it
# allows crc checksumming etc.
service rsync
{
# disable = yes
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@tonykorn etc]#

啟動服務端
[root@tonykorn front]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@tonykorn front]#

也有的地方說需要執行:rsync --daemon,經過試驗不需要
沒有執行rsync --daemon的時候程式狀態是:
[root@tonykorn front]# ps -ef | grep rsync
root 24033 15043 0 17:40 pts/0 00:00:00 grep rsync

執行後為:
[root@tonykorn front]# rsync --daemon
[root@tonykorn front]# ps -ef | grep rsync
root 24035 1 0 17:40 ? 00:00:00 rsync --daemon
root 24042 15043 0 17:40 pts/0 00:00:00 grep rsync
[root@tonykorn front]#

客戶端操作
客戶端同步出錯:
[test01@tonykorn02 ~]$ rsync -vzrtopg --progress test01@192.168.1.250::test01 /front/test01
Password:
@ERROR: auth failed on module test01
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=2.6.8]
[test01@tonykorn02 ~]$
原因:
secret file的檔案屬性有問題,該檔案屬性要是600的
[root@tonykorn etc]# ls -al rsync.secret
-rw-r--r-- 1 root root 14 Apr 2 17:04 rsync.secret
[root@tonykorn etc]# chmod 600 rsync.secret
[root@tonykorn etc]#

此時執行,test01需要密碼,輸入密碼後可以,back不需要密碼,直接可以同步
[root@tonykorn02 front]# rsync -vzrtopg --progress test01@192.168.1.250::test01 /front/test01
Password:
receiving file list ...
421 files to consider

sent 98 bytes received 8031 bytes 2322.57 bytes/sec
total size is 134589856 speedup is 16556.75
[root@tonykorn02 front]# rsync -vzrtopg --progress back@192.168.1.250::back /front/back
receiving file list ...
50 files to consider

sent 62 bytes received 1007 bytes 2138.00 bytes/sec
total size is 12629876 speedup is 11814.66
[root@tonykorn02 front]#

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-245849/,如需轉載,請註明出處,否則將追究法律責任。

相關文章