Centos+Serync+inotify實時同步數(shù)據(jù)文件(二)-創(chuàng)新互聯(lián)

這2天一直忙其它的事,忘記把剩余的同步過程分享到博客中,望諒解!上周把rsync已經配置完成,可以手動的同步,下面我們將使用Serync進行實時的同步,其實就手動同步而言也可以配置crontab定時備份,因人而異方法很多,選一種適合你自己的。

站在用戶的角度思考問題,與客戶深入溝通,找到長海網站設計與長海網站推廣的解決方案,憑借多年的經驗,讓設計與互聯(lián)網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網站建設、網站制作、企業(yè)官網、英文網站、手機端網站、網站推廣、域名申請、網頁空間、企業(yè)郵箱。業(yè)務覆蓋長海地區(qū)。

三、Serync Configuration

首先下載軟件

[root@nagios01 /]#cd /home/qiuyuetao/
[root@nagios01 qiuyuetao]# wget 
http://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

【http://code.google.com/p/sersync/】下載網站

1,安裝sersync

[root@nagios01 qiuyuetao]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/(-C 解壓到指定路徑)
[root@nagios01 qiuyuetao]# mv /usr/local/GNU-Linux-x86 sersync
[root@nagios01 local]# tree sersync/
sersync/
├── confxml.xml
└── sersync2

2,規(guī)范 sersync 目錄結構(自行抉擇是否規(guī)范)

 mkdir conf bin logs (配置文件放到conf、二進制命令Bin下、腳本logs下)
[root@nagios01 local]# cd sersync/
[root@nagios01 sersync]# mkdir conf bin logs
[root@nagios01 sersync]# mv confxml.xml conf/
[root@nagios01 sersync]# mv sersync2 bin/sersync
[root@nagios01 sersync]# tree 
.
├── bin
│   └── sersync
├── conf
│   └── confxml.xml
└── logs
3 directories, 2 files

3,編輯配置文件

備份 cp confxml.xml confxml.xmlq.$(date +%F)

4,更改及優(yōu)化sersync 配置

(1)定義本地的同步目錄
     24         <localpath watch="/opt/tongbu">要同步的目錄
     25             <remote ip="127.0.0.1" name="tongbu1"/>
     26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
                                   同步到哪臺機器       同步到那個模塊目錄
     27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
     28         </localpath>
修改后內容為:
 <sersync>
 <localpath watch="/usr/local/nagios/etc/cfgs">
                  <remote ip="192.168.1.206" name="cfgs"/>
             </localpath>
<!--###############################################################-->
   <localpath watch="/usr/local/nagios/etc/objects">
                  <remote ip="192.168.1.206" name="objects"/>
             </localpath>
<!--###############################################################-->
修改前
        <rsync>
     40             <commonParams params="-artuz"/>
     41             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
                         使用認證     
     42             <userDefinedPort start="false" port="874"/><!-- port=874 -->
     43             <timeout start="false" time="100"/><!-- timeout=100 -->
     44             <ssh start="false"/>
     45         </rsync>
修改后內容為:拼接同步命令
        <rsync>
                 <commonParams params="-artuz"/>
                  <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
                 <userDefinedPort start="false" port="874"/><!-- port=874 -->
                 <timeout start="true" time="100"/><!-- timeout=100 -->
                 <ssh start="false"/>
             </rsync>
修改36-37行 失敗后會寫入log
  <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
修改后內容
  <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins 
execute once-->

4,開啟sersync守護進程同步數(shù)據(jù)(全局變量)

 echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile
 tail -1 /etc/profile  (查看是否添加)
 source /etc/profile   (使/etc/Porofile 立即生效)
 which sersync         (查看sersync命令路徑能否找到)

5,《啟動同步命令》

sersync -r(先做一次同步) -d(后臺啟動) -o(指定文件) /usr/local/sersync/conf/confxml.xml

