机器
| 192.168.134.129 | Rsync服务端+Rsync客户端+inotify-tools |
| 192.168.134.132 | Rsync客户端+Rsync服务端+inotify-tools |
服务端
129 Rsync服务端已经搭建过了
132 Rsync服务端配置如下
yum -y install rsync
cat /etc/rsyncd.conf
uid = nfsuser
gid = nfsuser
use chroot = no
fake super = yes
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[nfs_data]
path = /nfs
ignore errors
read only = false
list=false
hosts allow = 192.168.134.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password_1
# 唯一不同的就是最后面一行
useradd -s /sbin/nologin -M -u 9090 nfsuser
mkdir /nfs
chown -R nfsuser:nfsuser /nfs/
cat /etc/rsync.password_1
rsync_backup:12345
chmod 600 /etc/rsync.password_1
rsync --daemon
客户端配置
132客户端已经搭建过了
129
yum -y install rsync
useradd -s /sbin/nologin -M -u 9090 nfsuser
mkdir /nfs
chown -R nfsuser:nfsuser /nfs/
cat /etc/rsync.password_1
12345
chmod 600 /etc/rsync.password_1
测试
129客户端执行命令
rsync -avz /nfs/ rsync_backup@192.168.134.132::nfs_data

132服务端查看数据

数据同步成功了
总不能每次都要手动执行数据上传命令吧
实时同步
129客户端安装工具+编写脚本
yum -y install inotify-tools
vim Inotify.sh
#!/bin/bash
rysnc_user=rsync_backup
rsync_server=192.168.134.132
rsync_path=/nfs
rsync_module=nfs_data
inotify=/usr/bin/inotifywait
$inotify -mrq --format '%w%f' -e create,delete,move,close_write $rsync_path | while read file
do
cd $rsync_path && \
/usr/bin/rsync -azP ./ --delete $rysnc_user@$rsync_server::$rsync_module --password-file=/etc/rsync.password_1 >/dev/null 2>&1
done >/dev/null 2>&1
赋予权限
chmod 755 Inotify.sh
客户端执行脚本+创建文件