问题描述

OpenSIPS 启动时报错:

1
parse error in config file /usr/local//etc/opensips/opensips.cfg, line 400, column 33-34: syntax error

配置错误截图

错误现象

关键错误日志

1
2
3
4
Jan  8 15:01:33 [303] CRITICAL:core:yyerror: parse error in config file /usr/local//etc/opensips/opensips.cfg, line 400, column 33-34: syntax error
Jan 8 15:01:33 [303] CRITICAL:core:yyerror: parse error in config file /usr/local//etc/opensips/opensips.cfg, line 400, column 33-34: bad argument (string or integer expected)
Jan 8 15:01:33 [303] CRITICAL:core:yyerror: parse error in config file /usr/local//etc/opensips/opensips.cfg, line 846, column 33-34: syntax error
Jan 8 15:01:33 [303] ERROR:core:main: bad config file (4 errors)

完整启动日志

1
2
3
4
5
6
7
8
9
10
this is in k8s, use rcs, rcs:8080
get edge nodeInfo
ERROR get node publicIP failed
edge nodeInfo 192.168.90.12
build opensips.cfg from /usr/local/etc/opensips/opensips.m4
CF_CLUSTER is
start check opensips.cfg
Jan 8 15:01:33 [303] CRITICAL:core:yyerror: parse error in config file /usr/local//etc/opensips/opensips.cfg, line 400, column 33-34: syntax error
Jan 8 15:01:33 [303] ERROR:core:main: bad config file (4 errors)
Jan 8 15:01:33 [303] NOTICE:core:main: Exiting....

原因分析

问题代码对比

1
2
3
4
5
# ❌ 错误:port 参数为空
set_advertised_port();

# ✅ 正常:port 有值
set_advertised_port(18627);

根本原因

配置文件生成时,从 node_address 表获取 Edge 节点信息失败:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
┌─────────────────┐     ┌─────────────────┐
│ opensips.m4 │────>│ 生成 opensips.cfg│
└─────────────────┘ └────────┬────────┘
│
│ 获取 Edge 信息
▼
┌─────────────────┐
│ node_address 表 │
└────────┬────────┘
│
┌────────────┴────────────┐
│ │
▼ ▼
✅ 有 Edge 数据 ❌ 没有 Edge 数据
│ │
▼ ▼
set_advertised_port(18627) set_advertised_port()
│ │
▼ ▼
启动成功 ❌ 语法错误

日志显示:

1
2
ERROR get node publicIP failed
edge nodeInfo 192.168.90.12

说明获取 Edge 节点的公网 IP 失败。

解决方案

1. 检查 node_address 表

1
2
3
4
-- 查看 node_address 表中是否有 Edge 数据
SELECT id, node_ip, public_ip, node_name, node_state
FROM node_address
WHERE node_name LIKE '%edge%';

2. 按 IP 查询节点信息

1
2
3
4
-- 查询特定 IP 的节点信息
SELECT id, node_ip, public_ip, node_name, node_state
FROM node_address
WHERE node_ip = '192.168.90.12';

3. 添加缺失的 Edge 节点

如果查询结果为空,需要手动添加 Edge 节点:

4. 验证配置

1
2
3
4
5
6
7
8
9
# 重新生成配置文件
cd /usr/local/etc/opensips/
m4 opensips.m4 > opensips.cfg

# 检查配置文件语法
opensips -c

# 重启 OpenSIPS
opensipsctl restart

排查步骤

1. 查看日志中的关键信息

1
2
3
4
5
# 查找 Edge 节点信息获取失败的日志
grep "ERROR get node publicIP failed" /var/log/opensips.log

# 查找配置文件生成相关日志
grep "build opensips.cfg" /var/log/opensips.log

2. 检查生成的配置文件

1
2
3
4
5
# 查看报错行附近的内容
sed -n '395,405p' /usr/local/etc/opensips/opensips.cfg

# 搜索 set_advertised_port 调用
grep -n "set_advertised_port" /usr/local/etc/opensips/opensips.cfg

3. 检查 M4 模板

1
2
# 查看 opensips.m4 中的相关定义
grep -A 5 "set_advertised_port" /usr/local/etc/opensips/opensips.m4

预防措施

1. 部署前检查

在 K8s 环境部署 OpenSIPS 前确保:

  • node_address 表已配置所有节点的信息
  • Edge 节点信息完整(包含 node_ip 和 public_ip)

2. 启动脚本增强

在启动脚本中添加检查:

1
2
3
4
5
6
7
8
# 检查 Edge 节点信息是否存在
EDGE_COUNT=$(mysql -u$user -p$pass -D$database -sse \
"SELECT COUNT(*) FROM node_address WHERE node_name LIKE '%edge%'")

if [ "$EDGE_COUNT" -eq 0 ]; then
echo "ERROR: No edge node found in node_address table"
exit 1
fi

相关知识

set_advertised_port

  • 用途:设置对外宣告的端口(用于 NAT 场景)
  • 语法:set_advertised_port(port)
  • 参数:必须是有效的端口号(整数或字符串)

node_address 表

字段 说明
id 主键
node_ip 节点内网 IP
public_ip 节点公网 IP
node_name 节点名称(edge/core 等)
node_state 节点状态

参考资料


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

站内搜索

没有找到内容!