Linux绯荤粺sersync鏁版嵁瀹炴椂鍚屾

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux绯荤粺sersync鏁版嵁瀹炴椂鍚屾相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/svn' title='svn'>svn   define   鍚屾杞欢   瀹夎   console   鎸囧畾   娴嬭瘯   rtu   鐩戝惉   

Linux绯荤粺sersync鏁版嵁瀹炴椂鍚屾

Linux绯荤粺sersync鏁版嵁瀹炴椂鍚屾

鍓嶉潰浠嬬粛浜嗕互瀹堟姢杩涚▼鐨勬柟寮忎紶杈撴垨鍚屾鏁版嵁rsync杞欢锛宭inux绯荤粺鏁版嵁鍚屾杞欢寰堝锛屼粖澶╂潵浠嬬粛涓媠ersync鏁版嵁鍚屾杞欢
涓€锛歴ersync浠嬬粛
sersync鍏跺疄鏄埄鐢╥notify鍜宺sync涓ょ杞欢鎶€鏈潵瀹炵幇鏁版嵁瀹炴椂鍚屾鍔熻兘鐨勶紝inotify鏄敤浜庣洃鍚瑂ersync鎵€鍦ㄦ湇鍔″櫒涓婄殑鏂囦欢鍙樺寲锛岀粨鍚坮sync杞欢鏉ヨ繘琛屾暟鎹悓姝ワ紝灏嗘暟鎹疄鏃跺悓姝ョ粰瀹㈡埛绔湇鍔″櫒
浜岋細sersync宸ヤ綔杩囩▼
鍦ㄥ悓姝ヤ富鏈嶅姟鍣ㄤ笂寮€鍚痵ersync锛岃礋璐g洃鍚枃浠剁郴缁熺殑鍙樺寲锛岀劧鍚庤皟鐢╮sync鍛戒护鎶婃洿鏂扮殑鏂囦欢鍚屾鍒扮洰鏍囨湇鍔″櫒涓婏紝涓绘湇鍔″櫒涓婂畨瑁卻ersync杞欢锛岀洰鏍囨湇鍔″櫒涓婂畨瑁卹sync鏈嶅姟
涓夛細鏁翠綋鐜鎷撴墤鍥?br/>鎶€鏈浘鐗? src=
鍥涳細瀹㈡埛绔畨瑁呴厤缃畆sync鏈嶅姟
[root@Client ~]# cat /etc/rsyncd.conf
cat: /etc/rsyncd.conf: No such file or directory
濡傛灉鏈夋鏂囦欢锛岄厤缃墠瑕佽繘琛屽浠斤紝鍐嶈繘琛岀浉鍏抽厤缃?br/>[root@Client etc]# vi /etc/rsyncd.conf
##rsync config start
##created by root 2016-08-08 15:00
##rsync.conf config start
uid = rsync
gid = rsync
use chroot = no
max connetctions = 200
timeout = 100
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
path = /backup/
ignore errors
read only = false
list = false
hosts allow = 192.168.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
##rsync config end
"rsyncd.conf" [New] 21L, 458C written
娣诲姞鐢ㄦ埛
[root@Client ~]# useradd rsync -s /sbin/nologin -M
鏀瑰彉鐩綍鏉冮檺
[root@Client ~]# chown -R rsync.rsync /backup
閰嶇疆瀵嗙爜鏂囦欢
[root@Client ~]# echo "rsync_backup:rsync.conf">>/etc/rsync.password
[root@Client ~]# cat /etc/rsync.password
rsync_backup:rsync.conf
鏀瑰彉瀵嗙爜鏂囦欢鏉冮檺
[root@Client ~]# chmod 600 /etc/rsync.password
[root@Client ~]# ls -ld /etc/rsync.password
-rw-------. 1 root root 24 Sep 9 13:06 /etc/rsync.password
鏍煎紡鍖栨枃浠?br/>[root@Client ~]# dos2unix /etc/rsyncd.conf
dos2unix: converting file /etc/rsyncd.conf to UNIX format ...
寮€鍚湇鍔″悗鍙拌繍琛?br/>[root@Client ~]# rsync --daemon
[root@Client ~]# netstat -lntup|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0: LISTEN 2002/rsync
tcp 0 0 :::873 :::
LISTEN 2002/rsync
浜旓細涓绘湇鍔″櫒涓婇厤缃瘑鐮佹枃浠?br/>[root@Master ~]# echo "rsync.conf">>/etc/rsync.password
[root@Master ~]# cat /etc/rsync.password
rsync.conf
[root@Master ~]# chmod 600 /etc/rsync.password
[root@Master ~]# ls -ld /etc/rsync.password
-rw-------. 1 root root 11 Sep 8 06:25 /etc/rsync.password
鍏細娴嬭瘯鎵嬪伐鍚屾
[root@Master /]# rsync -avzP /etc/hosts rsync_backup@192.168.1.3::rsync --password-file=/etc/rsync.password
sending incremental file list
hosts
158 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)
sent 120 bytes received 27 bytes 26.73 bytes/sec
total size is 158 speedup is 1.07
[root@Master /]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@Client ~]# cat /backup/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
缁忚繃瀵规瘮涓よ竟鏁版嵁涓€鑷达紝琛ㄦ槑鍚屾鎴愬姛锛屾墜宸ュ悓姝ユ垚鍔熶箣鍚庯紝鐒跺悗鍐嶈繘琛屽悗闈㈢殑閰嶇疆
涓冿細瀹夎sersync鏈嶅姟
棣栧厛涓嬭浇濂藉畨瑁呰蒋浠?br/>sersync_64bit_binary_stable_final.tar.gz
[root@Master tools]# tar -zxvf sersync_64bit_binary_stable_final.tar.gz -C
/usr/local/
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
[root@Master tools]# cd /usr/local/
[root@Master local]# ls
bin games include lib64 sbin src
etc GNU-Linux-x86 lib libexec share
GNU-Linux-x86灏辨槸sersync瀹夎杞欢锛屼负浜嗘柟渚垮皢瀹冩敼鍚?br/>[root@Master local]# mv GNU-Linux-x86 sersync
涓轰簡鍚庣画鏂逛究绠$悊锛屽垱寤哄嚑涓洰褰曠敤浜庡瓨鏀惧悇绫绘枃浠?br/>[root@Master sersync]# mkdir -p conf bin logs
[root@Master sersync]# mv confxml.xml conf
[root@Master sersync]# ls
bin conf logs sersync2
[root@Master sersync]# cd conf
[root@Master conf]# ls
confxml.xml
鍦ㄩ厤缃厤缃枃浠朵箣鍓嶅浠?br/>[root@Master conf]# cp confxml.xml confxml.xml.$(date +%F)
[root@Master conf]# ls
confxml.xml confxml.xml.2016-09-08
淇敼閰嶇疆鏂囦欢鍐呭锛坈onfxml.xml锛?br/>1銆佷慨鏀?4-28琛?br/><localpath watch="/opt/tongbu">
<remote ip="127.0.0.1" name="tongbu1"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->娉ㄩ噴鍐呭
<!--<remote ip="192.168.8.40" name="tongbu"/>-->娉ㄩ噴鍐呭
</localpath>
淇敼鍚庣殑鍐呭涓?br/><localpath watch="/opt/backup"> 鏈湴鏁版嵁鐨勮矾寰?br/><remote ip="192.168.1.3" name="rsync"/>杩滅IP涓庢ā鍧楀悕绉?br/></localpath>
<!#################################### -->娉ㄩ噴鍐呭
2銆佷慨鏀?1-34琛屽唴瀹光€斺€旇璇?br/><commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
淇敼鍚庣殑鍐呭涓?br/><commonParams params="-aruz"/>
<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"/>
3銆佷慨鏀?6-37琛?br/><failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default
every 60mins execute once-->
淇敼鎴愭垜浠垰鍒氬垱寤哄ソ鐨刲ogs鐩綍
<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecut
e="60"/><!--default every 60mins execute once-->
淇敼瀹屾垚鍚庢渶缁堢殑閰嶇疆鏂囦欢濡備笅
[root@Master conf]# cat /usr/local/sersync/conf/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="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="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/opt/backup">
<remote ip="192.168.1.3" name="rsync"/>
</localpath>
<!#################################### -->
<rsync>
<commonParams params="-aruz"/>
<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>
<failLog path="/usr/local/sersync/logs/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/">
<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>
鍏細寮€鍚痵ersync瀹堟姢杩涚▼
棣栧厛閰嶇疆鍏ㄥ眬鐜鍙橀噺锛屼娇寰楀悗鍚屽彲浠ョ洿鎺ヨ皟鐢╯ersync鍛戒护
[root@Master conf]# echo 鈥榚xport PATH=$PATH:/usr/local/sersync/bin鈥?gt;>/etc/profile
[root@Master conf]# tail -1 /etc/profile
export PATH=$PATH:/usr/local/sersync/bin
[root@Master conf]# source /etc/profile
[root@Master conf]# which sersync
/usr/local/sersync/bin/sersync
鍚姩sersync鏈嶅姟
serync -r -d -o /usr/local/sersync/conf/confxml.xml
-r鍒濆鍖栨暟鎹?
-d鍚庡彴鍚姩
-o鎸囧畾璺緞
濡傛灉闇€瑕佸皢鍛戒护寮€鍚姩锛屽彧闇€灏嗗懡浠ゅ幓鎺夊弬鏁?r瀹氬叆/etc/rc.local
鍚姩鍚庣粨鏋滃涓?br/>[root@Master backup]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -r rsync all the local files to the remote servers before the sersync work
option: -d run as a daemon
option: -o config xml name: /usr/local/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
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 remote servers once
working please wait...
execute command: cd /opt/backup && rsync -aruz -R --delete ./ --timeout=100 rsync_backup@192.168.1.3::rsync --password-file=/etc/rsync.password >/dev/null 2>&1
run the sersync:
watch path is: /opt/backup
涔濓細娴嬭瘯鏁版嵁鍚屾
[root@Master sersync]# cd /opt/backup/
[root@Master backup]# ls
[root@Master backup]# ls -ll
total 0
[root@Master backup]# touch 123
[root@Master backup]# touch 1234
[root@Master backup]# touch 1235
[root@Master backup]# touch 12333
[root@Master backup]# ls -ll
total 0
-rw-r--r--. 1 root root 0 Sep 8 09:26 123
-rw-r--r--. 1 root root 0 Sep 8 09:26 12333
-rw-r--r--. 1 root root 0 Sep 8 09:26 1234
-rw-r--r--. 1 root root 0 Sep 8 09:26 1235
鐩爣鏈嶅姟鍣ㄦ煡鐪嬪悓姝ユ儏鍐?br/>[root@Client backup]# ls -ll
total 0
-rw-r--r--. 1 rsync rsync 0 Sep 8 04:26 123
-rw-r--r--. 1 rsync rsync 0 Sep 8 04:26 12333
-rw-r--r--. 1 rsync rsync 0 Sep 8 04:26 1234
-rw-r--r--. 1 rsync rsync 0 Sep 8 04:26 1235
娴嬭瘯缁撴灉琛ㄦ槑鏁版嵁鍚屾姝e父锛岃兘澶熷疄鏃跺悓姝?br/>鎶€鏈浘鐗? src=

闀挎寜鍏虫敞鍏紬鍙封€斺€斿弸渚冩湁绗?/p>

以上是关于Linux绯荤粺sersync鏁版嵁瀹炴椂鍚屾的主要内容,如果未能解决你的问题,请参考以下文章

Spark + Hadoop,鍩轰簬WIFI鎺㈤拡鐨勫ぇ鏁版嵁鍒嗘瀽绯荤粺

Greenplum鏁版嵁搴撲腑绯荤粺琛╬g_class璇﹁В

Linux绯荤粺鍩虹鐭ヨ瘑鐩綍銆佸厓鏁版嵁銆佽蒋纭摼鎺ャ€佹枃浠剁鐞嗗懡浠ゃ€乿im鏌ユ壘鏇挎崲銆乿imtab缂╄繘

Linux绯荤粺SSH鏈嶅姟涔?sshkey瀵嗛挜璁よ瘉瀹炴垬

澶氱畻娉曠患鍚堢殑鏂囨湰鎸栨帢绯荤粺

Openldap 鏁版嵁鍚屾