外呼失败-NORMAL_TEMPORARY_FAILURE
问题现象
使用 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]
|
日志解读
核心问题
目标地址解析失败: @-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

文件位置:
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> <list name="core"> <node name="core1" weight="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 -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
| SELECT * FROM t_conf WHERE conf_key LIKE '%distributor%';
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
| ps aux | grep freeswitch
systemctl status freeswitch
|
方法 2: 检查端口监听
1 2 3 4 5
| netstat -tuln | grep 5060
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 -x "sofia status profile external reg"
fs_cli -x "sofia status gateway"
|
步骤 4: 检查 Dispatcher 表
表: dispatcher
SQL 查询:
1 2 3 4 5 6 7 8
| DESC dispatcher;
SELECT * FROM dispatcher;
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 freeswitch restart
|
方法 2: 在 fs_cli 中重载
1 2 3 4 5 6 7 8
| fs_cli -x "reloadxml"
fs_cli -x "reload mod_distributor"
fs_cli -x "reload mod_sofia"
|
方法 3: 重启 RCS 服务
1 2 3 4 5
| systemctl restart rcs
service rcs restart
|
步骤 6: 验证修复
测试 Distributor 功能:
1 2 3 4 5 6 7 8
| 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
| 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"
|
常见场景与解决方案
场景 1: Dispatcher 表为空
现象:
1 2
| SELECT * FROM dispatcher;
|
解决:
1 2 3 4 5 6 7 8 9 10
| INSERT INTO dispatcher (set_name, tuple, flags, weight) VALUES ('core', '192.168.1.100:5060', 0, 10);
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
netstat -tuln | grep 5060
|
解决:
1 2 3 4 5 6 7 8
| 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
cat /usr/local/freeswitch/conf/autoload_configs/odbc.conf.xml
|
解决:
1 2 3 4 5 6
| <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
| systemctl restart rcs
fs_cli -x "distributor_flush_cache core"
fs_cli -x "distributor_reload core"
fs_cli -x "distributor_dump_list core"
|
调试技巧
实时日志监控
1 2 3 4 5 6 7 8 9 10 11
| fs_cli -x "console loglevel 7"
tail -f /usr/local/freeswitch/log/freeswitch.log | grep -i distributor
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
| opensipsctl fifo dispatcher_dump
kamctl dispatcher dump
|
测试 Core 连通性:
1 2 3 4 5
| fs_cli -x "sofia global siprip on"
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
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" fi
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" fi
|
Cron 定时任务:
1 2
| */5 * * * * /usr/local/bin/monitor_distributor.sh
|
2. 健康检查
添加到 crontab:
1 2 3 4 5
| * * * * * 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
LOG_FILE="/var/log/fs_recovery.log"
function log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> $LOG_FILE }
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
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;
SELECT * FROM t_conf WHERE conf_key LIKE '%distributor%';
SELECT * FROM dispatcher WHERE set_name = 'core';
INSERT INTO dispatcher (set_name, tuple, flags, weight) VALUES ('core', '192.168.1.100:5060', 0, 10);
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
| systemctl start|stop|restart|status freeswitch
systemctl start|stop|restart|status rcs
fs_cli -x "reloadxml" fs_cli -x "reload mod_distributor" fs_cli -x "reload mod_sofia"
|
相关文档
相关错误码
总结
核心要点:
@-err 后缀表示 distributor 无法获取正确的 core 地址
- 排查顺序:配置文件 → 数据库 → dispatcher 表 → 服务状态
- 大部分情况通过重启 RCS 或 FreeSWITCH 可以解决
- 建议配置监控和自动恢复脚本
关键检查项:
- ✅ distributor.conf.xml 有 core 配置
- ✅ 数据库 t_conf 表有 core 配置
- ✅ dispatcher 表有 core IP 记录
- ✅ FreeSWITCH 服务运行正常
- ✅ RCS 服务运行正常