(後面列一下我們用的sersync,使用sersync 大概628G 大小不一的圖片文件及文件夾,15個同步工作組線程,同步了13個小時,io 大概13到15 MB/s,大概1G一分鐘。剛開始10個同步工作組線程,速度很慢,增加了5個同步工作組線程,速度快了一倍,所以如果是20個工作組線程7個小時應該能同步完)
原文鏈接 http://wenku.baidu.com/link?url=33U36GbrgvXv9__m2E5PKPDHKGvdtt2RL7V6t5bPvpETurxyt2iJ1X4I1fuE-rh59ls00ojGDnSFy_cBWYc-P5W1l2eYCHy5TNlUF6xqhk3 (居然在百度找到一個靠譜的文章,很意外)
1. 先關閉2臺機器的防火牆: /etc/init.d/iptables stop
2臺機器安裝rsync軟件包:
有兩種 安裝方式 第一種 yum 安裝 yum install rsync -y 安裝好直接啓動
第二種 從原始網站下載源碼安裝:http://rsync.samba.org/ftp/rsync/
[root@localhost bin]#./configure[root@localhost bin]#make
[root@localhost bin]#make install
2. 服務器端操作
rsync安裝時沒有提供一個配置文件模板,需要自己手動創建,名稱爲rsyncd.conf。
配置文件文件分爲兩部分,全局參數和模塊參數。
A.服務器端機器新建文件:vi /etc/rsyncd.conf
添加以下內容
#[global]全局配置
uid = root
gid = root
max connections = 15
transfer logging = true
log format = %h %o %f %l %b
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock slp
refresh = 300
#客戶端連接模塊配置
[rsynczgp]
path = /rsyncdir
comment = zgprsync
read only = no
auth users = root
secrets file = /etc/rsync.ser.pass
# rsynczgp 是客戶機鏈接的模塊名稱,你可以配置多個模塊鏈接到不同客戶端
#path 要把文件同步到服務端哪個目錄上 #/etc/rsync.ser.pass
客戶機鏈接的賬號密碼
B.創建服務端文件夾:mkdir /rsyncdir
C.新建文件vi /etc/rsync.ser.pass添加以下內容,
是客戶機鏈接的賬號密碼格式:用戶名:密碼
例如:root:zgp66dashun
D.修改 權限 chmod 600 /etc/rsync.ser.pass
(不修改客戶端會報錯:@ERROR: auth failed on module rsynczgp rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6])
E.啓動服務器端程序 rsync --daemon
F.查看服務器端是否啓動成功
lsof -i:873
如下:
[root@localhost etc]# lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 25364 root 3u IPv4 55277 0t0 TCP *:rsync (LISTEN)
rsync 25364 root 5u IPv6 55278 0t0 TCP *:rsync (LISTEN)
至此,服務端配置完成。
##########################分隔符##########################
3. 以下是客戶機上操作配置
A、新建上傳下載目錄 : mkdir /rsyncud
B、在目錄下/ rsyncud 創建任意文件:touch 123456.txt
C、創建客戶端密碼保存文件vi /etc/rsync.client.pass添加內容格式: passwd (服務端爲root:passwd,客戶端僅需要passwd)文件內容要和服務器端的配置密碼一致,本例爲:zgp66dashun
D、更改密碼文件/etc/rsync.client.pass權限爲600 chmod 600 /etc/rsync.client.pass (不更改報錯: password file must not be other-accessible continuing without password file)
E、同步客戶端/rsyncud/下文件到 服務器端(IP:192.168.191.140)
rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/rsync.client.pass
如下:
[root@localhost rsyncud]# rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/rsync.client.pass
sending incremental file list
./
123456.txt
sent 13590 bytes received 30 bytes 27240.00 bytes/sec
total size is 68636 speedup is 5.04
F、從服務器端/rsyncdir目錄同步文件到客戶端的/rsyncud/目錄下:
rsync -avz --delete [email protected]::rsynczgp /rsyncud --password-file=/etc/rsync.client.pass
receiving incremental file list
./
123456.txt
sent 80 bytes received 13658 bytes 27476.00 bytes/sec
total size is 68636 speedup is 5.00
[root@localhost rsyncud]# ls /rsyncud/ 123456.txt
##########################分隔符##########################
4. 修改rsync配置後服務器端需要重啓:
Killall rsync
rsync –daemon
lsof –i:873 5.
客戶端寫腳本運行持續更新
vi /root/rsync.job
輸入 rsync -avz --delete /rsyncud/ [email protected]::rsynczgp --password-file=/etc/ rsync.client.pass
將腳本加入crontab crontab –e * * * * * /bin/sh /root/rsync.job