sersync


一、sersync

理論

sersync=inotify+rsync

inotify有監控的功能,而rsync有同步的功能,那么sersync這個軟件的功能就是監控某個目錄,當這個目錄發生特定的動作時(比如:插入、刪除等),就自動觸發rsync的推送功能,將變化及時的同步到服務端。

場景:

在客戶端上通過sersync監控/data目錄,有變化時及時同步到服務端的/backup目錄。

client:192.168.80.20

server:192.168.80.23

客戶端的配置

先安裝rsync,因為sersync要依賴於rsync,還有inotiry-tools也要安裝上

[root@client ~]#  yum -y install rsync     #任意源都可以
[root@client ~]#  yum -y install inotify-tools

然后去github上面把sersync下載下來

https://github.com/wsgzao/sersync

https://github.com/wsgzao/sersync/raw/master/sersync2.5.4_64bit_binary_stable_final.tar.gz

sersync是一個綠色包,解壓出來就能用了,不用安裝,我們最好將它解壓到/var/local/目錄里面,tar -xf 解壓之后,會生成一個GUI開頭的目錄,更名為sersync

[root@client sersync]# pwd
/var/local/sersync
[root@client sersync]# ls   #conf是配置文件,sersync2是運行文件,編輯一下配置文件
confxml.xml  sersync2
[root@client sersync]# vim confxml.xml 
[root@client sersync]# cat confxml.xml 
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="true"/>     #這地方有改動
    <filter start="false">
	<exclude expression="(.*)\.svn"></exclude>
	<exclude expression="(.*)\.gz"></exclude>
	<exclude expression="^info/*"></exclude>
	<exclude expression="^static/*"></exclude>
    </filter>
    <inotify>       #所有的操作都改成true
	<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">    #監控哪個目錄,/data目錄
	    <remote ip="192.168.80.23" name="data"/> #服務端的IP和服務端模塊的名字,而不是目錄的名字
	    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
	    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
	</localpath>
	<rsync>
	    <commonParams params="-az"/>   #改成az即可
	    //打開密碼認證,用戶和密碼文件注意不要輸入錯了,不忘記改passwd的權限600
	    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.passwd"/>
	    <userDefinedPort start="false" port="874"/><!-- port=874 -->
	    <timeout start="true" time="100"/><!-- timeout=100 -->  #這里打開
	    <ssh start="false"/>
	    
[root@client sersync]# echo 1 > /etc/rsync.passwd  #注意,客戶端就直接填寫密碼就可以了
[root@client sersync]# chmod 600 /etc/rsync.passwd  #注意權限問題,密碼文件必須是600權限
[root@client sersync]# ./sersync2 -dro confxml.xml   #啟動
execute command: cd /data && rsync -az -R --delete ./  --timeout=100 rsync_backup@192.168.80.23::data --password-file=/etc/rsync.passwd >/dev/null 2>&1 
run the sersync: 
watch path is: /data

服務端的配置

服務端的配置與正常的rsync是一樣的,並沒有因為客戶端的變化而產生變化。

[root@server ~]# yum -y install rsync    #默認就在后台運行
[root@server ~]# systemctl start rsyncd 
cat /etc/rsyncd.conf 
uid = rsync
gid = rsync
port = 873 
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsync.log
[data]
comment = welcome!
path = /data


[root@server ~]# useradd -M -s /sbin/nologin rsync
[root@server ~]# echo "rsync_backup:1" > /etc/rsync.passwd  #密碼定義為1
[root@server ~]# chmod 600 /etc/rsync.passwd
[root@server ~]# mkdir /data
[root@server ~]# chown -R rsync:rsync /data


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM