数据同步 rsync+notify架构

rsync 同步命令,非常好用

notify是监控本地文件的变化的

、安装配置

1. 安装rsync,inotify-tools

sudo apt-get install rsync inotify-tools 

2. 拷贝rsync配置文件

mkdir /etc/rsync
cp /usr/share/doc/rsync/examples/rsyncd.conf   /etc/rsync/

3. 服务端配置/etc/rsync/rsyncd.conf

#secrets file=/etc/rsync/rsyncd.secrets
#motd file=/etc/rsync/rsyncd.motd
[test]
#path=/usr/share/nginx/html
path=/usr/share/nginx/html

log file=/var/log/rsyncd.log
pid file=/var/log/rsyncd.pid
lock file=/var/run/rsync.lock

read only=no
list=yes
uid=root
gid=root
use chroot=no
max connections=5
comment=share file
#ignore errors
上面这种是比较严谨的做法,实际上,如果是局域网内网的话,不需要设置权限,直接更改把标签名改成test,path=/test (你要共享的路径)

4. 创建同步目录

mkdir /test

5. 创建认证文件,修改权限600

vim /etc/rsync/rsync.secrets
user:passwd
chmod 600  /etc/rsync/rsync.secrets

6. 修改 /etc/default/rsync,设置为true   注意一定要修改这个,不然rsync启动不了

RSYNC_ENABLE=true
RSYNC_CONFIG_FILE= "/etc/rsync/rsyncd.conf"

7. 服务端启动rsync服务

/etc/init.d/rsync start
 

8. 然后就可以在客户端使用命令  rsync -a 192.168.1.229::,然后会发现 test 这个标签是可以进行同步的。



原文地址:https://www.cnblogs.com/to-be-rich/p/6678252.html