1.1 安裝
yum install xinetd
yum install rsync
1.2 配置文件
1.2.1 服務(wù)端主機(jī)配置
/etc/rsyncd.conf
motd file = /etc/rsyncd.motd #設(shè)置服務(wù)器信息提示文件星虹,在該文件中編寫提示信息
transfer logging = yes #開啟rsync數(shù)據(jù)傳輸日志功能
log file = /var/log/rsyncd.log #設(shè)置日志文件名停做,可通過log format參數(shù)設(shè)置日志格式
pid file = /var/run/rsyncd.log #設(shè)置rsync進(jìn)程號(hào)保存文件名稱
lock file = /var/run/rsync.lock #設(shè)置鎖文件名稱
uid = nobody #設(shè)置進(jìn)行數(shù)據(jù)傳輸時(shí)所使用的帳戶名或ID號(hào)涉兽,默認(rèn)使用nobody
gid = nobody #設(shè)置進(jìn)行數(shù)據(jù)傳輸時(shí)所使用的組名或GID號(hào)播瞳,默認(rèn)使用nobody
#若為yes, rsync會(huì)首先進(jìn)行chroot設(shè)置要拂,將根映射在下面的path參數(shù)路徑下堰氓,對(duì)客戶端而言渠概,系統(tǒng)的根就是path參數(shù)指定的路徑。但這樣做需要root權(quán)限舶替,并且在同步符號(hào)連接資料時(shí)只會(huì)同步名稱令境,不會(huì)同步內(nèi)容杠园。
use chroot = no
read only = yes #是否允許客戶端上傳數(shù)據(jù)顾瞪,yes表示不允許
max connections = 200 #設(shè)置并發(fā)連接數(shù),0表示無限制
[common] #自定義模塊名抛蚁,rsync通過模塊定義同步的目錄陈醒,可定義多個(gè)
comment = web content #定義注釋說明字串
path = /common #同步目錄的真是路徑通過path指定
ignore errors #忽略一些IO錯(cuò)誤
#exclude = test/ #exclude指定common目錄下某個(gè)目錄可以不同步數(shù)據(jù)
auth users = tom, jerry #設(shè)置允許連接服務(wù)器的賬戶,此賬戶可以是系統(tǒng)中不存在的用戶
secrets file = /etc/rsyncd.secrets #密碼驗(yàn)證文件名瞧甩,該文件權(quán)限要求為只讀钉跷,建議為600,僅在設(shè)置auth users后有效
hosts allow = 192.168.0.0/255.255.255.0 #設(shè)置哪些主機(jī)可以同步數(shù)據(jù)肚逸,多ip和網(wǎng)段之間使用空格分隔
hosts deny=* #除了hosts allow定義的主機(jī)外爷辙,拒絕其他所有
list = false #客戶端請(qǐng)求顯示模塊列表時(shí)彬坏,本模塊名稱是否顯示,默認(rèn)為true
/etc/rsyncd.secrets
tom:123
jerry:123
chmod 600 /etc/rsyncd.secrets
/etc/rsyncd.motd
Welcom to rsync
/etc/xinetd.d/rsync中disable改為no
檢驗(yàn)命令
netstat -tunlp | grep 873
1.2.2 客戶端主機(jī)配置
/etc/rsyncd.secrets
tom:123
jerry:123
chmod 600 /etc/rsyncd.secrets
1.3 啟動(dòng)
1.3.1 服務(wù)端啟動(dòng)
service xinetd restart
pkill rsync
rsync --daemon
echo "/usr/bin/rsync --daemon" >> /etc/rc.local #開機(jī)啟動(dòng)rsync服務(wù)
1.4 使用
1.4.1 示例
rsync -t *.c 192.168.0.54:src/ #將本機(jī)當(dāng)前目錄下的以.c結(jié)尾的文件賦值到192.168.0.54的src目錄下
rsync -avz 192.168.0.54:src/bar /data/tmp #從192.168.0.54主機(jī)上將src/bar目錄以遞歸方式復(fù)制到本機(jī)/data/tmp目錄
rsync -avz 192.168.0.54:src/bar/ /data/tmp #和例子2的區(qū)別是不在/data/tmp目錄下創(chuàng)建bar目錄
rsync -avz /src/foo /dest #將本機(jī)/src/foo目錄復(fù)制到/dest目錄
rsync -avz tom@192.168.0.230::common /test3 #使用tom賬戶連接遠(yuǎn)程192.168.0.230主機(jī)的rsync進(jìn)程膝晾,將common模塊定義的path路徑下載到本地test3目錄
rsync -avz 192.168.0.230::common /test3 #匿名下載192.168.0.230服務(wù)器的common模塊至本地的/test3目錄
rsync --list-only tom@192.168.0.254:: #顯示192.168.0.254服務(wù)器所有的模塊名稱栓始,需要服務(wù)器端配置list=true才會(huì)顯示
# 客戶端每次連接服務(wù)器都需要輸入密碼很麻煩,可以創(chuàng)建密碼文件rsync.pass血当,在其中包含密碼幻赚,然后使用--password-file指定此文件
echo "123" > rsync.pass #服務(wù)器端用戶tom的密碼
rsync -avz --delete --password-file=rsync.pass tom@192.168.0.254::common /dest