CentOS 5.5 安裝rsync服務

來源:互聯網
上載者:User

公司要做團購項目,發布了一個團購網站,我使用CentOS 5.5系統,基於LNMP配置的環境。考慮要同步伺服器上的資料,於是便想到了Rsync服務。以前一直在使用Cwrsync,是Windows環境的。第一次在Linux系統下配置該服務,原本認為很簡單,在實際操作過程中發現了若干問題,鬱悶了幾天,最終完全配置成功。整理如下。
 
伺服器端的配置
下面為安裝步驟:
一、伺服器端配置:
1、安裝xinetd,並修改rsync相關配置
# yum -y install xinetd
# vi /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
}
將disable = yes改成disable = no
然後重啟xinetd
# /etc/init.d/xinetd restart
[
  註:如果伺服器上裝有防火牆,需要開啟連接埠,預設連接埠是873
  # telnet 127.0.0.1 873
  Trying 127.0.0.1...
  telnet: connect to address 127.0.0.1: Connection refused
  # iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 873 -j ACCEPT
  # iptables -A INPUT -p tcp -m tcp --dport 873 -j DROP
]
 
2、編寫rsync.conf設定檔
# vi /etc/rsyncd.conf
內容如下:
port=873
uid = nobody
gid = nobody
user chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
 
[backup]
path = /home/www
ignore errors
read only = no
list = no
#hosts allow = 192.168.1.0/255.255.255.0
auth users = root
secrets file = /etc/rsyncd.secrets
 
注釋:
port  #開放連接埠
uid = nobody  #進行備份的使用者UID,nobody為任何使用者
gid = nobody  #進行備份的組GID,nobody為任意組
use chroot = no  #如果"use chroot"指定為true,那麼rsync在傳輸檔案以前首先chroot到path參數所指定的目錄下。這樣做的原因是實現額外的安全防護,但是缺點是需要以root許可權,並且不能備份指向外部的符號串連所指向的目錄檔案。預設情況下chroot值為true。但是這個一般不需要,所以我選擇no或false
list = no  #不允許列清單
max connections = 200 #最大串連數
timeout = 600 #覆蓋客戶指定的IP逾時時間,也就是說rsync伺服器不會永遠等待一個崩潰的用戶端。
pidfile = /var/run/rsyncd.pid  #pid檔案的存放位置
lock file = /var/run/rsync.lock  #鎖檔案的存放位置
log file = /var/log/rsyncd.log  #記錄檔的存放位置
 
[backup]  #這裡是認證模組名,即跟samba文法一樣,是對外公布的名字
path = /home/www  #這裡是參與同步的目錄
ignore errors  #可以忽略一些無關的IO錯誤
read only = no  #允許可讀可寫
list = no  #不允許列清單
hosts allow = 192.168.1.0/255.255.255.0  #這裡跟samba的文法是一樣的,只允許192.168.1.0/24的網段進行同步,拒絕其它一切IP
auth users = admin  #認證的使用者名稱
secrets file = /etc/rsyncd.secrets  #密碼檔案存放地址
 
注意:對於這個地方的設定檔,雖然解釋的很清楚,可是一些朋友始終還會在這裡出錯,這裡我提亮點易錯點:
[backup]是認證模組名和 path = /var/www 是參與同步的目錄
這裡的path 大家要記好了,這裡不要隨便的一設定就直接完事,要知道這裡是認證模組的,以後從客戶機備份的資料會儲存在這裡。
 
3、編寫使用者密碼檔案
# vi /etc/rsyncd.secrets
root:1234789 #使用者名稱:密碼
 
4、給予唯讀許可權
# chown root:root /etc/rsyncd.secrets
# chmod 600 /etc/rsyncd.secrets
 
5、建立目錄並修改所有者
# mkdir /home/www/
# chown -R nobody:nobody /home/www
 
6、啟動服務
# rsync --daemon
 
7、加入開機自啟動
# echo "rsync --daemon" >> /etc/rc.local
 
二、Linux用戶端進行同步
1、用戶端預設好像已經裝了rsync,沒有的話裝下:
# yum -y install rsync
 
2、建立密碼檔案
# vi /etc/rsyncd.passwd
檔案內容如下(只包含密碼部分):
123456789
 
3、執行非同步同步操作:
# /usr/bin/rsync -avz --progress --password-file=/etc/rsyncd.passwd root@192.168.1.1::backup /home/www
本文出自 “夢開始的地方” 部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.