阿里云海外 ECS 做 SIP 跨洋通话完整方案

[复制链接]
5|0
本帖最后由 中国英茂科工 于 2026-9-17 10:59 编辑

阿里云海外 ECS 做 SIP 跨洋通话完整方案
方案要点了然于胸,我先把总体架构图画出来(架构 + 三条跨洋通话路径),再给完整落地方案。

核心结论先说:**单台海外 ECS(默认新加坡)+ FreeSWITCH(业务)作为主力即可跑通,生产环境再加 Kamailio 做边缘信令防护;跨洋质量的关键是「选对节点 + TLS/SRTP + Opus + 抖动缓冲 + 海外 SIP Trunk 双线落地」**。下面是总体架构(示意):


方案要点了然于胸,我先把总体架构图画出来(架构 + 三条跨洋通话路径),再给完整落地方案。

核心结论先说:**单台海外 ECS(默认新加坡)+ FreeSWITCH(业务)作为主力即可跑通,生产环境再加 Kamailio 做边缘信令防护;跨洋质量的关键是「选对节点 + TLS/SRTP + Opus + 抖动缓冲 + 海外 SIP Trunk 双线落地」**。下面是总体架构(示意):

```
<html style="margin:0;padding:0;">
<title>SIP 跨洋通话总体架构示意</title>
<div style="width:100%;box-sizing:border-box;background:#f8fafc;padding:12px 8px;font-family:-apple-system,'PingFang SC','Microsoft YaHei',sans-serif;">
<svg viewBox="0 0 1340 960" width="100%" xmlns="[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)" role="img" aria-label="阿里云海外ECS SIP跨洋通话架构示意">
  <defs>
    <marker id="mb" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#2563eb"/></marker>
    <marker id="mg" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#16a34a"/></marker>
    <marker id="mo" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#ea580c"/></marker>
    <marker id="mt" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#0d9488"/></marker>
    <marker id="mg2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#94a3b8"/></marker>
  </defs>

  <text x="40" y="40" font-size="24" font-weight="700" fill="#0f172a">阿里云海外 ECS · SIP 跨洋通话总体架构</text>
  <text x="40" y="66" font-size="14" fill="#64748b">推荐部署点:新加坡(亚太默认)· 法兰克福(欧洲)· 弗吉尼亚/硅谷(美洲)|大陆→新加坡 RTT≈50-120ms,大陆→美西≈150-200ms(示意,非精确测量)</text>

  <!-- 列背景 -->
  <rect x="40" y="120" width="400" height="580" rx="10" fill="#ffffff" stroke="#e2e8f0"/>
  <rect x="470" y="120" width="400" height="580" rx="10" fill="#ffffff" stroke="#e2e8f0"/>
  <rect x="900" y="120" width="400" height="580" rx="10" fill="#ffffff" stroke="#e2e8f0"/>
  <text x="240" y="140" font-size="16" font-weight="700" fill="#334155" text-anchor="middle">中国侧(大陆办公室/用户)</text>
  <text x="240" y="158" font-size="12.5" fill="#94a3b8" text-anchor="middle">延迟敏感侧</text>
  <text x="670" y="140" font-size="16" font-weight="700" fill="#334155" text-anchor="middle">阿里云海外 ECS(核心节点)</text>
  <text x="670" y="158" font-size="12.5" fill="#94a3b8" text-anchor="middle">新加坡 · 法兰克福 · 弗吉尼亚/硅谷</text>
  <text x="1100" y="140" font-size="16" font-weight="700" fill="#334155" text-anchor="middle">海外侧(落地与远端)</text>
  <text x="1100" y="158" font-size="12.5" fill="#94a3b8" text-anchor="middle">PSTN 落地 + 海外分机</text>

  <!-- C1 盒子 -->
  <g>
    <rect x="52" y="150" width="376" height="60" rx="8" fill="#eff6ff" stroke="#93c5fd"/>
    <text x="70" y="177" font-size="15" font-weight="700" fill="#1e3a8a">国内办公分机</text>
    <text x="70" y="198" font-size="13" fill="#3b82f6">IP 话机 · 软电话 · 手机 App</text>
    <rect x="52" y="320" width="376" height="60" rx="8" fill="#f8fafc" stroke="#cbd5e1"/>
    <text x="70" y="347" font-size="15" font-weight="700" fill="#334155">国内语音网关(可选)</text>
    <text x="70" y="368" font-size="13" fill="#64748b">对接国内 PSTN 内线 / 老式话机</text>
    <rect x="52" y="500" width="376" height="60" rx="8" fill="#f8fafc" stroke="#cbd5e1"/>
    <text x="70" y="527" font-size="15" font-weight="700" fill="#334155">接入优化(可选)</text>
    <text x="70" y="548" font-size="13" fill="#64748b">阿里云 GA / 优质回程线路 / 国内接入机</text>
  </g>

  <!-- C2 盒子 -->
  <g>
    <rect x="482" y="150" width="376" height="60" rx="8" fill="#f0fdf4" stroke="#86efac"/>
    <text x="500" y="177" font-size="15" font-weight="700" fill="#14532d">安全组 + 弹性公网 IP(EIP)</text>
    <text x="500" y="198" font-size="13" fill="#16a34a">仅放行 5061/TLS · RTP 端口段 · SSH 白名单</text>
    <rect x="482" y="260" width="376" height="80" rx="8" fill="#eff6ff" stroke="#93c5fd"/>
    <text x="500" y="287" font-size="15" font-weight="700" fill="#1e3a8a">信令层:Kamailio(生产推荐)</text>
    <text x="500" y="308" font-size="13" fill="#3b82f6">SIP 代理 · 限流 · IP 白名单 · TLS 终结</text>
    <text x="500" y="326" font-size="13" fill="#3b82f6">小规模可省略,FreeSWITCH 直连</text>
    <rect x="482" y="390" width="376" height="60" rx="8" fill="#fefce8" stroke="#fde047"/>
    <text x="500" y="417" font-size="15" font-weight="700" fill="#713f12">业务层:FreeSWITCH / Asterisk</text>
    <text x="500" y="438" font-size="13" fill="#ca8a04">PBX · IVR · 录音 · 路由 · 计费</text>
    <rect x="482" y="500" width="376" height="60" rx="8" fill="#f0fdf4" stroke="#86efac"/>
    <text x="500" y="527" font-size="15" font-weight="700" fill="#14532d">安全与运维</text>
    <text x="500" y="548" font-size="13" fill="#16a34a">fail2ban · IDS · 云盘录音 · 快照备份</text>
  </g>

  <!-- C3 盒子 -->
  <g>
    <rect x="912" y="150" width="376" height="60" rx="8" fill="#fff7ed" stroke="#fdba74"/>
    <text x="930" y="177" font-size="15" font-weight="700" fill="#7c2d12">海外 DID 号码</text>
    <text x="930" y="198" font-size="13" fill="#ea580c">美国 / 新加坡 / 香港等本地号码</text>
    <rect x="912" y="260" width="376" height="80" rx="8" fill="#fff7ed" stroke="#fdba74"/>
    <text x="930" y="287" font-size="15" font-weight="700" fill="#7c2d12">国际 SIP Trunk(双供应商冗余)</text>
    <text x="930" y="308" font-size="13" fill="#ea580c">Twilio / Plivo / EnjoyTalk 等</text>
    <text x="930" y="326" font-size="13" fill="#ea580c">TLS + IP 白名单对接</text>
    <rect x="912" y="390" width="376" height="60" rx="8" fill="#fff7ed" stroke="#fdba74"/>
    <text x="930" y="417" font-size="15" font-weight="700" fill="#7c2d12">海外分机 / 远程员工</text>
    <text x="930" y="438" font-size="13" fill="#ea580c">话机或软电话直连 ECS</text>
    <rect x="912" y="500" width="376" height="60" rx="8" fill="#f8fafc" stroke="#cbd5e1"/>
    <text x="930" y="527" font-size="15" font-weight="700" fill="#334155">海外 PSTN</text>
    <text x="930" y="548" font-size="13" fill="#64748b">手机 · 固话 · 客服热线(被叫方)</text>
  </g>

  <!-- 内部调用 -->
  <line x1="670" y1="210" x2="670" y2="258" stroke="#94a3b8" stroke-width="1.6" marker-end="url(#mg2)"/>
  <line x1="670" y1="340" x2="670" y2="388" stroke="#94a3b8" stroke-width="1.6" marker-end="url(#mg2)"/>

  <!-- ① 信令(双向) -->
  <line x1="428" y1="172" x2="482" y2="172" stroke="#2563eb" stroke-width="2.2" marker-start="url(#mb)" marker-end="url(#mb)"/>
  <text x="455" y="162" font-size="13" font-weight="700" fill="#2563eb" text-anchor="middle">① 信令 SIP/TLS</text>

  <!-- ② 去话落地 -->
  <path d="M 428,210 V 225 H 858 V 300" fill="none" stroke="#16a34a" stroke-width="2.2" marker-end="url(#mg)"/>
  <line x1="858" y1="300" x2="912" y2="300" stroke="#16a34a" stroke-width="2.2" marker-end="url(#mg)"/>
  <text x="530" y="218" font-size="13" font-weight="700" fill="#16a34a">② 去话:分机→ECS→SIP Trunk</text>

  <!-- ③ 呼入 -->
  <path d="M 912,188 H 885 V 240 H 450 V 188 H 428" fill="none" stroke="#ea580c" stroke-width="2.2" marker-end="url(#mo)"/>
  <text x="745" y="233" font-size="13" font-weight="700" fill="#ea580c">③ 呼入:海外 DID→ECS→中国分机</text>

  <!-- ① 媒体 -->
  <path d="M 428,210 V 420 H 482" fill="none" stroke="#0d9488" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#mt)"/>
  <line x1="858" y1="420" x2="912" y2="420" stroke="#0d9488" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#mt)"/>
  <text x="500" y="412" font-size="13" font-weight="700" fill="#0d9488">① 媒体 RTP/SRTP(Opus/G.711,经 ECS 中转)</text>

  <!-- J→K 落地 -->
  <line x1="1010" y1="340" x2="1010" y2="498" stroke="#16a34a" stroke-width="2.2" marker-end="url(#mg)"/>
  <text x="1022" y="425" font-size="12.5" fill="#16a34a">落地 PSTN</text>

  <!-- 图例 -->
  <g font-size="13" fill="#334155">
    <line x1="40" y1="720" x2="80" y2="720" stroke="#2563eb" stroke-width="2.5"/>
    <text x="90" y="724">实线蓝:信令(SIP over TLS)</text>
    <line x1="300" y1="720" x2="340" y2="720" stroke="#0d9488" stroke-width="2.5" stroke-dasharray="7 5"/>
    <text x="350" y="724">虚线青:媒体(RTP/SRTP)</text>
    <line x1="580" y1="720" x2="620" y2="720" stroke="#16a34a" stroke-width="2.5"/>
    <text x="630" y="724">绿:去话落地</text>
    <line x1="820" y1="720" x2="860" y2="720" stroke="#ea580c" stroke-width="2.5"/>
    <text x="870" y="724">橙:呼入</text>
    <line x1="1080" y1="720" x2="1120" y2="720" stroke="#94a3b8" stroke-width="2"/>
    <text x="1130" y="724">灰:内部调用</text>
  </g>

  <!-- 基线卡片 -->
  <g>
    <rect x="40" y="760" width="400" height="150" rx="10" fill="#f1f5f9" stroke="#e2e8f0"/>
    <text x="60" y="786" font-size="15" font-weight="700" fill="#0f172a">网络基线(公网实测参考)</text>
    <text x="60" y="812" font-size="13.5" fill="#334155">· 京/津→新加坡:80-120ms</text>
    <text x="60" y="834" font-size="13.5" fill="#334155">· 沪/杭→新加坡:50-70ms</text>
    <text x="60" y="856" font-size="13.5" fill="#334155">· 国内→美西:150-200ms(高峰更高)</text>
    <text x="60" y="878" font-size="13.5" fill="#334155">· 抖动 2-20ms,跨境丢包 &lt;1% 为主</text>
    <rect x="470" y="760" width="400" height="150" rx="10" fill="#f1f5f9" stroke="#e2e8f0"/>
    <text x="490" y="786" font-size="15" font-weight="700" fill="#0f172a">通话质量目标</text>
    <text x="490" y="812" font-size="13.5" fill="#334155">· MOS ≥ 3.5(可接受线)</text>
    <text x="490" y="834" font-size="13.5" fill="#334155">· 编码:Opus 优先(弱网抗性),G.711 兜底</text>
    <text x="490" y="856" font-size="13.5" fill="#334155">· JitterBuffer 60-120ms + 回声消除必开</text>
    <text x="490" y="878" font-size="13.5" fill="#334155">· RTT &gt; 250ms 时需转双节点架构</text>
    <rect x="900" y="760" width="400" height="150" rx="10" fill="#f1f5f9" stroke="#e2e8f0"/>
    <text x="920" y="786" font-size="15" font-weight="700" fill="#0f172a">进阶:双节点架构</text>
    <text x="920" y="812" font-size="13.5" fill="#334155">· 大陆放一台接入 ECS(阿里云国内节点)</text>
    <text x="920" y="834" font-size="13.5" fill="#334155">· 与海外核心机之间走 CEN / 专线 / 优质回程</text>
    <text x="920" y="856" font-size="13.5" fill="#334155">· 大陆分机只连就近节点,延迟最优</text>
    <text x="920" y="878" font-size="13.5" fill="#334155">· 核心机负责 Trunk 落地与录音</text>
  </g>
</svg>
</div>
</html>
```

