<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>实时文件同步 Archives - CNERIS</title>
	<atom:link href="https://cneris.com/zh/tag/%E5%AE%9E%E6%97%B6%E6%96%87%E4%BB%B6%E5%90%8C%E6%AD%A5/feed/" rel="self" type="application/rss+xml" />
	<link>https://cneris.com/zh/tag/实时文件同步/</link>
	<description></description>
	<lastBuildDate>Sun, 25 Aug 2024 11:48:01 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>服务器 A 和 B 之间实时文件同步的解决方案</title>
		<link>https://cneris.com/zh/%e6%9c%8d%e5%8a%a1%e5%99%a8-a-%e5%92%8c-b-%e4%b9%8b%e9%97%b4%e5%ae%9e%e6%97%b6%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/</link>
					<comments>https://cneris.com/zh/%e6%9c%8d%e5%8a%a1%e5%99%a8-a-%e5%92%8c-b-%e4%b9%8b%e9%97%b4%e5%ae%9e%e6%97%b6%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Aug 2024 11:45:13 +0000</pubDate>
				<category><![CDATA[Centos]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[专用服务器]]></category>
		<category><![CDATA[系统管理]]></category>
		<category><![CDATA[实时文件同步]]></category>
		<category><![CDATA[文件同步]]></category>
		<category><![CDATA[服务器实时文件同步]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2128</guid>

					<description><![CDATA[<p>要在两个服务器之间进行实时文件同步，可以考虑以下几种解决方案： 使用 rsync 和 inotifywait： 使用 rsync 结合 inotifywait。inotifywait 监控服务器 A 上的文件系统变化，每当检测到变化时，rsync 将文件同步到服务器 B。这种方法对于几乎实时的同步非常高效。脚本示例： bash Copiar código #!/bin/bash SRC=”/要同步的路径” DEST=”user@serverB:/目标路径” inotifywait -m -r -e modify,create,delete $SRC | while read path action file; do rsync -avz $SRC $DEST done Lsyncd： Lsyncd（实时同步守护进程）是一种更高级的工具，它使用 rsync 进行同步，并使用 inotify 实时监控变化。它易于配置并作为后台守护进程运行。 lftp： 尽管 lftp 不是专门的实时同步工具，但你可以使用它的 mirror 命令和 –continue 选项在服务器 A 和 B [...]</p>
<p>The post <a href="https://cneris.com/zh/%e6%9c%8d%e5%8a%a1%e5%99%a8-a-%e5%92%8c-b-%e4%b9%8b%e9%97%b4%e5%ae%9e%e6%97%b6%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/">服务器 A 和 B 之间实时文件同步的解决方案</a> appeared first on <a href="https://cneris.com/zh">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>要在两个服务器之间进行实时文件同步，可以考虑以下几种解决方案：<span id="more-2128"></span></p>
<ol>
<li><strong>使用 rsync 和 inotifywait：</strong><br />
使用 <code>rsync</code> 结合 <code>inotifywait</code>。<code>inotifywait</code> 监控服务器 A 上的文件系统变化，每当检测到变化时，<code>rsync</code> 将文件同步到服务器 B。这种方法对于几乎实时的同步非常高效。脚本示例：</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<p>bash</p>
<div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center">Copiar código</button></span></div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash"><span class="hljs-meta">#!/bin/bash</span><br />
SRC=<span class="hljs-string">"/要同步的路径"</span><br />
DEST=<span class="hljs-string">"user@serverB:/目标路径"</span><br />
inotifywait -m -r -e modify,create,delete <span class="hljs-variable">$SRC</span> | <span class="hljs-keyword">while</span> <span class="hljs-built_in">read</span> path action file; <span class="hljs-keyword">do</span><br />
rsync -avz <span class="hljs-variable">$SRC</span> <span class="hljs-variable">$DEST</span><br />
<span class="hljs-keyword">done</span><br />
</code></div>
</div>
</li>
<li><strong>Lsyncd：</strong><br />
Lsyncd（实时同步守护进程）是一种更高级的工具，它使用 <code>rsync</code> 进行同步，并使用 <code>inotify</code> 实时监控变化。它易于配置并作为后台守护进程运行。</li>
<li><strong>lftp：</strong><br />
尽管 <code>lftp</code> 不是专门的实时同步工具，但你可以使用它的 <code>mirror</code> 命令和 <code>--continue</code> 选项在服务器 A 和 B 之间进行频繁的同步。然而，这不是一个实时解决方案，需要定期执行。<code>lftp</code> 的使用示例：</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<p>bash</p>
<div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center">Copiar código</button></span></div>
</div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-bash">lftp -e <span class="hljs-string">"mirror --reverse --delete --continue --verbose /本地目录 /远程目录; bye"</span> -u user,password serverB<br />
</code></div>
</div>
<p><strong>注意：</strong> 虽然 <code>lftp</code> 可能有用，但它不提供实时同步。对于实时同步，<code>rsync</code> 与 <code>inotifywait</code> 或 <code>Lsyncd</code> 是更好的选择。</li>
</ol>
<p>The post <a href="https://cneris.com/zh/%e6%9c%8d%e5%8a%a1%e5%99%a8-a-%e5%92%8c-b-%e4%b9%8b%e9%97%b4%e5%ae%9e%e6%97%b6%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/">服务器 A 和 B 之间实时文件同步的解决方案</a> appeared first on <a href="https://cneris.com/zh">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/zh/%e6%9c%8d%e5%8a%a1%e5%99%a8-a-%e5%92%8c-b-%e4%b9%8b%e9%97%b4%e5%ae%9e%e6%97%b6%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
