问题现象

使用 webclient 发起外呼时直接失败,错误信息:

1
Originate Resulted in Error Cause: 41 [NORMAL_TEMPORARY_FAILURE]

关键特征: 通道名称为 sofia/external/8000@-err,而不是正常的 sofia/external/8000@192.168.1.100:5060


日志分析

关键日志片段

1
2
3
4
5
6
7
sofia/external/8000@-err Standard INIT
sofia/external/8000@-err SOFIA ROUTING
sofia/external/8000@-err State Change CS_ROUTING -> CS_CONSUME_MEDIA
Channel sofia/external/8000@-err entering state [calling][0]
Channel sofia/external/8000@-err entering state [terminated][503]
Hangup sofia/external/8000@-err [CS_CONSUME_MEDIA] [NORMAL_TEMPORARY_FAILURE]
Originate Resulted in Error Cause: 41 [NORMAL_TEMPORARY_FAILURE]

日志解读

日志项 值 说明
通道名称 sofia/external/8000@-err ⚠️ 异常:目标地址为 -err
状态转换 calling → terminated SIP 503 响应
挂断原因 NORMAL_TEMPORARY_FAILURE 错误码 41
SIP 响应码 503 Service Unavailable

核心问题

目标地址解析失败: @-err 表示无法从 distributor/dispatcher 获取正确的 core 服务器地址。


问题根源

架构说明

在分布式 FreeSWITCH 架构中:

  • FreeSWITCH: 呼叫处理引擎
  • Distributor: 负载均衡器,分配呼叫到不同 core
  • Dispatcher: 存储 core 服务器的 IP 地址和端口
  • RCS: 配置管理服务

正常流程:

1
2
3
4
webclient → FreeSWITCH → Distributor → Dispatcher → Core SIP 服务器
↓
获取 core IP:端口
(如 192.168.1.100:5060)

异常流程:

1
2
3
webclient → FreeSWITCH → Distributor → Dispatcher
↓
失败,返回 -err

排查步骤

步骤 1: 检查 distributor.conf.xml

Pasted image 20260128171549

文件位置:

1
/usr/local/freeswitch/conf/autoload_configs/distributor.conf.xml

检查内容:

1
2
3
4
5
6
7
8
<configuration name="distributor.conf" description="Distributor Configuration">
<lists>
<!-- 检查是否有 core 列表配置 -->
<list name="core">
<node name="core1" weight="10"/> <!-- 权重 10 -->
</list>
</lists>
</configuration>

检查命令:

1
2
3
4
5
# 查看配置文件
cat /usr/local/freeswitch/conf/autoload_configs/distributor.conf.xml | grep -A 5 "list name"

# 或在 fs_cli 中查看
fs_cli -x "distributor_dump_list core"

预期输出:

1
2
3
4
# 正常情况应该显示 core 列表
List: core
Nodes: 1
- core1 (weight: 10, state: ACTIVE)

步骤 2: 检查数据库配置

表: t_conf

SQL 查询:

1
2
3
4
5
-- 查看 distributor 配置
SELECT * FROM t_conf WHERE conf_key LIKE '%distributor%';

-- 查看 core IP 配置
SELECT * FROM t_conf WHERE conf_key LIKE '%core%';

关键字段:

  • conf_key: 配置键名
  • conf_value: 配置值
  • conf_type: 配置类型

预期结果:

1
2
3
4
5
6
conf_key              | conf_value
-----------------------|-------------------
distributor.core.list | core1
core.core1.ip | 192.168.1.100
core.core1.port | 5060
core.core1.weight | 10

步骤 3: 检查 Core 服务状态

方法 1: 检查进程

1
2
3
4
5
# 查看 FreeSWITCH 进程
ps aux | grep freeswitch

# 或使用 systemd
systemctl status freeswitch

方法 2: 检查端口监听

1
2
3
4
5
# 检查 SIP 端口 (5060)
netstat -tuln | grep 5060

# 或使用 ss
ss -tuln | grep 5060

预期输出:

1
udp  0  0  0.0.0.0:5060  0.0.0.0:*  LISTEN

方法 3: 检查 SIP 注册