下面按实施顺序给出完整落地方案。

---

## 一、场景假设与关键决策

方案默认场景(如与你的实际不符,改动只影响“规模/节点/落地国”三处,框架不变):

| 决策点 | 默认值 | 理由 |
| --- | --- | --- |
| 规模 | ≤10 并发起,可平滑扩到 50+ | 并发 ×0.2 vCPU、×0.5GB 内存线性扩容 |
| 通话方向 | 大陆⇄海外内部分机 + 大陆→海外 PSTN 落地 + 海外 DID 呼入 | 覆盖最常见三种路径 |
| 软件栈 | FreeSWITCH(业务)+ Kamailio(信令边缘,生产推荐) | FreeSWITCH 媒体/录音/并发强,Kamailio 挡扫描 |
| 节点 | 新加坡(亚太默认) | 大陆 RTT 50-120ms 可接受,且是东南亚落地中心 |
| 落地 | 2 家国际 SIP Trunk 做双线 | 防单点故障,竞价压分钟成本 |

## 二、服务器与网络规划(阿里云侧)

**节点选择**:按“多数分机在哪一侧”定。大陆↔东南亚选**新加坡**(京/津→新 RTT 80-120ms,沪/杭→新 50-70ms,广深→新 30-45ms);主要打美加选**硅谷/弗吉尼亚**(大陆→美西公网约 150-200ms,晚高峰可到 250ms+);主要打欧洲选**法兰克福/伦敦**。

