需求:实时同步A机器文件到B机器
1 | A 192.168.1.225 |
基本架构
rsync
A1
yum install rsync
然后修改配置文件
/etc/rsyncd.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17pid file = /var/run/rsync.pid
log file = /var/log/rsync.log
lock file=/var/run/rsync.lock
secrets file = /etc/rsync.pwss
transfer logging = yes
address=192.168.1.226
[data]
path = /home/joy/imkefu/apache-tomcat-8.0.45/webapps/ROOT/WEB-INF/classes
comment = data
port = 873
uid = root
gid = root
timeout = 600
max connections = 200
use chroot = no
read only = no
hosts allow = 192.168.1.225
设置验证文件1
2
3
4#/etc/rsync.pass
123456
#chmod 600 /etc/rsync.pass
启动服务1
systemctl start rsyncd
B
1 | yum install rsync |
设置验证文件1
2
3
4#/etc/rsync.pass
123456
#chmod 600 /etc/rsync.pass
Inotify
安装inotify
1 | cd /usr/src |
同步脚本
A1
2
3
4
5
6
7
8
9
10
11
#currentdate=`date +%Y%m%d%H%M`
src=/home/joy/imkefu/apache-tomcat-8.0.45/webapps/ROOT/WEB-INF/classes/
des=data
user=root
host=192.168.1.226
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files
do
/usr/bin/rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.pass $src $user@$host::$des
done
然后执行该脚本。。。
备注
- 可以先拿无关目录测试
- 检查pass文件权限必须是600
- module名字必须保持一致