rsync + inotify sync server data

This article mainly talks about the rsync + inotify configuration method. As for how to install these two tools, there are a lot of online tutorials, so I won't describe them one by one here.

 

Function: server changes are synchronized to the client

 

Server side configuration:

 

Server IP : 10.11.28.4

/home/www/rsync.sh

 

 

#!/bin/bash
  src=/home/www/apache-tomcat-7.0.64/webapps/redpacket/ #Synced folder
  des=www #The correspondence between the logo and the client
  host="10.11.28.5" #Client IP address
  /home/www/inotify-tools-3.14/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e  modify,delete,create,attrib $src | while read files
  do
  for hostip in $host
  do
  rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd $src cib@$hostip::$des
  done
  echo "${files} was rsynced" >>/home/www/slave_sync/rsync.log 2>&1 # Server-side log address
  done

 /etc/rsync.passwd

 

 

bonus #password

 

 

Client configuration:

Client IP : 10.11.28.5

 

 

/etc/rsyncd.conf

list=yes
uid=root #Users and groups to which the synced folder belongs must be consistent
gid=root #Users and groups to which the synced folder belongs
hosts allow=10.11.28.4
max connections=30
log file=/var/log/rsyncd.log #Client log address
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
[www]
comment=from 10.11.28.5
path=/home/www/apache-tomcat-7.0.64/webapps/redpacket/
auth users=cib #Username, must be a system user, and corresponds to rsync.passwd
read only = false
secrets file=/etc/rsync.passwd

 /etc/rsync.passwd

cib:bonus # username and password

 

 

 Start rsync.sh on the server side

nohup /bin/bash /home/cib/rsync.sh &

Server side kills rsync.sh

ps -ef |grep rsync.sh |awk '{print $2}'|xargs kill -9

Client starts rsync

rsync --daemon

Client terminates rsync

ps –ef | grep rsync

Find the pid of rsync , then kill it

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326872844&siteId=291194637