まず、なぜrsyncを+ sersyncアーキテクチャを使うのか?
1、sersyncはinotifyの開発に基づいており、のinotify-toolsの同様のツール
2、sersyncは、ファイルやディレクトリを記録することができますが、ファイルやディレクトリの特定の名前(変更、削除、追加)ディレクトリを聞くように変更して、時刻を同期するためにrsyncを使用して、唯一の同期変更されます
二、のinotify-toolsとのrsync + sersyncアーキテクチャのrsync +の違いは?
1、rsyncの+のinotify-ツール
、inotifyのディレクトリは、特定のファイルまたはディレクトリレコードの変更されていない(、削除、変更を加える)のみモニターの変更に記録されています。
大量のデータ、全体のディレクトリ同期は非常に時間がかかり、B、時間のrsyncの同期、どの特定のファイルやディレクトリの変更を知らない、毎回全体のディレクトリ同期(rsyncのディレクトリ全体へ)参照文書を横断検索し、そのため非効率的
2、rsyncを+ sersync
、sersyncは(変更、削除、追加)ディレクトリを監視されているファイルやディレクトリの変更の具体的な名前を記録することができます。
同期B、rsyncのファイルまたはディレクトリ、同期変更のみ(場合rsyncのファイル検索コントラストを横断する、非常に高速なカタログデータの全体の同期に対応する各時間データが、十分に小さい変化)、従って、高効率。
要約:
データディレクトリ同期の場合は少量の、rsyncの+のinotifyを使用することをお勧めします
大量のデータ(G 1Tの何百ものよりもさらに)の場合は、ディレクトリ同期ファイルの多くは、rsyncの+ sersyncを使用することをお勧めします
#Rsyncサーバの設定
1. 展開のrsync サービス
yumをrsyncの#はrsyncのインストールインストールし、彼らはyumのバージョンが低すぎると思われる場合、ソースコードをインストールすることができます
2.vim /etc/rsyncd.conf#デフォルトのrsync 何の設定ファイルません、でファイルを作成#文字だけのコメントを、すべての注釈を消去を使用してください
サーバー#Rsync |
3 、ユーザ認証ファイルを作成します
"rsync_backup:123456" エコー>の/ etc / rsync.password#設定ファイルは、次のように追加します |
4 、設定ファイルのパーミッション
chmodの600 /etc/rsync.password
5. デーモンを起動し、スタートからの起動を書き込み、
rsyncの--daemon |
6. 同期する関連するディレクトリを作成します。
MKDIR -p /データ/ {WWW、掲示板、ブログ}
#rsyncクライアントの構成
1. インストールrsyncを上記のように、
2. 作成したrsyncの設定ファイルを、クライアントはコンテンツなしで作成することができます
タッチ/etc/rsyncd.conf
3. 設定rsyncのクライアントのアクセス許可の証明:
"123456">の/ etc / rsync.passwordエコー
のchmod 600 /etc/rsync.password
4. 同期するクライアント上でいくつかのデータを作成するために、データを作成します。
MKDIR -p /データ/ {WWW、掲示板、ブログ}
タッチ/data/www/www.log /data/bbs/bbs.log /data/blog/blog.log
5. 試験のrsyncが同期されます
rsyncの-avzP /データ/ www /の[email protected] :: WWW --password-ファイル=は/ etc / rsync.password |
#このステップは、次のステップに成功しなければなりません
6. sersyncの展開サービスを
tar fxz sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
cd /usr/local/
mv GNU-Linux-x86 sersync
7.配置sersync
cp sersync/confxml.xml sersync/confxml.xml-bak
vim sersync/confxml.xml
修改24--28行
|
8.开启sersync守护进程同步数据
/usr/local/sersync/bin/sersync -d -r -o /usr/local/sersync/conf/confxml.xml
配置sersync环境变量
echo"PATH=$PATH:/usr/local/sersync/">>/etc/profile
source /etc/profil
启动命令后返回结果如下为正常:**
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: ./confxml.xml
daemon thread num: 10
parse xml config file
XML Parsing error inside file './confxml.xml'.
Error: File not found
At line 0, column 0.
同步测试
[root@panwenbin1-sa GNU-Linux-x86]# ./sersync2 -d -r -o ./confxml-www.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: ./confxml-www.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data/www && rsync -artuz -R --delete ./ --timeout=100 [email protected]::www --password-file=/etc/rsync.password >/dev/null 2>&1
run the sersync:
watch path is: /data/www
9.多实例情况
1、配置多个confxml.xml文件(比如:www、bbs、blog....等等)
confxml-bbs.xml confxml-blog.xml confxml-www.xml(按照单个实例配置即可)
2、根据不同的需求同步对应的实例文件
rsync -avzP /data/www/ [email protected]::www/ --password-file=/etc/rsync.password
rsync -avzP /data/bbs/ [email protected]::bbs/ --password-file=/etc/rsync.password
rsync -avzP /data/test/ [email protected]::blog/ --password-file=/etc/rsync.passwor
分别启动即可
rsync缺点:
1.大量小文件同步时,比对时间长,有时候rsync进程会停止
2.同步大文件,10G这样的大文件有时也会有问题,会中断。未完整同步之前是隐藏文件,可通过参数续传
sersync的参数信息
参数-d:启用守护进程模式 参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍 c参数-n: 指定开启守护线程的数量,默认为10个 参数-o:指定配置文件,默认使用confxml.xml文件 参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块 参数-m:单独启用其他模块,使用 -m socket 开启socket模块 参数-m:单独启用其他模块,使用 -m http 开启http模块 不加-m参数,则默认执行同步程序