ガイド

使用WireGuard网状网络实现多区域故障转移

进阶40分で読めます更新日 2026年7月8日
短い回答

三个实例分布在三个国家,通过WireGuard组网,应用程序仅绑定到网状网络,并在其前面设置健康检查的DNS记录,这带来真正的容错能力,每月不到110美元。设计的限制是数据库复制:在区域内同步,跨区域异步。

01 选择三个独立的故障域

Different countries, ideally different transit mixes. Amsterdam, Ashburn and Singapore is the classic triangle. Three is the minimum for quorum — two gives you a split-brain problem rather than redundancy.

02 构建网状网络

Each node gets a stable private address. Every node peers with every other node; with three nodes that is three tunnels.

# node A — /etc/wireguard/mesh.conf
[Interface]
Address = 10.10.0.1/24
ListenPort = 51821
PrivateKey = <A private>

[Peer]                       # node B
PublicKey = <B public>
Endpoint = b.example.net:51821
AllowedIPs = 10.10.0.2/32
PersistentKeepalive = 25

[Peer]                       # node C
PublicKey = <C public>
Endpoint = c.example.net:51821
AllowedIPs = 10.10.0.3/32
PersistentKeepalive = 25

03 仅将服务绑定到网状网络

The database, the cache and the internal API should listen on 10.10.0.x, never on the public address. This removes an entire class of exposure without a single firewall rule.

04 适当复制数据库

Synchronous replication across regions is impractical — a 160 ms round trip becomes the floor for every write. Use asynchronous replication across regions and know your recovery point objective.

05 在DNS层进行健康检查

Short TTLs plus health-checked failover records, or anycast if your regions support it. Then run a failure drill: kill a region deliberately, on a weekday, while you are watching.

よくある質問

为什么不直接购买更大的服务器?

更大的服务器与较小的服务器具有相同的故障域数量:一个。可用性来自独立性,而不是容量。

etcd或Postgres同步副本之间可以相距多远?

将同步副本保持在彼此约100毫秒以内。超出此范围,写入延迟将成为每笔交易的主要成本。