服務器兩臺php
rsync-server:192.168.1.8 (備份服務器)node
sersync-node1:192.168.1.9 (須要備份的服務器)linux
系統express
CentOS7.4vim
關閉防火牆和selinuxapi
基礎優化 略安全
useradd -s /sbin/nologin -M rsync服務器
vi /etc/rsyncd.confdom
#rsync_config_________startssh
##rsyncd.conf start#####
uid = rsync #==>用戶 遠端的命令使用rsync訪問共享的目錄
gid = rsync #==>用戶組
usr 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 #==>rsync的日誌文件
[backup] #==>模塊名稱
path = /backup #==>服務器端提供訪問的目錄
ignore errors #==>忽略錯誤信息
read only = false #==>客戶端是否可上傳
list = false #==>不能列表(不能ls)
hosts allow = 192.168.0.0/16 #==>容許那些服務器鏈接
(這倆host兩者留其一就能夠;否則外網IP也能推送數據過來)
#hosts deny = 0.0.0.0/32 #==>拒絕那些機器鏈接
auth users = rsync_backup #==>虛擬用戶
secrets file = /etc/rsync.password #==>存放虛擬帳號的用戶和密碼
#rsync_config ______end#####
echo "rsync_backup:123456" >/etc/rsync.password #密碼123456
chmod 600 /etc/rsync.password
mkdir /backup -p
chown -R rsync.rsync /backup
rsync --daemon --config=/etc/rsyncd.conf
echo "rsync --daemon --config=/etc/rsyncd.conf" >>/etc/rc.local
echo "123456" >/etc/rsync.password
chmod 600 /etc/rsync.password
mkdir /usr/local/sersync -p
mkdir /usr/local/sersync/{bin,log,conf} -p
tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/confxml.xml /usr/local/sersync/conf/
mv GNU-Linux-x86/sersync2 /usr/local/sersync/bin
cd /usr/local/sersync/conf
cp confxml.xml confxml.xml.bak
vim 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="false"/>
<createFolder start="true"/>
<createFile start="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch=" /data/"> # 填寫須要備份的目錄
<remote ip="192.168.1.8" name="bakup"/> #服務端的IP地址和rsync定義的模塊名
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsyncd.password"/> #定義認證用戶和密碼文件 在服務器端都配置好了的,密碼文件是本地剛纔配置的
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="ture" 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>
# 設置sersync傳輸後調用name指定的插件腳本,默認關閉
<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>
啓動sersync
/usr/local/sersync/bin/sersync2 -d -r -o /usr/local/sersync/conf/confxml.xml
ps -ef|grep sersync #查看進程是否存在
測試
在node端執行
cd /data/
touch {1..10}.txt
在服務端看
cd /backup
ls
若是存在就說明OK了~