rsync + inotify 数据实时同步

一、rsync简介

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,
支持本地复制,或者与其他SSH、rsync主机同步

二、rsync三种命令

Rsync的命令格式常用的有以下三种:(与ssh类似)
rsync [OPTION]… SRC DEST (本地服务器之间:复制)
rsync [OPTION]… SRC [USER@]HOST:DEST (上传)
rsync [OPTION]… [USER@]HOST:SRC DEST (下载)

1、 rsync [OPTION]… SRC DEST (本地服务器之间:复制)
服务器(源):
[root@server tmp]# touch a
[root@server tmp]# ls
a
[root@server tmp]# rsync -a a filea
[root@server tmp]# ls
a  filea
2、 rsync [OPTION]… SRC [USER@]HOST:DEST (上传)
服务器(源):
[root@server tmp]# rsync -avz a root@192.168.100.30:/tmp
The authenticity of host '192.168.100.30 (192.168.100.30)' can't be established.
ECDSA key fingerprint is SHA256:R7/1dpul7cu8SnefsN2wQw5hKDL+xekk0ffasLS6OGI.
ECDSA key fingerprint is MD5:81:88:a1:16:52:83:c0:d5:59:ad:2b:3a:d5:52:02:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.30' (ECDSA) to the list of known hosts.
root@192.168.100.30's password: 
sending incremental file list
asent 80 bytes  received 35 bytes  6.57 bytes/sec
total size is 0  speedup is 0.00
客户端(目标):
[root@stw3 tmp]# ls
a
3、 rsync [OPTION]… [USER@]HOST:SRC DEST (下载)
目标:
[root@stw3 tmp]# touch b
[root@stw3 tmp]# ls
a  b
源:
[root@server tmp]# rsync -avz root@192.168.100.30:/tmp/b .
root@192.168.100.30's password: 
receiving incremental file list
bsent 43 bytes  received 80 bytes  7.45 bytes/sec
total size is 0  speedup is 0.00
[root@server tmp]# ls
a  b  filea

三、rsync+inotify

1、rsync的优点和缺点

优点:rsync与传统的cp、tar备份方式相比,rsync具有安全性高、备份迅速、支持增量备份等优点,
通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据到远端服务器,
对本地磁盘定期做数据镜像等。

缺点:首先,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输。如果文件数量达到了百万甚至千 万量级,扫描所有文件将是非常耗时的。而且正在发生变化的往往是其中很少的一部分,这是非常低效的方式。

其次,rsync不能实时的去监测、同步数据,虽然它可以通过linux守护进程的方式进行触发同步,但是两次触发动作一定会有时间差,这样就导致了服务端和客户端数据可能出现不一致,无法在应用故障时完全的恢复数据。

2、inotify

inotify是一种强大的、细粒度的、异步的文件系统事件监控机制,linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加、删除,修改、移动等各种细微事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而inotify-tools就是这样的一个第三方软件。在前面有讲到,rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rsync同步,这样刚好解决了同步数据的实时性问题。

基于以上原因,rsync+inotify(数据实时同步)组合出现了!

四、配置

(把源服务器上/root/etc目录实时同步到目标服务器的/tmp下)

1、源服务器和目标服务器要进行时钟同步
源:
[root@server ~]# vim /etc/chrony.conf 
[root@server ~]# systemctl restart chronyd
[root@server ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@server ~]# timedatectl Local time: Wed 2025-08-20 11:15:45 CSTUniversal time: Wed 2025-08-20 03:15:45 UTCRTC time: Wed 2025-08-20 03:15:45Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yes
NTP synchronized: yesRTC in local TZ: noDST active: n/a
[root@server ~]# hwclock -w

在这里插入图片描述