**机型与带宽**:

- 起步:轻量应用服务器新加坡 2C4G 约 **¥67/月**(含流量包),适合 POC;生产建议 ECS 标准实例(安全组、快照、内网能力更全)。
- 带宽测算:Opus 每路单向约 30-40kbps,G.711 约 87kbps;10 并发双向约 2-3Mbps,保底买 5-10Mbps。
- 公网流量:超出按 CDT 计费(ECS 公网流量约 0.50 元/GB 量级,随用量阶梯降价);录音文件建议直接写 OSS/云盘,不占公网流量。
- 固定 **EIP** 必买:TLS 证书、分机注册地址、Trunk 白名单都需要稳定 IP。

## 三、软件部署(Debian/Ubuntu 单机为例)

**选型结论**(小规模可砍到只剩 FreeSWITCH):

| 软件 | 职责 | 什么时候加 |
| --- | --- | --- |
| FreeSWITCH(或 Asterisk/FreePBX) | PBX、IVR、录音、路由、计费 | 必装;FreePBX 适合纯图形化管理 |
| Kamailio / OpenSIPS | 边缘信令代理:限流、IP 白名单、TLS 终结、防扫描 | 公网暴露 + 生产环境必加 |
| RTPEngine | 媒体转发/转码、NAT 穿透、jitter 补偿 | 分机在 NAT 后、多编码互通时加 |

