sersync 和 rsync 的安裝測試

環境搭建:(接收端,推送端)


一.首先關閉selinux與iptables

# vi /etc/sysconfig/selinux

---------

SELINUX=disabled

---------

# setenforce 0

# service iptables stop


在使用sersync之前,我們必須安裝配置好rsync服務器


rsync (接收端)


一.安裝rsync(centos6.3默認已安裝)

# yum install rsync -y

# yum install xinetd -y


二.啓動rsync依賴服務

# /etc/init.d/xinetd start

# chkconfig xinetd on


三.配置:

# vi /etc/rsyncd.conf

--------------------

uid = root

gid = root

use chroot = no

max connections = 10

strict modes = yes

port = 873

address = 192.168.100.29


[data] # rsync模塊名,後面配置sersync會用到

path = /data  # 該同步目錄只要uid所指定的用戶有寫權限即可

comment = mirror for test

ignore errors

read only = no

list = no

auth users = user

secrets file = /etc/rsync.pas # 密碼認證文件,必須爲600權限,否則rsync傳輸會報錯

hosts allow = *

# hosts deny = 0.0.0.0/0

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

--------------------


四.創建同步目錄

# mkdir /data


五.配置認證文件

# echo "user:123456" > /etc/rsync.pas

# chmod 600 /etc/rsync.pas

# rsync --daemon --config=/etc/rsyncd.conf


六.重啓xinetd使其配置生效:

# /etc/init.d/xinetd restart


七.設置開機啓動:

# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local


sersync (推送端)


一.下載sersync源碼包

# wget http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz

注:若在64位平臺安裝則可下載64位sersync源碼包,本例用32位

# wget http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz


二.創建sersync目錄結構

# mkdir /usr/local/sersync

# mkdir /usr/local/sersync/conf

# mkdir /usr/local/sersync/bin

# mkdir /usr/local/sersync/log

# tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz

# cd GNU-Linux-x86/

# cp confxml.xml /usr/local/sersync/conf

# cp sersync2 /usr/local/sersync/bin


三.配置sersync


1.首先創建連接rsyncd的密碼文件

# echo "123456" >/etc/rsync.pas

# chmod 600 /etc/rsync.pas


2.配置confxml.xml

# cd /usr/local/sersync/conf

# vi confxml.xml

按照註釋進行修改

-----------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>

<head version="2.5">

  # 設置本地IP和端口

  <host hostip="localhost" port="8008"></host>

  # 開啓DUBUG模式  

  <debug start="false"/>

  # 開啓xfs文件系統

  <fileSystem xfs="false"/>

  # 同步時忽略推送的文件(正則表達式),默認關閉

  <filter start="false">

      <exclude expression="(.*)\.svn"></exclude>

      <exclude expression="(.*)\.gz"></exclude>

      <exclude expression="^info/*"></exclude>

      <exclude expression="^static/*"></exclude>

  </filter>

  <inotify>

  # 設置要監控的事件

      <delete start="true"/>

      <createFolder start="true"/>

      <createFile start="true"/>

      <closeWrite start="true"/>

      <moveFrom start="true"/>

      <moveTo start="true"/>

      <attrib start="true"/>

      <modify start="true"/>

</inotify>


  <sersync>

  # 本地同步的目錄路徑

      <localpath watch="/data">

  # 遠程IP和rsync模塊名  

          <remote ip="192.168.100.29" name="data"/>  

          <!--<remote ip="192.168.8.39" name="tongbu"/>-->

          <!--<remote ip="192.168.8.40" name="tongbu"/>-->

      </localpath>

      <rsync>

  # rsync指令參數

          <commonParams params="-auvzP"/>

  # rsync同步認證

          <auth start="true" users="user" passwordfile="/etc/rsync.pas"/>

  # 設置rsync遠程服務端口,遠程非默認端口則需打開自定義

          <userDefinedPort start="false" port="874"/><!-- port=874 -->

  # 設置超時時間

          <timeout start="true" time="100"/><!-- timeout=100 -->

  # 設置rsync+ssh加密傳輸模式,默認關閉,開啓需設置SSH加密證書

          <ssh start="false"/>

      </rsync>

   # sersync傳輸失敗日誌腳本路徑,每隔60會重新執行該腳本,執行完畢會自動清空。

      <failLog path="/usr/local/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

   # 設置rsync+crontab定時傳輸,默認關閉

      <crontab start="false" schedule="600"><!--600mins-->

          <crontabfilter start="false">

              <exclude expression="*.php"></exclude>

              <exclude expression="info/*"></exclude>

          </crontabfilter>

      </crontab>

  # 設置sersync傳輸後調用name指定的插件腳本,默認關閉

      <plugin start="false" name="command"/>

  </sersync>

  # 插件腳本範例

  <plugin name="command">

      <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->

      <filter start="false">

          <include expression="(.*)\.php"/>

          <include expression="(.*)\.sh"/>

      </filter>

  </plugin>

  # 插件腳本範例

  <plugin name="socket">

      <localpath watch="/opt/tongbu">

          <deshost ip="192.168.138.20" port="8009"/>

      </localpath>

  </plugin>

  <plugin name="refreshCDN">

      <localpath watch="/data0/htdocs/cms.xoyo.com/site/">

          <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>

          <sendurl base="http://pic.xoyo.com/cms"/>

          <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

      </localpath>

  </plugin>

</head>

-----------------------------


3.創建推送端sersync同步目錄

# mkdir /data


4.設置環境變量:

# echo "export PATH=$PATH:/usr/local/sersync/bin/" >> /etc/profile

# source /etc/profile


5.啓動sersync

# sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml

注:重啓操作如下:

# killall sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml


6.設置開機啓動

# echo "sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml" >> /etc/rc.local


驗證:


(推送端)

# cd /data

# touch 1 2 3 4 5

# echo "test sersync" > 1


(接收端)

# cd /data

# ls

--------------------

1  2  3  4  5

--------------------

# cat 1

--------------------

test sersync

--------------------

注:這裏提一個細節,如果接收端服務器本地創建或修改/data同步目錄下的文件,當服務端進行目錄同步時則不會對接收端服務器本地創建或修改的文件產生影響。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章