1
2
3
4
5
# 在 fs_cli 中查看注册状态
fs_cli -x "sofia status profile external reg"

# 或查看在线网关
fs_cli -x "sofia status gateway"

步骤 4: 检查 Dispatcher 表

表: dispatcher

SQL 查询:

1
2
3
4
5
6
7
8
-- 查看 dispatcher 表结构
DESC dispatcher;

-- 查看所有 dispatcher 记录
SELECT * FROM dispatcher;

-- 查看 core 相关记录
SELECT * FROM dispatcher WHERE set_name = 'core';

预期结果:

1
2
3
4
id | set_name |     tuple     | flags  | weight
---|----------|---------------|--------|--------
1 | core | 192.168.1.100:5060 | 0 | 10
2 | core | 192.168.1.101:5060 | 0 | 10

关键字段:

  • set_name: 集合名称(如 “core”)
  • tuple: IP 地址和端口(格式:IP:PORT)
  • flags: 标志位
  • weight: 权重

步骤 5: 重启 Core 服务

如果 dispatcher 表中有 core 地址,但配置未生效:

方法 1: 重启 FreeSWITCH

1
2
3
4
5
6
7
8
9
10
11
# 停止服务
systemctl stop freeswitch

# 启动服务
systemctl start freeswitch

# 查看状态
systemctl status freeswitch

# 或使用 service 命令
service freeswitch restart

方法 2: 在 fs_cli 中重载

1
2
3
4
5
6
7
8
# 重新加载 XML 配置
fs_cli -x "reloadxml"

# 重新加载 distributor 模块
fs_cli -x "reload mod_distributor"

# 重新加载 Sofia SIP 模块
fs_cli -x "reload mod_sofia"

方法 3: 重启 RCS 服务

1
2
3
4
5
# 如果使用了 RCS 配置服务
systemctl restart rcs

# 或
service rcs restart

步骤 6: 验证修复

测试 Distributor 功能:

1
2
3
4
5
6
7
8
# 在 fs_cli 中测试 distributor
fs_cli -x "distributor_dump_list core"

# 查看可用的节点
fs_cli -x "distributor_ready_nodes core"

# 模拟分配节点
fs_cli -x "distributor_intrulate core"

发起测试呼叫:

1
2
3
4
5
# 使用 originate 测试
fs_cli -x "originate user/1000 &echo"

# 或测试外呼
fs_cli -x "originate sofia/external/8000@192.168.1.100 &echo"

检查通道名称:

1
2
3
4
5
6
# 查看活动通道
fs_cli -x "show channels"

# 通道名称应该类似:
# sofia/external/8000@192.168.1.100:5060 ✅ 正常
# sofia/external/8000@-err ❌ 异常

常见场景与解决方案

场景 1: Dispatcher 表为空

现象:

1
2
SELECT * FROM dispatcher;
-- Empty set (0.00 sec)

解决:

1
2
3
4
5
6
7
8
9
10
-- 插入 core 服务器记录
INSERT INTO dispatcher (set_name, tuple, flags, weight)
VALUES ('core', '192.168.1.100:5060', 0, 10);

-- 插入多个 core(负载均衡)
INSERT INTO dispatcher (set_name, tuple, flags, weight)
VALUES
('core', '192.168.1.100:5060', 0, 10),
('core', '192.168.1.101:5060', 0, 10),
('core', '192.168.1.102:5060', 0, 10);

场景 2: Distributor 配置文件缺失

现象:

1
2
cat /usr/local/freeswitch/conf/autoload_configs/distributor.conf.xml
# 文件为空或不存在

解决: 创建或编辑配置文件

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0"?>
<configuration name="distributor.conf" description="Distributor Configuration">
<lists>
<list name="core">
<node name="core1" weight="10"/>
<node name="core2" weight="10"/>
<node name="core3" weight="10"/>
</list>
</lists>
</configuration>

重载配置:

1
2
fs_cli -x "reloadxml"
fs_cli -x "reload mod_distributor"

场景 3: Core 服务未启动

现象:

1
2
3
4
5
ps aux | grep freeswitch
# 没有 FreeSWITCH 进程

