rsync+inotify数据传输
说明与名称 |
IP |
应用 |
操作系统 |
源端:server |
192.168.58.146 |
rsync inotify-tools 脚本 |
centos7 |
目标:node |
192.168.58.152 |
rsync |
centos7 |
一、在node服务器操作
1. 关闭防火墙与selinux
systemctl stop firewalld
systemctl disable firewalld
sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
getenforce 0
2. 安装rsync服务端软件
yum -y install rsync
3. 设置rsyncd.conf配置文件
vim /etc/rsyncd.conf
注意在实际使用中,配置文件中不要有注释
log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/rsync.pass
[etc_from_client]
path = /data/web/
comment = sync etc from client
uid = root
gid = root
port = 873
ignore errors
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = hanweb
hosts allow = 192.168.58.146
hosts deny = 192.168.24.188
4. 创建存放路径目录
mkdir /data/web -p
5. 创建用户认证文件
echo 'admin:admin@123' > /etc/rsync.pass
6. 设置文件权限
chmod 600 /etc/rsync*
7. 启动rsync服务并设置开机自启动
systemctl enable rsyncd --now
二、在server服务器操作
1. 关闭防火墙与selinux
systemctl stop firewalld
systemctl disable firewalld
sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
setenforce 0
2. 安装epel源
yum -y install epel-release
3. 安装rsync服务端软件,只需要安装
yum -y install rsync
4. 创建认证密码文件
echo 'admin@123' > /etc/rsync.pass
5. 设置文件权限
chmod 600 /etc/rsync.pass
6. 创建测试目录
mkdir -pv /data/test
rsync -avH --port 873 --progress --delete /data/web admin@192.168.58.152::etc_from_client --password-file=/etc/rsync.pass
ll /data/web
ll /proc/sys/fs/inotify/
max_queued_events
max_user_instances
max_user_watches
yum -y install inotify-tools
8. 编写同步脚本
mkdir /scripts
touch /scripts/inotify.sh
chmod 755 /scripts/inotify.sh
vim /scripts/inotify.sh
host=192.168.58.152
src=/data/web/
des=etc_from_client
password=/etc/rsync.pass
user=hanweb
inotifywait=/usr/bin/inotifywait
$inotifywait -mrq --timefmt '%Y%m%d %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \
| while read files ; do
rsync -avzP --delete --timeout=100 --password-file=${password} $src $user@$host::$des
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
bash -x /scripts/inotify.sh
nohup bash /scripts/inotify.sh &
ps -ef|grep inotify
echo 'hello world' > /data/web/test
tail /tmp/rsync.log
9. 设置脚本开机自动启动
chmod +x /etc/rc.d/rc.local
echo 'nohup /bin/bash /scripts/inotify.sh' >> /etc/rc.d/rc.local
10. 在node节点验证是否同步成功
ll /data/web
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY