fs_cli 连接问题排查
📋 问题现象
错误信息
执行 fs_cli 命令时报错:
1 2 3
| ./fs_cli -p ClueCon [ERROR] fs_cli.c:1691 main() Error Connecting [] Usage: ./fs_cli [-H <host>] [-P <port>] [-p <secret>] [-d <level>] [-x command] [-t <timeout_ms>] [profile]
|
关键特征
- ❌ Error Connecting: 连接 FreeSWITCH 服务器失败
- ❌ Usage 提示: 显示命令使用方法
- ✅ fs_cli 文件存在: 命令可以执行
- ✅ FreeSWITCH 正在运行: 服务状态正常
🔍 问题根源
为什么无法连接?
常见原因:
默认配置
FreeSWITCH 默认 ESL 配置:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <configuration name="event_socket.conf" description="Socket Client"> <settings> <param name="listen-ip" value="0.0.0.0"/>
<param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/> </settings> </configuration>
|
✅ 解决步骤
步骤 1: 确认错误原因
查看完整错误信息:
1 2 3 4 5 6
| /usr/local/freeswitch/bin/fs_cli
|
错误分析:
Error Connecting []: 方括号内为空,说明连接参数不正确
- 可能原因: 端口错误、密码错误或 host 错误
步骤 2: 检查 event_socket 配置
查看 ESL 配置文件:
1 2
| cat /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml
|
配置文件示例:
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
| <configuration name="event_socket.conf" description="Socket Client"> <settings> <param name="listen-ip" value="0.0.0.0"/>
<param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/>
<param name="apply-inbound-acl" value="lan"/>
</settings> </configuration>
|
关键配置说明:
⚠️ 注意: 如果你修改了这些配置,需要使用新值连接。
步骤 3: 使用正确的参数连接
基本语法:
1 2 3 4 5 6 7 8 9
| /usr/local/freeswitch/bin/fs_cli [options]
|
示例 1: 使用自定义端口和密码
1 2 3 4 5
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword
|
示例 2: 指定 host 连接
1 2 3 4 5
| /usr/local/freeswitch/bin/fs_cli -H 192.168.1.100 -P 8021 -p ClueCon
/usr/local/freeswitch/bin/fs_cli -H freeswitch.example.com -P 8021 -p ClueCon
|
示例 3: 执行单条命令
1 2 3 4 5 6 7 8
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "status"
/usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "show channels"
/usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "reloadxml;sofia status"
|
示例 4: 设置超时时间
1 2 3 4
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -t 5000
|
步骤 4: 验证连接成功
检查是否成功进入 fs_cli:
1 2 3 4 5 6 7 8 9 10 11 12 13
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword
freeswitch@internal> status freeswitch@internal> show channels freeswitch@internal> reloadxml
freeswitch@internal> /exit
|
测试常用命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| status
version
sofia status profile internal reg
show channels
reloadxml
/exit
|
步骤 5: 创建便捷连接脚本
创建简化连接脚本:
1 2 3 4 5 6 7 8 9 10 11
| vim /usr/local/bin/fs
/usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword "$@"
|
设置执行权限:
1 2 3 4 5 6 7 8
| chmod +x /usr/local/bin/fs
fs
fs -x "status"
|
步骤 6: 检查 event_socket 模块
确认 mod_event_socket 已加载:
1 2 3 4 5 6 7 8 9
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "module_exists mod_event_socket"
/usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "show modules" | grep event_socket
|
如果模块未加载,手动加载:
1 2 3 4 5 6 7
| /usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "load mod_event_socket"
freeswitch@internal> load mod_event_socket
|
确认模块自动加载:
1 2 3 4 5
| cat /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml | grep event_socket
|
步骤 7: 检查端口监听
检查 ESL 端口是否监听:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| netstat -tuln | grep 8021
netstat -tuln | grep 5
ss -tuln | grep 8021
lsof -i :8021
|
如果端口未监听:
1 2 3 4 5 6 7 8 9 10 11
| cat /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml
/usr/local/freeswitch/bin/fs_cli -P 5 -p newPassword -x "reload mod_event_socket"
systemctl restart freeswitch
netstat -tuln | grep 8021
|
步骤 8: 检查防火墙
检查防火墙规则:
1 2 3 4 5 6 7 8
| sudo iptables -L -n | grep 8021
sudo firewall-cmd --list-ports | grep 8021
sudo ufw status | grep 8021
|
添加防火墙规则:
1 2 3 4 5 6 7 8 9 10
| sudo iptables -I INPUT -p tcp --dport 8021 -j ACCEPT sudo service iptables save
sudo firewall-cmd --permanent --add-port=8021/tcp sudo firewall-cmd --reload
sudo ufw allow 8021/tcp
|
测试端口连通性:
1 2 3 4 5 6 7 8
| telnet 127.0.0.1 8021
nc -zv 127.0.0.1 8021
|
🚨 常见问题
问题 1: 忘记密码
现象: 修改密码后忘记新密码
解决方案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| vim /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml
<param name="password" value="your_password"/>
/usr/local/freeswitch/bin/fs_cli -x "reloadxml" /usr/local/freeswitch/bin/fs_cli -x "reload mod_event_socket"
systemctl restart freeswitch
/usr/local/freeswitch/bin/fs_cli -p your_password
|
问题 2: 连接超时
现象: 连接请求超时
排查步骤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| systemctl status freeswitch
netstat -tuln | grep 8021
sudo iptables -L -n | grep 8021
telnet 127.0.0.1 8021
/usr/local/freeswitch/bin/fs_cli -t 10000
ping 127.0.0.1
|
问题 3: 权限被拒绝
现象: Permission denied 错误
解决方案:
1 2 3 4 5 6 7 8 9 10 11
| ls -l /usr/local/freeswitch/bin/fs_cli
chmod +x /usr/local/freeswitch/bin/fs_cli
sudo /usr/local/freeswitch/bin/fs_cli
su - freeswitch -c "/usr/local/freeswitch/bin/fs_cli"
|
问题 4: 连接后立即断开
现象: 连接成功但立即断开
排查步骤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| cat /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml | grep acl
cat /usr/local/freeswitch/conf/autoload_configs/acl.conf.xml
<!-- <param name="apply-inbound-acl" value="lan"/> -->
/usr/local/freeswitch/bin/fs_cli -x "reloadxml"
|
问题 5: 多个 FreeSWITCH 实例
现象: 服务器上运行多个 FreeSWITCH 实例
解决方案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| ps aux | grep freeswitch
netstat -tuln | grep freeswitch
/usr/local/freeswitch/bin/fs_cli -P 8021 -p password1
/usr/local/freeswitch/bin/fs_cli -P 8022 -p password2
/usr/local/freeswitch1/bin/fs_cli -P 8021 -p password1 /usr/local/freeswitch2/bin/fs_cli -P 8022 -p password2
|
🔧 高级配置
配置 SSL/TLS 加密连接
启用 event_socket 的 SSL/TLS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <configuration name="event_socket.conf" description="Socket Client"> <settings> <param name="ssl-enable" value="true"/>
<param name="ssl-bind-params" value="transport=tls"/>
<param name="ssl-cert-file" value="/usr/local/freeswitch/certs/agent.pem"/> <param name="ssl-key-file" value="/usr/local/freeswitch/certs/agent.key"/> <param name="ssl-version" value="tlsv1.2"/>
<param name="listen-port" value="8022"/> <param name="password" value="ClueCon"/> </settings> </configuration>
|
使用 SSL 连接:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
vim /etc/stunnel/fs_cli.conf
stunnel /etc/stunnel/fs_cli.conf
/usr/local/freeswitch/bin/fs_cli -P 8023 -p ClueCon
socat - openssl:freeswitch.server.com:8022
|
配置访问控制列表 (ACL)
限制特定 IP 可以连接:
1 2 3 4 5 6 7 8 9 10 11
| <configuration name="acl.conf" description="Access Lists"> <lists> <list name="management" default="deny"> <node type="allow" cidr="192.168.1.0/24"/> <node type="allow" cidr="192.168.0.0/16"/> <node type="allow" cidr="127.0.0.1/32"/> </list> </lists> </configuration>
|
在 event_socket.conf.xml 中应用 ACL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <configuration name="event_socket.conf" description="Socket Client"> <settings> <param name="apply-inbound-acl" value="management"/>
<param name="acl-failed-on-connection-refuse" value="true"/>
<param name="listen-ip" value="0.0.0.0"/> <param name="listen-port" value="8021"/> <param name="password" value="ClueCon"/> </settings> </configuration>
|
重载 ACL 配置:
1 2 3 4 5
| /usr/local/freeswitch/bin/fs_cli -x "reloadacl"
/usr/local/freeswitch/bin/fs_cli -x "reload mod_event_socket"
|
📋 快速诊断流程图
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 33
| fs_cli 连接失败 | ├─ 步骤 1: 检查错误信息 | └─ Error Connecting [] → 参数错误 | ├─ 步骤 2: 检查 event_socket 配置 | └─ cat event_socket.conf.xml | ├─ 记录端口 | └─ 记录密码 | ├─ 步骤 3: 使用正确参数连接 | └─ fs_cli -P <port> -p <password> | ├─ 步骤 4: 检查模块加载 | └─ module_exists mod_event_socket | ├─ 未加载 → load mod_event_socket | └─ 已加载 → 继续 | ├─ 步骤 5: 检查端口监听 | └─ netstat -tuln | grep <port> | ├─ 未监听 → reload mod_event_socket | └─ 已监听 → 继续 | ├─ 步骤 6: 检查防火墙 | └─ iptables -L -n | grep <port> | ├─ 阻止 → 添加防火墙规则 | └─ 允许 → 继续 | ├─ 步骤 7: 测试端口连通性 | └─ telnet 127.0.0.1 <port> | └─ 验证修复 └─ 成功进入 fs_cli
|
📚 相关文档
💡 最佳实践
- 安全配置: 修改默认密码
ClueCon
- 使用脚本: 创建便捷连接脚本简化操作
- 限制访问: 配置 ACL 限制管理 IP
- 启用日志: 设置适当的日志级别便于调试
- 定期备份: 备份 event_socket.conf.xml 配置文件
- 监控连接: 使用监控系统检测 ESL 连接状态
🎯 常用命令速查
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| fs_cli fs_cli -P 8021 -p ClueCon fs_cli -H 192.168.1.100 -P 8021
fs_cli -x "status" fs_cli -x "show channels" fs_cli -x "reloadxml"
fs_cli -x "module_exists mod_event_socket" fs_cli -x "show modules" | grep event_socket
netstat -tuln | grep 8021 lsof -i :8021 telnet 127.0.0.1 8021
sudo iptables -L -n | grep 8021 sudo iptables -I INPUT -p tcp --dport 8021 -j ACCEPT
|
文档版本: v1.0
最后更新: 2026-01-29
维护者: FreeSWITCH 运维团队