環境:CentOS 5.2 (兩台)
rsync伺服器IP:192.168.1.114
用戶端IP:192.168.1.115
1、安裝rsync,並通過xinetd管理rsync
yum install rsync xinetd
2、修改/etc/xinetd.d/rsync檔案,使其隨xinetd啟動而啟動
vim /etc/xinetd.d/rsync
將disable = yes 修改為 disable = no
3、防火牆設定(rsync預設連接埠 837)
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
Service iptables restart
4.建立rsync需要的檔案
mkdir /etc/rsyncd
touch /etc/rsyncd/rsyncd.conf (主設定檔)
touch /etc/rsyncd/secrets (驗證使用者和密碼存放地)
touch /etc/rsyncd/rsyncd.motd (伺服器描述資訊)
ln /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf (建立連結)
chmod 600 /etc/rsyncd.secrets (給該檔案設定許可權) 必須的
chown root:root /etc/rsyncd.secrets (給該檔案設定所屬使用者和組)
5.修改主設定檔
vi /etc/rsyncd/rsyncd.conf
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid (告訴進程寫到該檔案中)
port = 873 (指定服務連接埠)
address = 192.168.1.114 (設定伺服器IP地址)
uid = root (伺服器傳輸檔案時用root 許可權執行)
gid = root
use chroot = yes
read only = yes (唯讀,不讓用戶端上傳檔案到伺服器)
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 (限制能訪問該服務的網段)
hosts deny=*
max connections = 5 (最大串連數)
motd file = /etc/rsyncd/rsyncd.motd (伺服器資訊定義指向該檔案,該檔案可寫伺服器資訊)
This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b (記錄檔格式)
syslog facility = local3
timeout = 300 (逾時時間)
[backup] (連結名)
path = /home (連結名指向的路徑)
list=yes (伺服器上同步資料的目錄在伺服器模組上列出來)
ignore errors (忽略IO錯誤)
auth users = cs (驗證使用者,我的使用者是cs)
secrets file = /etc/rsyncd/rsyncd.secrets (指向驗證使用者存放檔案)
6.修改rsyncd.secrets 和rsyncd.motd 檔案
vi /etc/rsyncd/rsyncd.secrets
cs:123456 (cs就存在的系統使用者,但密碼最好設為跟系統密碼不一樣)
vi /etc/rsyncd/rsyncd.motd
++++++++++++++++++++++++++++++++
Welcome
++++++++++++++++++++++++++++++++
7.重啟服務
service xinetd restart
用戶端同步測試(用戶端要安裝rsync)
rsync –avzP cs@192.168.1.114::backup /var/local
意思就是用cs使用者登入伺服器,將backup指定的目錄資料儲存到我本地/var/local
測試並不是一帆風順,遇到些問題,可看參考連結。
客戶機完全同步伺服器 touch rsync.password (建立一個存放密碼的檔案) chmod 600 rsync.password echo "123456"> rsync.password (寫入密碼) rsync -avzP --delete --password-file=rsync.password cs@192.168.1.114::backup /var/local