日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sersync+rsync同步

發布時間:2023/12/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sersync+rsync同步 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 一、Sersync安裝

? (1)Sersync同步需求邏輯圖

? ? ?Sersync依賴于rsync進行數據同步,需在主服務器master上開啟Sersync,Sersync負責監控配置文件

中的文件系統的事件變化,然后調用rsync命令把更新的文件同步到目標服務器slave上。

?結論:需要在主服務器上配置Sersync,在同步目標服務器上安裝rsync-server。

? ? ? ? ? Sersync同步示意圖

? user----}Sersync--------}S1-rsync服務器

? ? ? ? ? ? 服務器--------}S2-rsync服務器

? ? ?用戶user會實時的往Sersync服務器寫入或更新數據文件,此時,需要在左邊的同步服務器上配置Sersync,在右邊的同步目標服務器S1和S2上配置rsync守護進程服務,這樣在主服務器寫入或更新數據文件時,就會被

? ? ?Sersync實時同步到slave服務器S1和S2。

? ? ?結論: Sersync就是監控本地的數據寫入或更新事件,然后調用rsync客戶端命令,將寫入或更新的文件實時同步到slave服務器S1和S2上。

??

??

? ?(2)檢查版本---安裝--升級版本 ? yum -y install rsync ?也可編譯安裝

? ??

? ?(3)在目錄服務器slave服務器S1和S2上配置。

? ?################配置客戶端S1-S2######################

[root@rsync-s1 ~]# cat /etc/rsyncd.conf?

#rsync_config_______________start

#create by tangbo 2015-12-02 13:25

#QQ7313760

#########rsyncd.conf______start#########


uid = root

gid = root

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

read only = false

#write only = no

hosts allow = 192.168.11.0/24

hosts deny = 0.0.0.0/32

list = false

auth users = rsync_backup

secrets file = /etc/rsync.password


#####################################

[www]

path=/data/www/www/

comment = www by tangbo 13:40 2015-11-20

#####################################

[bbs]

path=/data/www/bbs/

comment = www by tangbo 13:40 2015-11-20

#####################################

[blog]

path=/data/www/blog/

comment = www by tangbo 13:40 2015-11-20

###################################

#########rsyncd.conf______end#########

[root@rsync-s1 ~]#?

上面的rsync服務的配置文件,允許Sersync主服務器訪問,rsync同步的模塊名為[www] [bbs][blog]

將同步過來的文件分別放入對應path指定的目錄/data/www/www/ /data/www/bbs/ /data/www/blog/下,如果有多臺目標服務器,則每臺都需要類似配置,uid,gid可根據實際情況變化。該用戶必須對這三個目錄有寫入權限。

? ?

? ?(4)創建相關目錄:

? ? ? [root@rsync-s2 ~]# mkdir -p /data/www/www/ /data/www/bbs/ /data/www/blog/

? ? ? [root@rsync-s2 ~]# ls /data/www/

? ? ? ? bbs ?blog ?www

? ? ? [root@rsync-s2 ~]#?

? 權限相關配置:

? ? ? [root@rsync-s1 ~]# vim /etc/rsync.password?

? ? ? ?rsync_backup:tangbo ?(這個用戶和密碼需要去創建)

? ? ? [root@rsync-s1 ~]# chmod 600 /etc/rsync.password?

? 檢查:

? ? ?[root@rsync-s1 ~]# cat /etc/rsync.password?

? ? ?rsync_backup:tangbo

? ? ?[root@rsync-s1 ~]# ll /etc/rsync.password?

? ? ? -rw-------. 1 root root 20 Dec ?8 21:54 /etc/rsync.password

? ? ?[root@rsync-s1 ~]# ?

? ?配置完成后,以守護進程方式啟動rsync服務。

? ?[root@rsync-s1 ~]# pkill rsync

? ?[root@rsync-s1 ~]# rsync --daemon