sersync -r -d -o /usr/local/sersync/conf/confxml.xml
[root@Server conf]# sersync -r -d -o /usr/local/sersync/conf/confxml.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: -r      rsync all the local files to the remote servers before the sersync work
option: -d      run as a daemon
option: -o      config xml name:  /usr/local/sersync/conf/confxml.xml
daemon thread num: 10 默認啟動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 工作線程數(shù) = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 
Max threads numbers is: 32大線程數(shù) = 12(Thread pool nums) + 20(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 /usr/local/nagios/etc/cfgs && rsync -artuz -R --delete ./  --timeout=100 
rsync_backup@192.168.1.206::cfgs --password-file=/etc/rsync.password >/dev/null 2>&1 
[root@nagios01 conf]# run the sersync: 
watch path is: /usr/local/nagios/etc/cfgs
成功

6,#####測試結果:發(fā)現(xiàn)一個問題,僅能同步一個模塊目錄 cfgs模塊 / objects 沒有同步

[root@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/1.txt /usr/local/nag
ios/etc/objects/1.txt
[root@nagios01 conf]# tree /usr/local/nagios/etc/
/usr/local/nagios/etc/
├── cfgs
│   ├── 1.txt
│   ├── cfgs.log
├── objects
│   ├── 1.txt
│   ├── objects.log
│ 
[root@Nagios02 /usr/local/nagios/etc]$tree 
├── cfgs
│   ├── 1.txt
│   ├── cfgs.log
├── objects
│   ├── objects.log

7,####如下是采用多實例的方法進行 同時同步2個目錄#####

創(chuàng)建2個文件

 cp confxml.xml confxml.xml_new
 cp confxml.xml cfgs_confxml.xml
 cp confxml.xml objects_confxml.xml

規(guī)范目錄看著舒服多了

[root@nagios01 conf]# ll
total 12
-rwxr-xr-x. 1 root root 2328 Feb 23 00:49 cfgs_confxml.xml
-rwxr-xr-x. 1 root root 2339 Feb 23 00:50 objects_confxml.xml
drwxr-xr-x. 2 root root 4096 Feb 23 00:51 tmp

8,配置文件內容刪除多余節(jié)點目錄 修改日志報錯名稱 如下是比對結果

[root@nagios01 conf]# diff cfgs_confxml.xml objects_confxml.xml 
23,24c23,24
<  <localpath watch="/usr/local/nagios/etc/cfgs">
<                   <remote ip="192.168.1.206" name="cfgs"/>
---
>    <localpath watch="/usr/local/nagios/etc/objects">
>                   <remote ip="192.168.1.206" name="objects"/>
34c34
< <failLog path="/usr/local/sersync/logs/cfgs_rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins 
execute once-->
---
> <failLog path="/usr/local/sersync/logs/objects_rsync_fail_log.sh" timeToExecute="60"/><!--default every 
60mins execute once-->

9,更新sersync運行狀態(tài)

[root@nagios01 conf]# ps -ef|grep sersync
root      6134     1  0 Feb22 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml.xml
root      7178  2428  0 00:55 pts/0    00:00:00 grep sersync
[root@nagios01 conf]# pkill sersync
[root@nagios01 conf]# ps -ef|grep sersync
root      7187  2428  0 00:56 pts/0    00:00:00 grep sersync

10,同時啟動2個配置文件,各自指定各自的配置文件(配置要求高些,進程數(shù)隨之調整)

sersync -r -d -o /usr/local/sersync/conf/cfgs_confxml.xml
sersync -r -d -o /usr/local/sersync/conf/objects_confxml.xml
[root@nagios01 conf]# ps -ef |grep sersync
root      7290     1  0 01:01 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/cfgs_confxml.xml
root      7308     1  0 01:01 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/objects_confxml.xml
root      7327  2428  0 01:01 pts/0    00:00:00 grep sersync

11,在做一下測試

[root@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/2.txt /usr/local/nagios/etc/objects/2.txt
[root@nagios01 conf]# tree /usr/local/nagios/etc/
/usr/local/nagios/etc/
├── cfgs
│   ├── 1.txt
│   ├── 2.txt
│   ├── cfgs.log
├── objects
│   ├── 1.txt
│   ├── 2.txt
│   ├── objects.log
│ 
[root@Nagios02 /usr/local/nagios/etc]$tree 
├── cfgs
│   ├── 1.txt
│   ├── 2.txt
│   ├── cfgs.log
├── objects
│   ├── 1.txt
│   ├── 2.txt
│   ├── objects.log

Sersync 多實例 實時同步配置成功,希望大家多多支持。http://qiuyt.blog.51cto.com

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網頁題目:Centos+Serync+inotify實時同步數(shù)據(jù)文件(二)-創(chuàng)新互聯(lián)
鏈接地址:http://muchs.cn/article12/dpppgc.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供移動網站建設、網頁設計公司、網站收錄、靜態(tài)網站、營銷型網站建設網站設計

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網站建設