rsync服務器配置

 

 

rsync工具簡介

     
    rysnc是一個數據鏡像及備份工具,具有可使本地和遠程兩臺主機的文件,目錄之間,快速同步鏡像,遠程數據備份等功能。在同步過程中,rsync是根據自己獨特的算法,只同步有變化的文件,甚至在一個文件裏只同步有變化的部分,所以可以實現快速的同步數據的功能。
 
 
兩臺機器都需要安裝軟件包,這裏不羅嗦了。
rysnc一般是通過xinetd進行啓動的。
修改/etc/xinetd.d/rsync,只修改一個地方
# default: off
# description: The rsync server is a good addition to am ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
        disable = yes  修改爲disable = no
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
 
加入rc.local
編輯/etc/rc.d/rc.local,在最後添加:
/usr/local/bin/rsync –daemon
 
接下來編輯配置文件,手動創建rsyncd.conf
uid = nobody  
gid = nobody 
use chroot = no     #最好不使用chroot
max connections = 9  #最大連接數
list = yes   #允許列出文件清單
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
hosts allow  = 192.168.0.2   #只允許這個主機訪問
 
[html]     #發佈項
path = /var/www/html/    #發佈的路徑
ignore errors
read only = yes   #只讀
auth users = backup  #認證用戶爲root
secrets file = /etc/sery.pass    #密碼文件
下面是密碼文件
cat /etc/sery.pass
backup:123456
權限爲600
首次啓動rsync
rsync –daemon –config=/etc/rsyncd.conf
如果提示
failed to create pid file /var/run/rsyncd.pid: File exists
使用指令
rm -rf /var/run/rsyncd.pid
重啓已經在運行的rsync
ps -ef | grep rsync
root     27284     1  0 10:26 ?        00:00:00 rsync –daemon –config=/etc/rsyncd.conf
root     30516 29986  0 18:35 pts/3    00:00:00 grep rsync
kill -9 27284
rsync –daemon –config=/etc/rsyncd.conf
 
服務器端配置完成,客戶端只需要安裝rsync包即可
接下來創建密碼文件
[root@mailsvr ~] # cat /etc/sery.pass
123456        #這裏只需要輸入服務器端密碼文件中定義的密碼即可。
 設置權限爲只讀600
使用命令開始同步
rsync -vzrtopg –progress –delete –password-file=/etc/sery.pass [email protected]::html  /home/
 
rsync -aSvH --password-file=/etc/sery.pass [email protected]::data /home/
解釋:
--password-file=/etc/sery.pass  這段是密碼文件,如果不加這段,需要手動輸入服務器端定義好的密碼。
[email protected]::html 這裏的是服務器端的發佈項。
如果文件比較大,可以使用nohup將進城放在後臺執行,加上&
上面的表示將遠程機器192.168.0.2機器上發佈的html目錄,同步到本地機器的/home/目錄下。
 
 
 
 
解決錯誤
用戶密碼錯誤

@ERROR: auth failed on module ***
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]
檢查服務器端存儲密碼文件和客服端密碼文件。
  • 服務器密碼文件 /etc/rsyncd.secrets 格式爲: username:password
  • 客服端密碼文件 password.rsync 格式爲:password
文件權限錯誤
password file must not be other-accessible
continuing without password file

 
檢查服務器存儲密碼文件和客服端密碼文件。
  • 服務器密碼文件 /etc/rsyncd.secrets 權限爲600: chmod 600
  • 客服端密碼文件 password.rsync 權限爲600:chmod 600
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章