您好,登錄后才能下訂單哦!
這2天一直忙其它的事,忘記把剩余的同步過程分享到博客中,望諒解!上周把rsync已經配置完成,可以手動的同步,下面我們將使用Serync進行實時的同步,其實就手動同步而言也可以配置crontab定時備份,因人而異方法很多,選一種適合你自己的。
三、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,規范 sersync 目錄結構(自行抉擇是否規范)
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,更改及優化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守護進程同步數據(全局變量)
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 工作線程數 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 32最大線程數 = 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,#####測試結果:發現一個問題,僅能同步一個模塊目錄 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個目錄#####
創建2個文件
cp confxml.xml confxml.xml_new cp confxml.xml cfgs_confxml.xml cp confxml.xml objects_confxml.xml
規范目錄看著舒服多了
[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,配置文件內容刪除多余節點目錄 修改日志報錯名稱 如下是比對結果
[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運行狀態
[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個配置文件,各自指定各自的配置文件(配置要求高些,進程數隨之調整)
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。