netstat -tuln | grep 5060
# 端口未监听

解决:

1
2
3
4
5
6
7
8
# 启动 FreeSWITCH
systemctl start freeswitch

# 检查状态
systemctl status freeswitch

# 查看日志
tail -f /usr/local/freeswitch/log/freeswitch.log

场景 4: 数据库连接失败

现象: Distributor 无法从数据库读取配置

检查数据库连接:

1
2
3
4
5
# 测试数据库连接
mysql -u root -p -h localhost

# 查看 FreeSWITCH 数据库配置
cat /usr/local/freeswitch/conf/autoload_configs/odbc.conf.xml

解决:

1
2
3
4
5
6
<!-- 确保 odbc.conf.xml 配置正确 -->
<configuration name="odbc.conf" description="ODBC Configuration">
<settings>
<param name="odbc-dsn" value="freeswitch:root:123456"/>
</settings>
</configuration>

场景 5: RCS 服务配置不同步

现象: Dispatcher 和数据库配置不一致

解决:

1
2
3
4
5
6
7
8
9
10
11
# 1. 重启 RCS 服务
systemctl restart rcs

# 2. 清理缓存
fs_cli -x "distributor_flush_cache core"

# 3. 重新加载数据
fs_cli -x "distributor_reload core"

# 4. 验证
fs_cli -x "distributor_dump_list core"

调试技巧

实时日志监控

1
2
3
4
5
6
7
8
9
10
11
# 开启详细日志
fs_cli -x "console loglevel 7"

# 只看 distributor 相关
tail -f /usr/local/freeswitch/log/freeswitch.log | grep -i distributor

# 只看 sofia 外呼相关
tail -f /usr/local/freeswitch/log/freeswitch.log | grep "sofia/external"

# 查看错误
tail -f /usr/local/freeswitch/log/freeswitch.log | grep -i "error\|fail\|err"

测试单个组件

测试 Distributor:

1
2
3
4
5
6
7
8
# 查看所有列表
fs_cli -x "distributor_dump_all"

# 查看特定列表
fs_cli -x "distributor_dump_list core"

# 查看可用节点
fs_cli -x "distributor_ready_nodes core"

测试 Dispatcher:

1
2
3
4
5
-- OpenSIPS dispatcher 测试
opensipsctl fifo dispatcher_dump

-- Kamailio dispatcher 测试
kamctl dispatcher dump

测试 Core 连通性:

1
2
3
4
5
# SIP OPTIONS ping
fs_cli -x "sofia global siprip on"

# 或使用 sipsak
sipsak -I -s sip:core@192.168.1.100:5060

预防措施

1. 配置监控

监控脚本示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# monitor_distributor.sh

# 检查 dispatcher 表
COUNT=$(mysql -u root -p123456 freeswitch -se "SELECT COUNT(*) FROM dispatcher WHERE set_name='core'")

if [ $COUNT -eq 0 ]; then
echo "WARNING: No core servers in dispatcher table"
# 发送告警
# send_alert "Dispatcher table empty"
fi

# 检查 distributor 节点
NODES=$(fs_cli -x "distributor_ready_nodes core" | grep "Nodes:" | awk '{print $2}')

if [ $NODES -eq 0 ]; then
echo "ERROR: No ready nodes in distributor"
# 发送告警
# send_alert "No distributor nodes ready"
fi

Cron 定时任务:

1
2
# 每 5 分钟检查一次
*/5 * * * * /usr/local/bin/monitor_distributor.sh

2. 健康检查

添加到 crontab:

1
2
3
4
5
# 每分钟检查 FreeSWITCH 进程
* * * * * pgrep -f freeswitch || systemctl start freeswitch

# 每分钟检查端口监听
* * * * * netstat -tuln | grep 5060 || /usr/local/bin/restart_core.sh

3. 自动恢复

自动恢复脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# auto_recovery.sh

LOG_FILE="/var/log/fs_recovery.log"

function log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> $LOG_FILE
}

# 检查 dispatcher
DISPATCHER_COUNT=$(mysql -u root -p123456 freeswitch -se "SELECT COUNT(*) FROM dispatcher WHERE set_name='core'")