? ?[root@rsync-s1 ~]# netstat -tlnp | grep 873

? ? tcp ? ? ? ?0 ? ? ?0 0.0.0.0:873 ? ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?888/rsync ? ? ? ? ??

? ? tcp ? ? ? ?0 ? ? ?0 :::873 ? ? ? ? ? ? ? ? ? ? ?:::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?888/rsync ? ? ? ? ??

? ?[root@rsync-s1 ~]#?

? (5)設置開機自啟動

? ? ?[root@rsync-s1 ~]# echo "#rsync service daemon by tangbo 20151207" >>/etc/rc.local?

? ? ?[root@rsync-s1 ~]# echo "/usr/bin/rsync --daemon" >>/etc/rc.local?

? ? ?[root@rsync-s1 ~]# grep daemon /etc/rc.local?

? ? ? #rsync service daemon by tangbo 20151207

? ? ? /usr/bin/rsync --daemon

? ? ?[root@rsync-s1 ~]#?

?重啟命令:?

? ? ?[root@rsync-s2 ~]# pkill rsync

? ? ?[root@rsync-s2 ~]# netstat -tlnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address ? ? ? ? ? ? ? Foreign Address ? ? ? ? ? ? State ? ? ? PID/Program name ??

tcp ? ? ? ?0 ? ? ?0 0.0.0.0:22 ? ? ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?22616/sshd ? ? ? ? ?

tcp ? ? ? ?0 ? ? ?0 127.0.0.1:25 ? ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?1258/master ? ? ? ??

tcp ? ? ? ?0 ? ? ?0 :::22 ? ? ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?22616/sshd ? ? ? ? ?

tcp ? ? ? ?0 ? ? ?0 ::1:25 ? ? ? ? ? ? ? ? ? ? ?:::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?1258/master ? ? ? ??

tcp ? ? ? ?0 ? ? ?0 :::3306 ? ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?5210/mysqld ? ? ? ??

?[root@rsync-s2 ~]# /usr/bin/rsync --daemon

? ?自己可以寫一個正常的rsync啟動腳本。

??

三、Master端安裝rsync客戶端并且測試 ? ?yum -y install rsync ?也可編譯安裝

? ?

? ?(1)在Master上配置相關權限認證

? ?[root@open*** ~]# echo "tangbo" >/etc/rsysn.password

? ?[root@open*** ~]# chmod 600 /etc/rsync.password?

? ?[root@open*** ~]# chmod 600 /etc/rsync.password?

? ?[root@open*** ~]# cat /etc/rsync.password?

? ? tangbo

? ? [root@open*** ~]# ll /etc/rsync.password?

? ? -rw------- 1 root root 7 Dec ?8 22:09 /etc/rsync.password

? ? [root@open*** ~]#?

? ? ?啟動服務:

[root@open*** ~]# touch /etc/rsyncd.conf

? ? ?[root@open*** ~]# rsync --daemon

? ? ?[root@open*** ~]# netstat -tlnp

? ?(2)master 上手工測試同步情況:此步驟非常關鍵,一定要測試。如果測試同步不成功,后面的sersync配置后也不會同步數據。

? ? ?[root@rsync-s2 ~]# mkdir -p /data/www/www/ /data/www/bbs/ /data/www/blog/

[root@open*** ~]# touch /data/www/www/www.log /data/www/bbs/bbs.log /data/www/blog/blog.log

??

? ?(3)執行同步命令

? ? ?[root@open*** /]# rsync -avzP ?/data/www/www/ ?rsync_backup@192.168.11.34::www/ ?--password-file=/etc/rsync.password

[root@open*** /]# rsync -avzP ?/data/www/www/ ?rsync_backup@192.168.11.35::www/ ?--password-file=/etc/rsync.password

?

[root@open*** /]# rsync -avzP ?/data/www/bbs/ ?rsync_backup@192.168.11.34::bbs/ ?--password-file=/etc/rsync.password

