searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

ceph mgr和dashboard架构解析

2024-09-04 17:42:32
139
0

一、ceph mgr架构解析

1、mgr的插件放在src/pybind/mgr/下;所有mgr服务启动时身份都是standby,唯一作用是包含一个mgr的client端,获取mgrmap及相关msg。在获取了mgr-map发现自己为当前active时,才会初始化mgr主服务进程。

2、在源码的src/pybind/下的cephfs/、rados/、rbd/和rgw/分别有.pyx文件将C接口转换为python接口,部分模块如dashboard的rbd模块需调用这些接口进行相应操作。

3、在src/mgr/下,定义了mgr相关的类:

1)PyModules包含ActivePyModule、StandbyPyModules、ActivePyModules、BaseMgrModule、BaseMgrStandbyModule、PyModulesRegistry、PyModuleRunner等类,分别处理mgr处于active和standby时对plugins的处理,并在active时初始化python的运行环境,将plugin模块初始化并加载运行。该类大量使用了python的c++扩展接口。PyFormatter类,将C++格式转换为python格式。

2)src/mgr/BaseMgrModule.cc中的BaseMgrModule_methods[]列出了转换为python接口的C++接口,在src/mgr/BaseMgrStandbyModule.cc中也定义了BaseMgrStandbyModule_methods[],src/pybind/mgr/mgr_module.py中的MgrModule类通过继承ceph_module.BaseMgrModule类可直接调用这些C++接口,mgr通过这种方法实现python程序对C++接口的调用。

例如get方法,调用过程为:MgrModule::get()-->BaseMgrModule::_ceph_get() --> ActiveModules::get_python(),在get_python()函数,基于参数值进行判断,调用相应的ceph C++库函数向mon进行数据获取。

3)DaemonServer为mgr主要的服务进程,和osd、mds等类似,初始化了一个mgr类型的Messenger,监听有关mgr消息,主要是MSG_PGSTATS、MSG_MGR_REPORT、MSG_MGR_OPEN、MSG_COMMAND。比如执行‘ceph tell mgr {command}’时就被发送到daemonserver中handle_command函数进行处理(包括了native命令和plugin的commands)。

 

二、dashboard架构解析

1、使用CherryPy作为pyhton web框架;

2、前端使用html和typescript(javascript的超集)编写,代码在src/pybind/mgr/dashboard/frontend/下;

3、开启dashboard:

ceph mgr module enable dashboard

查看开启的mgr服务:

ceph mgr services

4、dashboard后端默认运行在mgr所在地址的8443端口,可以通过如下命令修改,修改后需重启服务才生效:

ceph config set mgr mgr/dashboard/server_addr $IP

ceph config set mgr mgr/dashboard/server_port $PORT

5、通过网页登录http://IP:PORT,需要输入用户名和密码,通过如下命令修改:

ceph dashboard set-login-credentials <username> <password>

6、dashboard启动过程:

1)主要是src/pybind/mgr/dashboard/module.py中的Module类,Module继承了MgrModule类和SSLCherryPyConfig类,MgrModule提供与ceph底层的接口,Module类在初始化时会通过mgr.init(self)初始化_init_.py中的mgr为MgrModule;SSLCherryPyConfig用于配置CherryPy的地址、端口和认证信息;

2)开启dashboard时调用Module类的serve()函数,首先进行CherryPy的初始化,调用SSLCherryPyConfig的await_configuration()生成服务端地址前缀url_prefix,随后调用src/pybind/mgr/dashboard/controllers/_init_.py中的generate_routes(url_prefix)函数,该函数会通过load_controllers()加载controllers/文件夹下所有的模块并将符合条件的模块映射为端口,返回后通过cherrypy.tree.mount(None, config=config)将端口挂载到CherryPy下,最后通过cherrypy.engine.start()启动CherryPy;

3)src/pybind/mgr/dashboard/controllers/下的每个可挂载的模块类都继承自_init_.py中的RESTController类,RESTController映射了几个基本的方法,如下:


 各模块类则实现相应的方法。同时各模块类会用ApiController做修饰,设置路径,而ApiController默认的基础路径是/api,例如:


 合起来就是/api/rbd。

7、curl调用接口:

1)用户认证并保存cookie:

curl -X POST -d username=*** -d password=*** -d stay_signed_in=true -c cookie.txt http://IP:PORT/api/auth

2)查看pool:

curl -b cookie.txt -d pool_name=rbd -X GET http://IP:PORT/api/pool

3)创建pool:

curl -b cookie.txt -d pool=test2 -d pg_num=50 -d pool_type=replicated -X POST http://IP:PORT/api/pool

4)删除pool:

curl -b cookie.txt -X DELETE http://IP:PORT/api/pool/test2

5)查看rbd:

curl -b cookie.txt -d pool_name=rbd -X GET http://IP:PORT/api/block/image

6)创建rbd(mimic版本缺少int(size)处理,因此要直接传整数,而最新版则有):

curl -b cookie.txt -d pool_name=rbd -d name=img-20 -d size=100 -X POST http://IP:PORT/api/block/image

7)删除rbd:

curl -b cookie.txt -X DELETE http://IP:PORT/api/block/image/rbd/img-20

8)查看monitor状态:

curl -b cookie.txt -X GET http://IP:PORT/api/monitor

9)获取集群状态,用于下图:

curl -b cookie.txt -X GET http://IP:PORT/api/dashboard/health


 

10)获取所有osd数据,用于下图:

curl -b cookie.txt -X GET http://IP:PORT/api/osd


 

