sersync的服務設置

sersync可以理解爲建立在inotify基礎上的加強版,它可以更加細膩和完美的實現inotifyrsync的能力.

使用sersync就必須安裝inotifyrsync.

1.1 環境nfs客戶端和backup服務端

默認iptables,xelinux已經關閉

1.1.1 nfs客戶端

[root@nfs01 ~]# uname -a

Linux nfs01 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017x86_64 x86_64 x86_64 GNU/Linux

查看是否有inotify,如果沒有下載

[root@nfs01 ~]# rpm -qa inotify-tools

inotify-tools-3.14-1.el6.x86_64

下載方法

yum install inotify-tools -y

設置nfs客戶端的推送目錄

mkdir -p /nfsbackup/

設置rsync的密碼文件,權限,查看

echo "密碼" >/etc/rsync.password

chmod 600 /etc/rsync.password

[root@nfs01 ~]# ll /etc/rsync.password

-rw------- 1 root root 7 Jun 28 11:21/etc/rsync.password

1.1.2 backup服務端

[root@backup ~]# uname -a

Linux backup 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017x86_64 x86_64 x86_64 GNU/Linux

查看rsync是否啓動(默認已經安裝rsync,如果沒有安裝請看之前發的rsync服務設置)

[root@backup ~]# ss -lntup|grep rsyn

tcp   LISTEN     0      5                     :::873                  :::*      users:(("rsync",1294,5))

tcp   LISTEN     0      5                      *:873                   *:*      users:(("rsync",1294,3))

如果沒有啓動請啓動

rsync --daemon

查看rsync的配置文件找到虛擬用戶,用戶密碼,用戶路徑

[root@backup ~]# cat /etc/rsyncd.conf

######rsync_config_______________start

#created by oldboy 15:01 2007-6-22

#QQ 31333741 blog:http://oldboy.blog.51cto.com

##rsyncd.conf start##

uid=rsync

gid=rsync

 

use chroot = no

max connections = 200

timeout = 300

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

ignore errors

list = false

hosts allow = 172.16.1.0/24

#hosts deny = 0.0.0.0/32

auth users = rsync_backup

secrets file = /etc/rsync.password

#rsync_config_______________end

read only = false

[backup]

path = /backup/

 

[nfsbackup] #模塊的名字

path = /nfsbackup/ #模塊的路徑

ignore errors

read only = false

list = false

hosts allow = 172.16.1.0/24

#hosts deny = 0.0.0.0/32

auth users = rsync_backup #虛擬用戶的用戶名

secrets file = /etc/rsync.password #用戶密碼的路徑

 

1.2 安裝sersync

1.2.1 去網站下載sersync

1.2.2 傳輸到nfs服務器

輸入sz選擇sersync

如果沒有,安裝上傳下載命令

yum install -y lrzsz

解壓sersync,需要unzip命令

unzip sersync_installdir_64bit.zip

sersync文件包移動到/usr/local/sersync

mv sersync_installdir_64bit  /usr/local/sersync

給執行權限

chmod +x  /usr/local/sersync/bin/sersync

查看

[root@nfs01 ~]# tree /usr/local/sersync/

/usr/local/sersync/

├── bin

   └── sersync

├── conf

   └── confxml.xml

├── logs

└── sersync

 

4 directories, 2 files

1.3 設置sersync的配置文件

vim /usr/local/sersync/conf/confxml.xml

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

<head version="2.5">

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

    <debugstart="false"/>

   <fileSystem xfs="false"/>

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

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

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

   </filter>

   <inotify>

       <delete start="true"/>

       <createFolder start="true"/>

       <createFile start="false"/>

       <closeWrite start="true"/>

       <moveFrom start="true"/>

       <modify start="false"/>

   </inotify>

 

   <sersync>

       <localpath watch="/nfsbackup"> ###填寫nfs客戶端的目錄

           <remote ip="172.16.1.41"name="nfsbackup"/>###填寫backup服務端的IP地址和模塊名字

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

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

       </localpath>

       <rsync>

           <commonParams params="-az"/> ###選擇rsync執行的命令參數

                       <auth start="true" users="rsync_backup"passwordfile="/etc/rsync.password"/>

#####選擇開啓,名字就是rsync的虛擬用戶名,虛擬用戶密碼目錄

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

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

            <ssh start="false"/>

       </rsync>

       <failLog path="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60mins execute once-->

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

           <crontabfilter start="false">

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

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

           </crontabfilter>

       </crontab>

       <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/">

            <cdninfodomainname="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>

1.4 查看使用說明

[root@nfs01 ~]# sersync -h

set the system param

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

_______________________________________________________

參數-d:啓用守護進程模式

參數-r:在監控前,將監控目錄與遠程主機用rsync命令推送一遍

c參數-n: 指定開啓守護線程的數量,默認爲10

參數-o:指定配置文件,默認使用confxml.xml文件

參數-m:單獨啓用其他模塊,使用 -m refreshCDN 開啓刷新CDN模塊

參數-m:單獨啓用其他模塊,使用 -m socket 開啓socket模塊

參數-m:單獨啓用其他模塊,使用 -m http 開啓http模塊

不加-m參數,則默認執行同步程序

________________________________________________________________

1.5 啓動sersync服務

[root@nfs01 conf]# sersync -rd -o /usr/local/sersync/conf/confxml.xml

set the system param

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r         rsyncall the local files to the remote servers before the sersync work

option: -d        runas a daemon

option: -o        configxml name /usr/local/sersync/conf/confxml.xml

daemon thread num: 10

parse xml config file

host ip : localhost    hostport: 8008

daemon startsersync run behind the console

use rsync password-file :

useris      rsync_backup

passwordfileis        /etc/rsync.password

config xml parse success

please set /etc/rsyncd.conf max connections=0Manually

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 remoteservers once

working please wait...

execute command: cd /nfsbackup && rsync -az -R --delete ./[email protected]::nfsbackup --password-file=/etc/rsync.password>/dev/null 2>&1

run the sersync:

watch path is: /nfsbackup

1.6 測試

nfs客戶端

添加

root@nfs01 nfsbackup]# touch {1..5}.log

[root@nfs01 nfsbackup]# ll

total 0

-rw-r--r-- 1 root root 0 Jun 29 18:46 1.log

-rw-r--r-- 1 root root 0 Jun 29 18:46 2.log

-rw-r--r-- 1 root root 0 Jun 29 18:46 3.log

-rw-r--r-- 1 root root 0 Jun 29 18:46 4.log

-rw-r--r-- 1 root root 0 Jun 29 18:46 5.log

刪除

[root@nfs01 nfsbackup]# rm -f *

[root@nfs01 nfsbackup]# ll

total 0

1.6.1 backup服務端

添加

[root@backup nfsbackup]# ll

total 0

-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 1.log

-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 2.log

-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 3.log

-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 4.log

-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 5.log

刪除

[root@backup nfsbackup]# ll

total 0


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