如何在Linux上为Firebird收集转储文件并生成堆栈跟踪
简介
当 Firebird 出现严重问题(如挂起或异常终止)时,需要配置转储收集,然后创建堆栈跟踪。借助转储和堆栈跟踪,IBSurgeon 的 Firebird 核心开发人员可以分析挂起/故障的详细情况并提供解决方案。
| 转储和堆栈跟踪分析是 IBSurgeon 提供的 Firebird 高级技术支持服务的一部分。我们的方案起价为 199 美元/服务器/月,包括通过聊天(WhatsApp、Telegram 等)提供支持,因此在出现严重问题时,您几乎可以立即获得专业帮助。 详情请访问:/zh/enterprise-subscription-plans-for-firebird/ |
| 以下所有操作都需要 root 或 sudoer 权限。 |
1. 前提条件
1.1 删除或停止干扰包
Ubuntu/Debian
- systemd-coredump
apt-get purge --auto-remove systemd-coredump
验证删除:
cat /proc/sys/kernel/core_pattern
不应出现类似输出:
/lib/systemd/systemd-coredump%P %u %g %s %t %e
- apport
# 搜索
service --status-all | grep -m1 -i apport
# 模拟删除
apt-get -s remove apport
# 删除
sudo apt-get remove apport
# 清理剩余文件
sudo apt-get purge apport
CentOS/RedHat
- abrtd
检查:
cat /proc/sys/kernel/core_pattern
如果看到类似输出:
/usr/libexec/abrt-hook-ccpp %s %c %p %u %g%t e %P %I
停止并删除 abrtd:
对于 CentOS 6:
service abrtd stop
对于 CentOS 7:
systemctl disable abrtd.service
删除:
yum -y remove abrt*
# 清理剩余文件
rm -r /var/cache/abrt/
# 验证清理
cat /var/log/yum.log | grep abrt
1.2 安装 GDB
| 需要 GDB 来从收集的转储中创建堆栈跟踪。安装 GDB 不会影响性能,也不会将 Firebird 置于“调试”模式。 |
对于 CentOS:
yum install gdb
对于 Ubuntu/Debian:
apt-get install gdb
2. 移除转储大小限制
检查当前转储大小限制:
ulimit -c
如果看到 0,则表示禁止创建转储。
对于使用 systemd 的系统,修改服务文件:
CentOS/RedHat
/usr/lib/systemd/system/firebird-superserver.service
Ubuntu/Debian
/lib/systemd/system/firebird-superserver.service
在 [Service] 部分添加:
LimitCORE=infinity
重启服务:
systemctl daemon-reload
systemctl restart firebird-superserver.service
验证无限制转储大小:
strings /proc/$(pgrep firebird)/limits
3. 配置转储文件位置和命名
| 此步骤是可选的,但强烈建议指定有意义的转储文件名并确保有足够的存储空间。 |
临时配置
sysctl -w kernel.core_pattern=/path/to/dumps/core.%e.%t.%p
永久配置
添加到 /etc/sysctl.conf:
kernel.core_pattern=/path/to/dumps/core.%e.%t.%p
设置所有权
chown firebird /path/to/dumps -R
4. 测试转储收集
前提条件
-
重启 SSH
-
验证
ulimit -c返回 “unlimited”
测试崩溃命令
Firebird 3+(SuperServer 或 SuperClassic)
echo "shell kill -6 $(pgrep firebird);" | /opt/firebird/bin/isql -q localhost:employee -user sysdba -pas masterkey
Firebird 2.5(SuperClassic)
echo "shell kill -6 $(pgrep fb_smp_server);" | /opt/firebird/bin/isql -q localhost:employee -user sysdba -pas masterkey
Classic 模式
select mon$server_pid from mon$attachments where mon$attachment_id = current_connection;
shell kill -6 <找到的PID>;
5. 安装调试文件
| - 调试文件必须与您的 Firebird 构建版本匹配 - 安装调试文件不会影响性能 - 更新 Firebird 时需更新调试文件 |
预期的调试文件位置:
/opt/firebird/bin/.debug/firebird.debug
/opt/firebird/bin/.debug/gbak.debug
/opt/firebird/bin/.debug/isql.debug
/opt/firebird/lib/.debug/libfbclient.so.3.0.11.debug
/opt/firebird/lib/.debug/libib_util.so.debug
/opt/firebird/plugins/.debug/libfbtrace.so.debug
/opt/firebird/plugins/.debug/libEngine12.so.debug
| HQbird 安装包含正确的调试文件并自动处理更新。 |
6. 从运行中的进程创建堆栈跟踪
- 创建
gdb-commands.txt:
thread apply all bt
quit
yes
- 生成堆栈跟踪:
gdb -q -x ./gdb-commands.txt /opt/firebird/bin/firebird $(pgrep firebird) 1>./stacktrace.txt 2>&1
7. 从运行中的进程创建转储
gcore -o /path/to/dumps/firebirdprefix $(pgrep firebird)
| 该工具会将进程 ID 附加到前缀后面。 |
8. 从现有转储创建堆栈跟踪
gdb -q -x ./gdb-commands.txt /opt/firebird/bin/firebird /tmp/core.firebird.23041 1>./stacktrace1.txt 2>&1
9. 深度转储分析
要分析共享库:
echo -e "info sharedlibrary\nquit\n" | gdb