rsync+sersync大数据T级以上进行同步方法
2019獨角獸企業重金招聘Python工程師標準>>>
操作系統:rhel 5.7
rsync地址: http://rsync.samba.org/download.html
serync下載地址:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
這次的實驗主要有兩臺機器,172.16.54.114和172.16.54.115,我們把115做為源服務器,114做為目標服務器
主要是把115上/home/md中的所有數據實時同步到114上的/home/md中
1,先關閉防火墻
vi /etc/selinux/config #編輯防火墻配置文件
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存,退出
setenforce 0 #立即生效
?
2,查看端口是否被占用(直接在命令行輸入)及安裝
netstat –apn | grep 873
?
安裝rsync,在兩臺服務器上都要進行這個步驟
首先將下載的包解壓
tar -xzvf ?rsync-3.1.0.tar.gz
解壓后進入目錄
./configure --prefix=/usr/local/rsync
?
#說明安裝在/usr/local/rsync目錄中
在這一步之前要安裝相對就的gcc和gcc-c++
make
make install
安裝完畢
?
chkconfig rsync on #隨系統啟動
這個只在114上做
創建rsync配置文件rsync.conf
vi /etc/rsyncd.conf #創建配置文件,添加以下代碼
log file = /var/log/rsyncd.log #日志文件位置,啟動rsync后自動產生這個文件,無需提前創建
pidfile = /var/run/rsyncd.pid? #pid文件的存放位置
lock file = /var/run/rsync.lock? #支持max connections參數的鎖文件
secrets file = /etc/rsync.pass? #用戶認證配置文件,里面保存用戶名稱和密碼,后面會創建這個文件
motd file = /etc/rsyncd.Motd? #rsync啟動時歡迎信息頁面文件位置(文件內容自定義)
[md] #自定義名稱
path = /home/md/ #rsync服務端數據目錄路徑
comment = md #模塊名稱
uid = root #設置rsync運行權限為root
gid = root #設置rsync運行權限為root
port=873? #默認端口
use chroot = no #默認為true,修改為no,增加對目錄文件軟連接的備份
read only = no? #設置rsync服務端文件為讀寫權限
list = no #不顯示rsync服務端資源列表
max connections = 200 #最大連接數
timeout = 600? #設置超時時間
auth users = md #執行數據同步的用戶名,可以設置多個,用英文狀態下逗號隔開
hosts allow = 172.16.54.114? #允許進行數據同步的客戶端IP地址,可以設置多個,用英文狀態下逗號隔開
#hosts deny = 218.234.1.254 #禁止數據同步的客戶端IP地址,可以設置多個,用英文狀態下逗號隔開(這個比較隨便,也可以沒有)
:wq!? #保存,退出
?
創建用戶認證文件
vi /etc/rsync.scrt? #配置文件,添加以下內容
md:123456 #格式為 用戶:密碼,如果是多個,可以一行一個
:wq!? #保存,退出
chmod 600 /etc/rsyncd.conf? #設置文件所有者讀取、寫入權限
chmod 600 /etc/rsync.scrt? #設置文件所有者讀取、寫入權限
?
在此,我們普及一個問題,我們先進入/etc/xinetd.d文件中,可以看到rsync這個文件,說明rsync是由xinetd管理,可以通過xinetd來啟動rsync
/etc/init.d/xinetd start? #啟動
service xinetd stop?? #停止
service xinetd restart #重新啟動
------------------------只在114上進行的到此為止--------------------
?
以下只到115上進行
vi /etc/rsync.scrt? #編輯文件,添加以下內容
123456 #密碼
:wq! #保存退出
chmod 600 /etc/passwd.txt #設置文件權限,只設置文件所有者具有讀取、寫入權限即可
4,安裝sersync
上傳sersync2.5.4_64bit_binary_stable_final.tar.gz到/usr/local目錄下
cd /usr/local
tar –xzvf? sersync2.5.4_64bit_binary_stable_final.tar.gz
這個解壓后會得到一個GUN-linux x86的文件夾
mv G GUN-linux x86/*?? /usr/local/sersync
cd? /usr/local/sersync #進入sersync安裝目錄
cp confxml.xml confxml.xml-bak? #備份原文件
vi 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="/home/md/">
<remote ip="172.16.54.114" name="buspos "/>
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="buspos" passwordfile="/etc/rsyncd.scrt"/>
<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="true" 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>
#標紅的可按自己的配置改,名字和IP比較隨便,是我的配置,紅色#的還得根據自己rsync配置進行修改
?
?
5、設置sersync監控開機自動執行
vi /etc/rc.d/rc.local? #編輯,在最后添加一行
/usr/local/sersync/sersync2 -d -r -o ?/usr/local/sersync/confxml.xml? #設置開機自動運行腳本
:wq!? #保存退出
?
寫完后,首先對數據進行一次整體同步
cd /usr/local/sersync
./sersync2 –r? #以下是輸入之后看到的
set the system param
execute錛歟cho 50000000 > /proc/sys/fs/inotify/max_user_watches
execute錛歟cho 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
daemon thread num: 10
parse xml config file
host ip : localhost???? host port: 8008
Start the crontab?????? Every 600 minutes rsync all the files to the remote servers entirely
use rsync password-file :
user is buspos
passwordfile is???????? /etc/rsyncd.scrt
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 錛寀se -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /home/md && rsync -artuz -R --delete ./ buspos@172.16.54.114::buspos --password-file=/etc/rsyncd.scrt >/dev/null 2>&1
run the sersync:
watch path is: /home/md
--------------------------------到此為止-----------------------------
?
我們來寫個簡單的腳本吧
vi? /home/sh/sersync.sh
#!/bin/sh
sersync="/usr/local/sersync/sersync2"
confxml="/usr/local/sersync/confxml.xml"
status=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)
if [ $status -eq 0 ];
then
$sersync -d -r -o $confxml &
else
exit 0;
fi
:wq??? #保存腳本
?
vi /etc/crontab #編輯,在最后添加下面一行
*/5 * * * * root /home/sh/sersync.sh > /dev/null 2>&1 ?#每隔5分鐘執行一次腳本
service crond reload ?#重新加載服務
至此就不再管了,加入工作例程了!
?
?
?
轉載于:https://my.oschina.net/u/1013648/blog/207600
總結
以上是生活随笔為你收集整理的rsync+sersync大数据T级以上进行同步方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于NPOI的报表引擎——ExcelRe
- 下一篇: 接口统一管理设想