環境:兩臺Centos7的虛擬機html
服務端ip:192.168.120.12
web
客戶端ip:192.168.120.13vim
服務端配置bash
一 安裝rsync程序,編輯rsync守護進程配置文件tcp
#yum install rsync -yide
#vim /etc/rsyncd.confui
各項參數含義可參考幫助手冊spa
#man 5 rsyncd.conform
uid=nobodyserver
gid=nobody
use chroot=no
max_connections=10
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/var/log/rsyncd.log
[web1]
path=/liferay/
comment= document_library file
ignore errors
read only=no
write only=no
#hosts allow="SRProdLnxAmp01.*****.local"
hosts allow=192.168.120.13
hosts deny=*
list=false
uid=root
gid=root
auth users=web1
secrets file=/etc/web1.pass
[web2]
path=/liferay/
comment= lucene file
ignore errors
read only=no
write only=no
#hosts allow=SRProdLnxAmp01.*****.local
hosts allow=192.168.120.13
hosts deny=*
list=false
uid=root
gid=root
auth users=web1
secrets file=/etc/web1.pass
[web3]
path=/liferay/
comment= customer_html_import
ignore errors
read only=no
write only=no
hosts allow=192.168.120.13
hosts deny=*
list=false
uid=root
gid=root
auth users=web1
secrets file=/etc/web1.pass
二 建立用戶名/密碼,注意這裏用戶名和密碼與系統的無關,可隨意指定,可是要和rsyncd.conf中的auth users這一項匹配。
#vim /etc/web1.pass
web1:password
三 防火牆放開873端口
# firewall-cmd --add-port=873/tcp --permanent
# firewall-cmd --reload
四 啓動rsync後臺進程,設置開機自啓。
#rsync --daemon
#netstat -lntup | grep rsync
#echo "/usr/bin/rsync --deamon">>/etc/rc.local
客戶端配置
一 安裝rsync和inotify
#yum install rsync
下載inotify的rpm包
#wget http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/i/inotify-tools-3.14-8.el7.x86_64.rpm
#rpm -Uvh inotify-tools-3.14-8.el7.x86_64.rpm
#yum install inotify-tools
二 建立rsync認證文件
#vim /etc/server.pass
三 建立腳本
#vim /usr/local/rsync/rsync001.sh
#vim /usr/local/rsync/rsync002.sh
#vim /usr/local/rsync/rsync003.sh
#!/bin/bash
host1=SRProdLnxLiferayBackup.****.local
src1=/usr/local/liferay/data/document_library
src2=/usr/local/liferay/data/lucene
dst1=web1
dst2=web2
user1=web1
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib ${src1} \
| while read files
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass ${src1} $user1@$host1::$dst1
echo "${files} was rsynced">>/var/log/rsy.log 2>&1
done
四 運行腳本並查看運行狀態
#sh /usr/local/rsync/rsync001.sh &
#sh /usr/local/rsync/rsync002.sh &
#sh /usr/local/rsync/rsync003.sh &
#ps aux | grep '/usr/local/rsync/rsync'