0条评论
0 / 1000
黄****锐
4文章数
1粉丝数
黄****锐
4 文章 | 1 粉丝
黄****锐
4文章数
1粉丝数
黄****锐
4 文章 | 1 粉丝
原创

ceph mgr和dashboard架构解析

2024-09-04 17:42:32
139
0

一、ceph mgr架构解析

1、mgr的插件放在src/pybind/mgr/下;所有mgr服务启动时身份都是standby,唯一作用是包含一个mgr的client端,获取mgrmap及相关msg。在获取了mgr-map发现自己为当前active时,才会初始化mgr主服务进程。

2、在源码的src/pybind/下的cephfs/、rados/、rbd/和rgw/分别有.pyx文件将C接口转换为python接口,部分模块如dashboard的rbd模块需调用这些接口进行相应操作。

3、在src/mgr/下,定义了mgr相关的类:

1)PyModules包含ActivePyModule、StandbyPyModules、ActivePyModules、BaseMgrModule、BaseMgrStandbyModule、PyModulesRegistry、PyModuleRunner等类,分别处理mgr处于active和standby时对plugins的处理,并在active时初始化python的运行环境,将plugin模块初始化并加载运行。该类大量使用了python的c++扩展接口。PyFormatter类,将C++格式转换为python格式。

2)src/mgr/BaseMgrModule.cc中的BaseMgrModule_methods[]列出了转换为python接口的C++接口,在src/mgr/BaseMgrStandbyModule.cc中也定义了BaseMgrStandbyModule_methods[],src/pybind/mgr/mgr_module.py中的MgrModule类通过继承ceph_module.BaseMgrModule类可直接调用这些C++接口,mgr通过这种方法实现python程序对C++接口的调用。

例如get方法,调用过程为:MgrModule::get()-->BaseMgrModule::_ceph_get() --> ActiveModules::get_python(),在get_python()函数,基于参数值进行判断,调用相应的ceph C++库函数向mon进行数据获取。

3)DaemonServer为mgr主要的服务进程,和osd、mds等类似,初始化了一个mgr类型的Messenger,监听有关mgr消息,主要是MSG_PGSTATS、MSG_MGR_REPORT、MSG_MGR_OPEN、MSG_COMMAND。比如执行‘ceph tell mgr {command}’时就被发送到daemonserver中handle_command函数进行处理(包括了native命令和plugin的commands)。

 

二、dashboard架构解析

1、使用CherryPy作为pyhton web框架;

2、前端使用html和typescript(javascript的超集)编写,代码在src/pybind/mgr/dashboard/frontend/下;

3、开启dashboard:

ceph mgr module enable dashboard

查看开启的mgr服务:

ceph mgr services

4、dashboard后端默认运行在mgr所在地址的8443端口,可以通过如下命令修改,修改后需重启服务才生效:

ceph config set mgr mgr/dashboard/server_addr $IP

ceph config set mgr mgr/dashboard/server_port $PORT

5、通过网页登录http://IP:PORT,需要输入用户名和密码,通过如下命令修改:

ceph dashboard set-login-credentials <username> <password>

6、dashboard启动过程:

1)主要是src/pybind/mgr/dashboard/module.py中的Module类,Module继承了MgrModule类和SSLCherryPyConfig类,MgrModule提供与ceph底层的接口,Module类在初始化时会通过mgr.init(self)初始化_init_.py中的mgr为MgrModule;SSLCherryPyConfig用于配置CherryPy的地址、端口和认证信息;

2)开启dashboard时调用Module类的serve()函数,首先进行CherryPy的初始化,调用SSLCherryPyConfig的await_configuration()生成服务端地址前缀url_prefix,随后调用src/pybind/mgr/dashboard/controllers/_init_.py中的generate_routes(url_prefix)函数,该函数会通过load_controllers()加载controllers/文件夹下所有的模块并将符合条件的模块映射为端口,返回后通过cherrypy.tree.mount(None, config=config)将端口挂载到CherryPy下,最后通过cherrypy.engine.start()启动CherryPy;

3)src/pybind/mgr/dashboard/controllers/下的每个可挂载的模块类都继承自_init_.py中的RESTController类,RESTController映射了几个基本的方法,如下:


 各模块类则实现相应的方法。同时各模块类会用ApiController做修饰,设置路径,而ApiController默认的基础路径是/api,例如:


 合起来就是/api/rbd。

7、curl调用接口:

1)用户认证并保存cookie:

curl -X POST -d username=*** -d password=*** -d stay_signed_in=true -c cookie.txt http://IP:PORT/api/auth

2)查看pool:

curl -b cookie.txt -d pool_name=rbd -X GET http://IP:PORT/api/pool

3)创建pool:

curl -b cookie.txt -d pool=test2 -d pg_num=50 -d pool_type=replicated -X POST http://IP:PORT/api/pool

4)删除pool:

curl -b cookie.txt -X DELETE http://IP:PORT/api/pool/test2

5)查看rbd:

curl -b cookie.txt -d pool_name=rbd -X GET http://IP:PORT/api/block/image

6)创建rbd(mimic版本缺少int(size)处理,因此要直接传整数,而最新版则有):

curl -b cookie.txt -d pool_name=rbd -d name=img-20 -d size=100 -X POST http://IP:PORT/api/block/image

7)删除rbd:

curl -b cookie.txt -X DELETE http://IP:PORT/api/block/image/rbd/img-20

8)查看monitor状态:

curl -b cookie.txt -X GET http://IP:PORT/api/monitor

9)获取集群状态,用于下图:

curl -b cookie.txt -X GET http://IP:PORT/api/dashboard/health


 

10)获取所有osd数据,用于下图:

curl -b cookie.txt -X GET http://IP:PORT/api/osd


 

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0