Environment: Two Centos7 virtual machine
Server ip: 192.168.120.12
Client ip: 192.168.120.13
Server configuration
A program to install rsync, rsync daemon configuration file editing
#yum install rsync -y
#vim /etc/rsyncd.conf
The meaning of each can refer to the help manual
#man 5 rsyncd.conf
uid=nobody
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
Two create a username / password, note the username and password here has nothing to do with the system, it can be arbitrary, but to auth users and rsyncd.conf in this one match.
#vim /etc/web1.pass
web1:password
Three open firewall port 873
# firewall-cmd --add-port=873/tcp --permanent
# firewall-cmd --reload
Four start rsync daemon, set the post.
#rsync --daemon
#netstat -lntup | grep rsync
#echo "/usr/bin/rsync --deamon">>/etc/rc.local
Client Configuration
A mounting rsync and inotify
#yum install rsync
Download the rpm package inotify
#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
Two certified documents created rsync
#vim /etc/server.pass
Three create a script
#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
Four run scripts and view the running status
#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'