標籤:伺服器即時同步檔案
服務鏡像解決方案 lsyncd機緣巧合,聽群裡的兄弟提到了lsyncd這個軟體,於是google了一把,發現竟然是google開源項目組的一個開源軟體(相關連結http://code.google.com/p/lsyncd/)。
眼神大致一掃,立馬下載了一個進行體驗:
搭建lsyncd需要核心版本在2.6.13以上,因為它需要一個inotify的核心,這個核心的作用就是可以即時提供系統檔案變化的資訊,供 lsyncd來進行同步檔案操作。關於inotify這個東東,我下個檔案會詳細介紹測試環境:
伺服器端:192.168.1.241
兩個結點:192.168.1.40 192.168.1.239
作業系統:centos5.4 x86_64
需要兩個軟體包,rsync和lsyncdwget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz1.在每個結點伺服器上安裝rsync
tar -zxvf rsync-3.0.7.tar.gz
cd tar -zxvf rsync-3.0.7
./configure
make
make install2.在主伺服器上安裝lsyncd
主伺服器為同步資料的原始伺服器,從伺服器不需要安裝lsyncd,只啟動rsyncd進程即可tar -zxvf lsyncd-1.26.tar.gz
cd lsyncd-1.26
./configure
make
make install3. 配置從伺服器的rsync守護進程(內容如下:)
vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[data]
path = /data
hosts allow = 192.168.1.241 #這是主伺服器的ip地址
ignore errors
read only = no儲存退出後啟動daemon進程。
# rsync --daemon
PS: 我們一般使用rsync都是把啟動守護進程的作為主伺服器,然後從伺服器來同步主伺服器的資料,也就是同步rsyncd.conf中tag路徑下的資料,而這次剛好相反,我們需要把lsyncd伺服器的資料同步至rsync伺服器的tag目錄。4. 配置主伺服器lsyncd服務
首先編輯設定檔
# cp lsyncd.conf.xml /etc/
# vi /etc/lsyncd.conf.xml
<lsyncd version="1">
<settings>
<logfile filename="/var/log/lsyncd.log"/>
<binary filename="/usr/local/bin/rsync"/>
<pidfile filename="/var/run/lsyncd.pid"/>
<callopts>
<option text="-avz"/> \\這裡填寫rsync的參數
<option text="--delete"/>
<option text="--force"/>
<exclude-file/>
<source/>
<destination/>
</callopts>
</settings>
<directory>
<source path="/opt/www/"/> \\源路徑
<target path="192.168.1.239::data"/> \\目的路徑
</directory>
</lsyncd>儲存退出。
啟動服務:
# /usr/local/bin/lsyncd --conf /etc/lsyncd.conf.xml