[root@open*** /]# rsync -avzP ?/data/www/bbs/ ?rsync_backup@192.168.11.35::bbs/ ?--password-file=/etc/rsync.password

?

[root@open*** /]# rsync -avzP ?/data/www/blog/ ?rsync_backup@192.168.11.35::blog/ ?--password-file=/etc/rsync.password

[root@open*** /]# rsync -avzP ?/data/www/blog/ ?rsync_backup@192.168.11.35::blog/ ?--password-file=/etc/rsync.password

? ??

上述目錄都可以同步成功則可以實現下一步的工作,安裝sersync ?


四、安裝Sersync---單實例

? ? ? (1)下載源碼且解壓到/usr/local/下

?[root@open*** tools]# tar -zxvf sersync_64bit_binary_stable_final.tar.gz -C /usr/local/

?重命名GNU-Linux-x86/ 為sersync?

?[root@open*** local]# mv GNU-Linux-x86/ sersync ? ?

?[root@open*** local]# ls -R sersync/

? ? ? ? ?sersync/:

? ? ? ? ?confxml.xml ?sersync2

? ? ? ? ?[root@open*** local]#?

? ? ?

(2)規范sersync目錄結構

[root@open*** local]# cd sersync/

? ? ?[root@open*** sersync]# mkdir -p conf bin logs

[root@open*** sersync]# mv confxml.xml conf

? ? ?[root@open*** sersync]# mv sersync2 bin

?

[root@open*** local]# ls -R sersync/

? ? ? ?sersync/:

? ? ? ?bin ?conf ?logs


? ? ? ?sersync/bin:

? ? ? ?sersync2


? ? ? ?sersync/conf:

? ? ? ?confxml.xml


? ? ? ?sersync/logs:

? ? ? ?[root@open*** local]#?

?

(3)配置sersync

? ?首先備份配置文件: [root@open*** conf]# cp confxml.xml confxml.xml.backup.$(date +%F)

? ? ?

(4)更改優化sersync配置

? ?修改第24行

[root@open*** conf]# vim +24 confxml.xm

? ?<sersync>

? ? ? ? <localpath watch="/data/www/www">

? ? ? ? ? ? <remote ip="192.168.11.34" name="www"/>

? ? ? ? ? ? <remote ip="192.168.11.35" name="www"/>

? ? ? ? <localpath watch="/data/www/bbs"> ? ? ? ? ? ? ? ? 只建立一個目錄,三個目錄要修改配置文件

? ? ? ? ? ? <remote ip="192.168.11.34" name="bbs"/>

? ? ? ? ? ? <remote ip="192.168.11.35" name="bbs"/>

? ? ? ?<localpath watch="/data/www/blog">

? ? ? ? ? ? <remote ip="192.168.11.34" name="blog"/>

? ? ? ? ? ? <remote ip="192.168.11.35" name="blog"/>

?提示:此步驟<localpath watch="/data/www/blog">就是定義服務端待同步的目錄和目標服務器的模塊name="blog"名。

?

(5)修改第34行

? ? ? <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>

其實這個修改就是在拼接:

rsync -avzP ?/data/www/www/ ?rsync_backup@192.168.11.34::www/ ?--password-file=/etc/rsync.password這個同步命令而已。

?

(6)修改第37行--當同步失敗后,錯誤日志存放路徑。并且沒60分鐘對失敗的log進行重新同步。

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

?

#############開啟sersync守護進程同步數據######################

(7)配置sersync 環境變量

? ?[root@open*** conf]# echo 'export PATH=$PATH:/usr/localsersync/bin'>>/etc/profile

[root@open*** conf]# tail -l /etc/pro

? ? ? ? ?profile ? ?profile.d/ protocols ?

? ? ? ? [root@open*** conf]# tail -l /etc/profile

? ? ? ? ? ? . "$i"

? ? ? ? else

? ? ? ? ? ? . "$i" >/dev/null 2>&1