目标:
[root@stw3 ~]# vim /etc/chrony.conf 
[root@stw3 ~]# systemctl restart chronyd
[root@stw3 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@stw3 ~]# hwclock -w
[root@stw3 ~]# chrony
chronyc  chronyd  
[root@stw3 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? 192.168.100.20                0   7     0     -     +0ns[   +0ns] +/-    0ns

在这里插入图片描述

2、关闭防火墙和selinux(源和目标主机都要关闭,操作一致)
[root@server ~]# systemctl stop firewalld.service 
[root@server ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@server ~]# setenforce 0
[root@server ~]# vim /etc/selinux/config 
[root@server ~]# reboot

在这里插入图片描述

3、目标服务器:
(1)修改配置文件

log file = /var/log/rsyncd.log # 日志文件位置,启动rsync后自动产生这个文件,无需提前创建
pidfile = /var/run/rsyncd.pid # pid文件的存放位置
lock file = /var/run/rsync.lock # 支持max connections参数的锁文件
secrets file = /etc/rsync.pass # 用户认证配置文件,里面保存用户名称和密码,必须手动创建这个文件

[etc_from_client] # 自定义同步名称
path = /tmp/ # rsync服务端数据存放路径,客户端的数据将同步至此目录
comment = sync etc from client
uid = root # 设置rsync运行权限为root
gid = root # 设置rsync运行权限为root
port = 873 # 默认端口
ignore errors # 表示出现错误忽略错误
use chroot = no # 默认为true,修改为no,增加对目录文件软连接的备份
read only = no # 设置rsync服务端为读写权限
list = no # 不显示rsync服务端资源列表
max connections = 200 # 最大连接数
timeout = 600 # 设置超时时间
auth users = admin # 执行数据同步的用户名,可以设置多个,用英文状态下逗号隔开
hosts allow = 192.168.100.10 # 允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hosts deny = 192.168.1.1 # 禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开

[root@stw3 ~]# vim /etc/rsyncd.conf

在这里插入图片描述

(2)创建用户认证文件
[root@stw3 ~]# vim /etc/rsync.pass
[root@stw3 ~]# cat /etc/rsync.pass 
admin:123456

在这里插入图片描述

(3)设置文件权限
[root@stw3 ~]# chmod 600 /etc/rsync*
[root@stw3 ~]# ll /etc/rsync*
-rw------- 1 root root 914 Aug 20 11:30 /etc/rsyncd.conf
-rw------- 1 root root  13 Aug 20 11:32 /etc/rsync.pass
(4)启动rsync服务并设置开机自启
[root@stw3 ~]# rsync --daemon
[root@stw3 ~]# vim /etc/rc.d/rc.local 
[root@stw3 ~]# netstat -tulnp | grep 873
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      9993/rsync          
tcp6       0      0 :::873                  :::*                    LISTEN      9993/rsync      

在这里插入图片描述

4、源服务器:
(1)配置网络源和epel-release
[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@server yum.repos.d]# rm -rf *
[root@server yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2025-08-20 11:43:00--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 117.92.155.17, 150.139.241.204, 111.77.199.29
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|117.92.155.17|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’100%[===================================================================>] 2,523       --.-K/s   in 0s      2025-08-20 11:43:00 (10.5 MB/s) -/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523][root@server yum.repos.d]# yum -y install epel-release
(2)安装rsync服务端软件,只需要安装,不要启动,不需要配置(可忽略,rsync默认已经安装)
[root@server ~]# yum -y install rsync
(3)创建认证密码文件
[root@server ~]# vim /etc/rsync.pass
[root@server ~]# cat /etc/rsync.pass 
123456

在这里插入图片描述

(4)设置文件权限,只设置文件所有者具有读取、写入权限即可
[root@server ~]# chmod 600 /etc/rsync.pass 
(5)在源服务器上创建测试目录,然后在源服务器运行以下命令
[root@server ~]# mkdir /root/etc
[root@server ~]# cd /root/etc
[root@server etc]# ls
[root@server etc]# mkdir test
[root@server etc]# cd test
[root@server test]# pwd
/root/etc/test
[root@server test]# rsync -avH --port 873 --progress --delete /root/etc/ admin@192.168.100.30::etc_from_client --password-file=/etc/rsync.pass
sending incremental file list
deleting vmware-root_8623-1990534217/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-rtkit-daemon.service-V88iF7/tmp/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-rtkit-daemon.service-V88iF7/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-cups.service-I0Q073/tmp/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-cups.service-I0Q073/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-colord.service-9TD9Zd/tmp/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-colord.service-9TD9Zd/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-chronyd.service-fc3OEy/tmp/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-chronyd.service-fc3OEy/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-bolt.service-ZCd3B8/tmp/
deleting systemd-private-587fbc66687344f9bed799a3b4ad760a-bolt.service-ZCd3B8/
deleting .font-unix/
deleting .esd-0/
deleting .XIM-unix/
deleting .X11-unix/X0
deleting .X11-unix/
deleting .Test-unix/
deleting .ICE-unix/9983
deleting .ICE-unix/9630
deleting .ICE-unix/9469
deleting .ICE-unix/9446
deleting .ICE-unix/
deleting .X0-lock
./
test/sent 77 bytes  received 1,018 bytes  104.29 bytes/sec
total size is 0  speedup is 0.00
(6)在目标服务器上查看,在/tmp目录下有test目录,说明数据同步成功
[root@stw3 ~]# cd /tmp
[root@stw3 tmp]# ls
systemd-private-587fbc66687344f9bed799a3b4ad760a-bolt.service-ZCd3B8
systemd-private-587fbc66687344f9bed799a3b4ad760a-chronyd.service-fc3OEy
systemd-private-587fbc66687344f9bed799a3b4ad760a-colord.service-9TD9Zd
systemd-private-587fbc66687344f9bed799a3b4ad760a-cups.service-I0Q073
systemd-private-587fbc66687344f9bed799a3b4ad760a-rtkit-daemon.service-V88iF7
vmware-root_8623-1990534217
[root@stw3 tmp]# ls
test
测试:源服务器中创建文件,可以传输到目标服务器中
源:
[root@server test]# ls
[root@server test]# 
[root@server test]# touch file1 file2
[root@server test]# ls
file1  file2
[root@server test]# rsync -avH --port 873 --progress --delete /root/etc/ admin@192.168.100.30::etc_from_client --password-file=/etc/rsync.pass
sending incremental file list
test/
test/file10 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=1/4)
test/file20 100%    0.00kB/s    0:00:00 (xfr#2, to-chk=0/4)sent 195 bytes  received 66 bytes  24.86 bytes/sec
total size is 0  speedup is 0.00
目标:
[root@stw3 tmp]# cd test
[root@stw3 test]# ls
file1  file2

实现实时同步(rsync+inotify)

源:
(1)安装inotify-tools工具(make、gcc、gcc-c++、inotify-tools)
[root@server ~]# yum -y install make gcc gcc-c++ inotify-tools
(2)写同步脚本,让脚本自动去检测我们制定的目录下 文件发生的变化,然后再执行rsync的命令把它同步到我们的目标服务器端去
[root@server ~]# mkdir /tbjiaoben
[root@server ~]# cd /tbjiaoben
[root@server tbjiaoben]# ls
[root@server tbjiaoben]# vim inotify.sh

host=192.168.100.20 # 目标服务器的ip(备份服务器)
src=/root/etc # 在源服务器上所要监控的备份目录(此处可以自定义,但是要保证存在)
des=etc_from_client # 自定义的模块名,需要与目标服务器上定义的同步名称一致
password=/etc/rsync.pass # 执行数据同步的密码文件
user=admin # 执行数据同步的用户名
inotifywait=/usr/bin/inotifywait

$inotifywait -mrq --timefmt ‘%Y%m%d %H:%M’ --format ‘%T %w%f%e’ -e modify,delete,create,attrib src∣whilereadfiles;dorsync−avzP−−delete−−timeout=100−−password−file=src | while read files;dorsync -avzP --delete --timeout=100 --password-file=srcwhilereadfiles;dorsyncavzPdeletetimeout=100passwordfile={password} $src user@user@user@host::desecho"desecho "desecho"{files} was rsynced" >>/tmp/rsync.log 2>&1
done

在这里插入图片描述

(3)启动脚本
[root@server ~]# nohup bash /tbjiaoben/inotify.sh &
[2] 11411
[root@server ~]# nohup: ignoring input and appending output to ‘nohup.out’
[root@server ~]# ps -ef | grep inotify
root      11401      1  0 15:48 pts/0    00:00:00 /usr/bin/inotifywait -mrq --timefmt %Y%m%d %H:%M --format %T %w%f%e -e modify,delete,create,attrib /root/etc
root      11402      1  0 15:48 pts/0    00:00:00 bash /tbjiaoben/inotify.sh
root      11411   9783  0 15:48 pts/0    00:00:00 bash /tbjiaoben/inotify.sh
root      11412  11411  0 15:48 pts/0    00:00:00 /usr/bin/inotifywait -mrq --timefmt %Y%m%d %H:%M --format %T %w%f%e -e modify,delete,create,attrib /root/etc
root      11413  11411  0 15:48 pts/0    00:00:00 bash /tbjiaoben/inotify.sh
root      11436   9783  0 15:50 pts/0    00:00:00 grep --color=auto inotify
(wd now: ~)
(4)在源服务器上生成一个新文件,查看inotify生成的日志

从日志上可以看到,我们生成了一个test文件,并且添加了内容到其里面

[root@server ~]# cd /root/etc
[root@server etc]# ls
test
[root@server etc]# touch file111
[root@server etc]# ls
file111  test
[root@server etc]# cd
[root@server ~]# tail /tmp/rsync.log 
20250820 15:52 /root/etc/file111CREATE was rsynced
20250820 15:52 /root/etc/file111CREATE was rsynced
20250820 15:52 /root/etc/file111ATTRIB was rsynced
20250820 15:52 /root/etc/file111ATTRIB was rsynced
(5)目标服务器验证
[root@stw3 ~]# cd /tmp
[root@stw3 tmp]# ls
etc  test
[root@stw3 tmp]# cd etc
[root@stw3 etc]# ls
file111  test
5、设置脚本开机自启
(1)把nohup /bin/bash /tbjiaoben/inotify.sh &写到配置文件(/etc/rc.d/rc.local)中
[root@server ~]# vim /etc/rc.d/rc.local 

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/93834.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/93834.shtml
英文地址,请注明出处:http://en.pswp.cn/web/93834.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux基础介绍-3——第一阶段

文章目录一、进程管理1.1 进程的基本概念1.2 常见管理命令1.3 进程优先级调整:nice 与 renice二、软件包管理三、防火墙管理四、shell脚本五、xshell链接kali一、进程管理 1.1 进程的基本概念 进程是程序的动态执行实例,每个进程都有唯一的 PID&#x…

python 可迭代对象相关知识点

1. 什么是可迭代对象 (Iterable) 在 Python 里,可迭代对象指的是: 👉 能够一次返回一个元素的对象,可以被 for 循环遍历。 常见的可迭代对象有: 序列类型:list、tuple、str集合类型:set、dict&a…

ijkplayer Android 编译

一、下载编译库文件1.1 编译库文件环境:ubuntu 20.04 版本liangtao:ffmpeg$lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focal1.2 项目源码下载使用 git 下载 ijkplayer&#…

snn前向推理时间计算(处理器实现)

公式 Tinf(1−sparsity)number of synapsesnumber of sub-processorsSIMD ways T_{\text{inf}} \frac{(1-\text{sparsity})\times \text{number of synapses}} {\text{number of sub-processors}\times \text{SIMD ways}} Tinf​number of sub-processorsSIMD ways(1−sparsity…

Linux------《操作系统全景速览:Windows·macOS·Linux·Unix 对比及 Linux 发行版实战指南》

(一)常见操作系统(system)电脑:Windows,Macos,Linux,UnixWindows:微软公司开发的一款桌面操作系统(闭源系统)。版本有dos,win98,win NT,win XP , …

Three.js 初级教程大全

本文档旨在为初学者提供一个全面的 Three.js 入门指南。我们将从 Three.js 的基本概念开始,逐步介绍如何创建场景、添加物体、设置材质、使用光照和相机,以及如何实现简单的动画和交互。通过本教程,你将能够掌握 Three.js 的核心知识&#xf…

遥感领域解决方案丨高光谱、无人机多光谱、空天地数据识别与计算

一:AI智慧高光谱遥感实战:手撕99个案例项目、全覆盖技术链与应用场景一站式提升方案在遥感技术飞速发展的今天,高光谱数据以其独特的光谱分辨率成为环境监测、精准农业、地质勘探等领域的核心数据源。然而,海量的波段数据、复杂的…

(LeetCode 面试经典 150 题) 114. 二叉树展开为链表 (深度优先搜索dfs+链表)

题目:114. 二叉树展开为链表 思路:深度优先搜索dfs链表,时间复杂度0(n)。 C版本: /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : …

《线程状态转换深度解析:从阻塞到就绪的底层原理》

目录 一、线程的五种基本状态 二、线程从 RUNNABLE 进入阻塞 / 等待状态的三种典型场景 1. 调用sleep(long millis):进入 TIMED_WAITING 状态 2. 调用wait():进入 WAITING/TIMED_WAITING 状态 3. 等待 I/O 资源或获取锁失败:进入 BLOCKE…

面经整理-猿辅导-内容服务后端-java实习

部门管理系统设计 题目要求 设计部门 MySQL 数据表实现接口:根据中间部门 ID 获取其下属叶子部门 ID设计包含子节点列表的 Java 数据对象,并实现批量获取功能 一、MySQL 部门表设计 表结构 CREATE TABLE department (id BIGINT PRIMARY KEY AUTO_INCREME…

Openharmony之window_manager子系统源码、需求定制详解

1. 模块概述 Window Manager 模块是 OpenHarmony 操作系统的核心窗口管理系统,负责窗口的创建、销毁、布局、焦点管理、动画效果以及与硬件显示的交互。该模块采用客户端-服务端架构,提供完整的窗口生命周期管理和用户界面交互支持。 1.1架构总览 Window Manager Client 应…

《CDN加速的安全隐患与解决办法:如何构建更安全的网络加速体系》

CDN(内容分发网络)作为提升网站访问速度的关键技术,被广泛应用于各类互联网服务中。然而,在享受加速优势的同时,CDN也面临诸多安全隐患。本文将解析常见的CDN安全问题,并提供实用的解决办法,帮助…

【Linux指南】GCC/G++编译器:庖丁解牛——从源码到可执行文件的奇幻之旅

不只是简单的 gcc hello.c 每一位Linux C/C++开发者敲下的第一行编译命令,几乎都是 gcc hello.c -o hello 或 g++ hello.cpp -o hello。这像一句神奇的咒语,将人类可读的源代码变成了机器可执行的二进制文件。但在这条简单的命令背后,隐藏着一个如同精密钟表般复杂的多步流…

地区电影市场分析:用Python爬虫抓取猫眼_灯塔专业版各地区票房

在当今高度数据驱动的影视行业,精准把握地区票房表现是制片方、宣发团队和影院经理做出关键决策的基础。一部电影在北上广深的表现与二三线城市有何差异?哪种类型的电影在特定区域更受欢迎?回答这些问题,不能再依赖“拍脑袋”和经…

Spark03-RDD02-常用的Action算子

一、常用的Action算子 1-1、countByKey算子 作用:统计key出现的次数,一般适用于K-V型的RDD。 【注意】: 1、collect()是RDD的算子,此时的Action算子,没有生成新的RDD,所以,没有collect()&…

[Android] 显示的内容被导航栏这挡住

上图中弹出的对话框的按钮“Cancel/Save”被导航栏遮挡了部分显示&#xff0c;影响了使用。Root cause: Android 应用的主题是 Theme.AppCompat.Light1. 修改 AndroidManifest.xml 将 application 标签的 android:theme 属性指向新的自定义主题&#xff1a;<applicationandr…

分贝单位全指南:从 dB 到 dBm、dBc

引言在射频、音频和通信工程中&#xff0c;我们经常会在示波器、频谱仪或测试报告里看到各种各样的dB单位&#xff0c;比如 dBm、dBc、dBV、dBFS 等。它们看起来都带个 dB&#xff0c;实则各有不同的定义和参考基准&#xff1a;有的表示相对功率&#xff0c;有的表示电压电平&a…

怎么确定mysql 链接成功了呢?

asyncio.run(test_connection()) ✗ Connection failed: cryptography package is required for sha256_password or caching_sha2_password auth methods 根据你提供的错误信息,问题出现在 MySQL 的认证插件和加密连接配置上。以下是几种解决方法: 1. 安装 cryptography 包…

(5)软件包管理器 yum | Vim 编辑器 | Vim 文本批量化操作 | 配置 Vim

Ⅰ . Linux 软件包管理器 yum01 安装软件在 Linux 下安装软件并不像 Windows 下那么方便&#xff0c;最通常的方式是去下载程序的源代码并进行编译&#xff0c;从而得到可执行程序。正是因为太麻烦&#xff0c;所以有些人就把一些常用的软件提前编译好并做成软件包&#xff0c;…

VGG改进(3):基于Cross Attention的VGG16增强方案

第一部分&#xff1a;交叉注意力机制解析1.1 注意力机制基础注意力机制的核心思想是模拟人类的选择性注意力——在处理信息时&#xff0c;对重要部分分配更多"注意力"。在神经网络中&#xff0c;这意味着模型可以学习动态地加权输入的不同部分。传统的自注意力(Self-…