系统内核要求2.6.13以上
目标服务器,rsync服务端配置,也就是被同步到的服务器
uname -r //查看系统内核版本
yum -y install rsync
vi /etc/rsyncd.conf
uid = rsync
gid = rsync
max connections = 200
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.lock
timeout = 900
read only = false
[redis_dump]
path = /data/redis_dump.bak/
hosts allow = 192.168.88.130
hosts deny = * //先允许再拒绝
secrets file = /etc/rsync.pass
auth users = rsync
read only = no
fake super = yes //新版本需要这个参数,否则无法同步
echo "rsync:123456" > /etc/rsync.pass
chmod 600 /etc/rsync.pass //权限一定为600,否则同步是没有权限
chown -R rsync:rsync redis_dump.bak //备份目录属主和属组一定要是rsync配置文件中指定的用户
systemctl start rsyncd
源服务器,rsync客户端,也就是被同步的服务器
yum provides inotifywait
yum -y install inotify-tools-3.14-9.el7.x86_64
vi /data/inotify_bak.sh
#!/bin/bash
src=/data/redis_dump/
pass=/etc/rsync.pass
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src |while read files;do
rsync -avH --port 873 --progress --delete $src [email protected]::redis_dump --password-file=$pass
echo "${files} was rsynced" >> /tmp/rsync.log 2>&1
done
chmod +x /data/inotify_bak.sh
echo "123456" > /etc/rsync.pass //认证用户的密码
chmod 600 /etc/rsync.pass
nohup sh /data/inotify_bak.sh &
然后再源服务器创建一些文件测试一下,再到目标服务器看看有没有被同步过去