? ? ? ? fi

? ? fi

done


unset i

unset -f pathmunge

export PATH=$PATH:/usr/local/sersync/bin

? ? ?[root@open*** conf]# source /etc/profile

?

? ? (8)測試結果:發現問題,僅僅能同步一個模塊的路徑,其它模塊的路徑不能同步。


五、多實例

? ?(1)復制配置文件

? ?[root@open*** conf]# cp confxml.xml www_confxml.xml

? ?[root@open*** conf]# cp confxml.xml bbs_confxml.xml

? ?[root@open*** conf]# cp confxml.xml blog_confxml.xml

? ?

? ?(2)修改配置文件

? ?[root@open*** conf]# diff www_confxml.xml bbs_confxml.xml?

24,26c24,26

< <localpath watch="/data/www/www">

< ? ?<remote ip="192.168.11.34" name="www"/>?

< ? ?<remote ip="192.168.11.35" name="www"/>

---

> <localpath watch="/data/www/bbs">

> ? ?<remote ip="192.168.11.34" name="bbs"/>?

> ? ?<remote ip="192.168.11.35" name="bbs"/>

37c37

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

---

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

[root@open*** conf]#?


[root@open*** conf]# diff www_confxml.xml blog_confxml.xml?

24,26c24,26

< <localpath watch="/data/www/www">

< ? ?<remote ip="192.168.11.34" name="www"/>?

< ? ?<remote ip="192.168.11.35" name="www"/>

---

> <localpath watch="/data/www/blog">

> ? ?<remote ip="192.168.11.34" name="blog"/>?

> ? ?<remote ip="192.168.11.35" name="blog"/>

37c37

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

---

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

[root@open*** conf]#?


? ?(3)多實例初始化同步命令:

? ?sersync -r -d -o /usr/local/sersync/conf/www_confxml.xml

? ?sersync -r -d -o /usr/local/sersync/conf/bbs_confxml.xml

? ?sersync -r -d -o /usr/local/sersync/conf/blog_confxml.xml

? ?

? ?(4)檢查配置

? ?[root@open*** conf]# ps -ef | grep sersync

root ? ? 18118 ? ? 1 ?0 20:51 ? ? ? ? ?00:00:00 sersync -r -d -o /usr/local/sersync/conf/www_confxml.xml

root ? ? 18141 ? ? 1 ?0 20:51 ? ? ? ? ?00:00:00 sersync -r -d -o /usr/local/sersync/conf/bbs_confxml.xml

root ? ? 18165 ? ? 1 ?0 20:51 ? ? ? ? ?00:00:00 sersync -r -d -o /usr/local/sersync/conf/blog_confxml.xml

root ? ? 18187 29986 ?0 20:51 pts/0 ? ?00:00:00 grep sersync

root ? ? 32204 29986 ?0 01:49 pts/0 ? ?00:00:00 vim sersync2

[root@open*** conf]#?

? ?(5)到測試目錄下面去測試是否同步成功,同時建立一千個文件

? ?[root@open*** tmp]# cat for.sh?

? ?#!/bin/bash


? ?for i in `seq 1 1000`

? ?do

? ?touch /data/www/www/$i

? ?touch /data/www/bbs/$i

? ?touch /data/www/blog/$i

? ?done

? ?(6)加入開機自啟動

? ? ? [root@open*** tmp]# tail -4 /etc/rc.local?

? ? ? ?tail: inotify cannot be used, reverting to polling

? ? ? #sersync boot

? ? ? sersync -r -d -o /usr/local/sersync/conf/www_confxml.xml

? ? ? sersync -r -d -o /usr/local/sersync/conf/bbs_confxml.xml

? ? ? sersync -r -d -o /usr/local/sersync/conf/blog_confxml.xml

? ? ? [root@open*** tmp]#?

? ?


轉載于:https://blog.51cto.com/cqtangbo/1752546

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的sersync+rsync同步的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。