if [ $DISPATCHER_COUNT -eq 0 ]; then
log "ERROR: Dispatcher table empty, attempting recovery..."

# 从配置文件或数据库恢复
mysql -u root -p123456 freeswitch <<EOF
INSERT INTO dispatcher (set_name, tuple, flags, weight)
VALUES ('core', '192.168.1.100:5060', 0, 10)
ON DUPLICATE KEY UPDATE tuple='192.168.1.100:5060';
EOF

log "Recovery complete, restarting services..."
systemctl restart rcs
systemctl restart freeswitch
fi

# 检查 FreeSWITCH
if ! pgrep -f freeswitch > /dev/null; then
log "ERROR: FreeSWITCH not running, starting..."
systemctl start freeswitch
fi

快速诊断流程图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
外呼失败
|
├─ 查看日志,通道名称是否包含 @-err?
| ├─ 是 → 继续排查
| └─ 否 → 其他问题
|
├─ 检查 distributor.conf.xml
| ├─ 有 core 配置?
| | ├─ 是 → 检查数据库
| | └─ 否 → 添加配置并重载
|
├─ 检查数据库 t_conf 表
| ├─ 有 core 配置?
| | ├─ 是 → 检查 dispatcher 表
| | └─ 否 → 更新配置
|
├─ 检查 dispatcher 表
| ├─ 有 core IP?
| | ├─ 是 → 检查 core 服务
| | └─ 否 → 插入记录
|
├─ 检查 core 服务状态
| ├─ 运行中?
| | ├─ 是 → 重启 RCS
| | └─ 否 → 启动服务
|
└─ 验证修复
├─ fs_cli -x "distributor_dump_list core"
└─ 发起测试呼叫

常用命令速查

Distributor 相关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 查看所有列表
fs_cli -x "distributor_dump_all"

# 查看特定列表
fs_cli -x "distributor_dump_list core"

# 查看可用节点
fs_cli -x "distributor_ready_nodes core"

# 清理缓存
fs_cli -x "distributor_flush_cache core"

# 重新加载
fs_cli -x "distributor_reload core"

数据库查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- 查看所有配置
SELECT * FROM t_conf;

-- 查看 distributor 配置
SELECT * FROM t_conf WHERE conf_key LIKE '%distributor%';

-- 查看 dispatcher 表
SELECT * FROM dispatcher WHERE set_name = 'core';

-- 插入 core 记录
INSERT INTO dispatcher (set_name, tuple, flags, weight)
VALUES ('core', '192.168.1.100:5060', 0, 10);

-- 更新 core 记录
UPDATE dispatcher
SET tuple = '192.168.1.100:5060'
WHERE set_name = 'core' AND id = 1;

-- 删除记录
DELETE FROM dispatcher WHERE set_name = 'core' AND id = 1;

服务管理

1
2
3
4
5
6
7
8
9
10
# FreeSWITCH
systemctl start|stop|restart|status freeswitch

# RCS
systemctl start|stop|restart|status rcs

# 重载配置
fs_cli -x "reloadxml"
fs_cli -x "reload mod_distributor"
fs_cli -x "reload mod_sofia"

相关文档


相关错误码

错误码 原因 说明
41 NORMAL_TEMPORARY_FAILURE 临时性失败,通常由服务不可用引起
404 NOT_FOUND 用户不存在
486 BUSY_HERE 用户忙
487 REQUEST_TERMINATED 请求被终止
503 SERVICE_UNAVAILABLE 服务不可用

总结

核心要点:

  1. @-err 后缀表示 distributor 无法获取正确的 core 地址
  2. 排查顺序:配置文件 → 数据库 → dispatcher 表 → 服务状态
  3. 大部分情况通过重启 RCS 或 FreeSWITCH 可以解决
  4. 建议配置监控和自动恢复脚本

关键检查项:

  • ✅ distributor.conf.xml 有 core 配置
  • ✅ 数据库 t_conf 表有 core 配置
  • ✅ dispatcher 表有 core IP 记录
  • ✅ FreeSWITCH 服务运行正常
  • ✅ RCS 服务运行正常

© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!