Ceph 14.2.22:如何调试使用ceph-deploy工具部署的集群

← 返回主页

1. 前言

ceph-deploy 默认使用官方发布的 Ceph 安装包来搭建集群,如果想要调试这种集群,有两种方法。第一种方法是安装官方发布的对应的 dbg 包。第二种方法是使用本地编译出来的二进制文件和动态库进行相应的替换。对于后者而言,要确保对应的源码也应该在同一台机器上。

本文将着重介绍如何在 ubuntu 18.04 中使用替换二进制方法来调试使用 ceph-deploy 部署的 Ceph 集群,Ceph 版本为 14.2.22。这种方法需要编译 Ceph 源码,本文不再赘述,详细请参考 如何编译 Ceph 源码

2. 集群部署

本文需要调试文件系统方面的功能,因此需要提前搭建好文件系统集群,详细部署教程可以参考 Ceph 集群部署

3. 调试

3.1. 替换二进制文件和动态库文件

在安装 Ceph 时,默认把 Ceph 相关的二进制文件安装到 /usr/bin,把 Ceph 相关的动态库安装到 /usr/lib 中。而编译 Ceph 源码时生成的二进制文件放在了 build/bin 目录下,动态库文件放在了 build/lib 目录下。本文需要调试文件系统 mds 管理元数据功能,只需要替换与 mds 相关的二进制文件以及动态库文件。

3.2. 查看 mds 进程号

ps -e| grep ceph-mds
----------------------
15201 ?		00:29:32 ceph-mds

从结果可以看到 mds 进程号为 15201

3.3. GDB 调试

3.3.1. 进入 gdb 模式

gdb 调试需要以管理员权限,本文默认是 root 用户,所以直接输入 gdb 即可进入 gdb 模式。

gdb
-----
GNU gdb (Ubuntu 7 .11.1- 0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc .
L icense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type " show copying"
and” show warranty" for details.
This GDB was configured as "x86_64-1inux-gnu".
Type "show conf iguration" for configuration details.
For bug reporting instructions, pLease see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)

3.3.2. attach mds 进程

(gdb) attach 15201
--------------------
Attaching to process 15201
[New LWP 15203]
[New LWP 15204]
[New LWP 15205]
[New LWP 15206]
[New LWP 15211]
[New LWP 15212]
[New LWP 15213]
[New LWP 15214]
[New LWP 15215]
[New LWP 15216]
[New LWP 15217]
[New LWP 15218]
[New LWP 15219]
[New LWP 15220]
[New LWP 15223]
[New LWP 15224]
[New LWP 15225]
[New LWP 15226]
[New LWP 15227]
[New LWP 15228]
[New LWP 15229]
[New LWP 15231]
[Thread debugging using libthread_db enabled]
Using host libthread db library "/1ib/x86_64-linux-gnu/libthread_db.so.1" .
pthread_cond_wait@aGLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
185		../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: No such file or directory.
(gdb)

3.3.3. 设置断点

因为需要调试新建目录时,mds 对元数据的管理,因此断点设置在 Server::handle_client_mkdir 起始处。

(gdb) b Server.cc:5913
Breakpoint 1 at 0x56086dc98df6: file /work/ceph-14.2.22/src/mds/Server.cc, line 5913.

设置完断点后,执行 continue。

(gdb) c
Continuing.

3.3.4. 测试

在挂载出来的文件系统目录下,新建一个目录,代码会跳到之前设置的断点处。

Thread 9 "ms_dispatch" hit Breakpoint 1, Server::handle_client_mkdir (this=0x560870f16dc0, mdr=...)
at /work/ceph-14.2.22/src/mds/Server.cc:5914
5914	{
(gdb) n
5915	const MClientRequest::const_ref &req = mdr->client_request;

从上面结果可以看到,新建一个目录时,函数停在代码的 5914 行,现在就可以使用 gdb 命令进行代码调试,和正常调试代码一样。