**关键配置要点(FreeSWITCH)**:

- 分机侧 profile:`TLS 5061` 监听 + 强密码 + 注册限速;`<param name="apply-nat-acl">` 与 `external_rtp_ip` 指向 EIP。
- 编码顺序:`opus` → `PCMU/PCMA`(G.729 需商业授权,跨洋弱网不建议当主力)。
- 抖动缓冲:`<param name="jitterbuffer" value="true"/>` + 60-120ms 目标;mod_echo 开启回声消除。
- Trunk 侧 profile:只允许 Trunk 供应商 IP(ACL 白名单),TLS/SRTP 加密对端。
- 注册心跳:`expires` 设 60-120s,分机 App 做 TCP 长连接保活。

**安全加固(必做,公网 SIP 服务器每天都被扫描)**:5060 明文端口不对公网开放,改 5061/TLS + SRTP;fail2ban 捕获 SIP 认证失败(生产基线可参考 maxretry 20 / findtime 300s / bantime 86400s);限制 OPTIONS/REGISTER 速率、关闭枚举响应,防“话费盗打”。

**阿里云安全组规则**(入方向):

| 端口 | 协议 | 放行范围 | 说明 |
| --- | --- | --- | --- |
| 5061 | TCP | 分机所在网段 + Trunk IP | SIP-TLS 信令 |
| 5060 | UDP | 仅 Trunk 供应商 IP | 或直接关闭,Trunk 走 5061 |
| 10000-20000 | UDP | 分机网段 + Trunk IP | RTP/SRTP 媒体(收窄默认端口段) |
| 22 | TCP | 运维白名单 IP | SSH |

## 四、跨洋通话质量优化(成败关键)

1. **节点先行**:RTT>250ms 基本无法保证 MOS≥3.5,先选对节点;大陆↔美洲量大的直接上双节点(国内接入机 + 海外核心机,中间 CEN/优质回程互联)。
2. **编码 Opus 优先**:弱网抗丢包/抖动能力明显优于 G.711,两端都支持时优先协商。
3. **JitterBuffer 60-120ms + 回声消除**:跨洋高延迟下必开,否则回声和断续会毁掉体验。
4. **媒体走 ECS 中转**:大陆分机→ECS→Trunk,避免大陆出口直连海外 Trunk 的劣化路径。
5. **监控与拨测**:sngrep 抓 SIP、RTCP 看质量,每 30s 定时呼叫测试号码算 MOS;Prometheus/Grafana 或 Zabbix 盯注册数与异常注册尝试。

## 五、落地线路与费用

**SIP Trunk 选择**(建议双线):

- 国际厂商:Twilio Elastic SIP Trunk(全球 100+ 国 DID,出向约 $0.013/min 起)、Plivo(美国本地号出向 $0.0046/min 起);
- 国内服务商:EnjoyTalk/泛珀 等海外 DID 100+ 国家、呼出低至 0.15 元/分钟(美国约 0.08-0.12 元/分钟);
- DID 月租参考:日本约 $4/月、香港约 $8/月、大陆约 $16/月+用量,按目标市场购买本地号码。

**月成本示例**(10 并发、月通话 5000 分钟、新加坡单机):

| 项目 | 估算 |
| --- | --- |
| ECS 2C4G + 带宽 + EIP + 云盘 | ¥200-450 |
| SIP Trunk 通话费(5000min×0.15-0.8 元) | ¥750-4000(视目的地) |
| DID 月租(2-3 个号码) | ¥30-200 |
| 合计 | **约 ¥1000-5000/月**(海外本地话务为主则取低值) |

**合规提醒**:跨境语音务必走持牌/正规线路;内部 IP 通信自建无碍,但**无资质外呼营销、私自落地大陆 PSTN 属违规**,运营商和监管都会处理,量大的营销场景请走有外呼资质的云通信平台。

## 六、实施里程碑(约 1-2 周)

1. **D1-D2**:开通新加坡 ECS + EIP,安全组收敛端口,装 FreeSWITCH(+Kamailio)。
2. **D3-D4**:配置分机 profile(TLS/编码/jitter),软电话+话机注册,大陆↔海外分机互打内测。
3. **D5-D6**:接第一路 SIP Trunk(IP 白名单+TLS),打通去话/呼入,配 DID 路由。
4. **D7-D9**:fail2ban/限速/录音/快照,加第二路 Trunk 冗余;拨测 + 质量调优。
5. **D10**:监控接入,交付运维手册。

需要的话,我可以把这份方案落成飞书文档/Word 版实施手册,或者直接帮你写好 FreeSWITCH/Kamailio 的关键配置文件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

519

主题

1451

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0