date: 2021-04-28title: Ceph管理和监控 #标题
tags: ceph #标签
categories: 存储 # 分类
一个ceph集群必不可少的就是监控了,这篇文章来记录下Ceph原生的dashboard以及结合prometheus来进行监控。
Ceph dashboard部署
参考:官方文档。
安装ceph-mgr-dashboard
$ yum -y install ceph-mgr-dashboard
注:ceph集群中的所有mgr节点都要安装,否则在启用该模块时,会报错如下:
$ ceph mgr module enable dashboard
Error ENOENT: all mgr daemons do not support module 'dashboard', pass --force to force enablement
启用dashboard
$ ceph mgr module enable dashboard
# 确认模块已启用
$ ceph mgr module ls | grep -A 4 enabled_modules
"enabled_modules": [
"dashboard",
"iostat",
"restful"
],
配置dashboard证书
ceph默认提供了自生成的证书,也支持导入外部证书,当然,也支持禁用掉ssl协议,走http协议进行访问,这里将记录不同的方式如何配置。
1、使用ceph自生成证书(我这里将使用这种方式)
$ ceph dashboard create-self-signed-cert
2、使用外部证书
# 自己制作证书
$ openssl req -new -nodes -x509 \
-subj "/O=IT/CN=ceph-mgr-dashboard" -days 3650 \
-keyout dashboard.key -out dashboard.crt -extensions v3_ca
# 导入ceph集群
$ ceph dashboard set-ssl-certificate -i dashboard.crt
$ ceph dashboard set-ssl-certificate-key -i dashboard.key
3、禁用SSL
$ ceph config set mgr mgr/dashboard/ssl false
配置dashboard监听地址
默认情况下,启用ssl的话,dashboard将监听8443端口,如果未启用SSL,那么将监听8080端口,如果你想更改它,可以使用如下指令:
# 配置监听IP
$ ceph config set mgr mgr/dashboard/server_addr 0.0.0.0
# 配置监听http请求的端口
$ ceph config set mgr mgr/dashboard/server_port 8080
# 配置监听https请求的端口
$ ceph config set mgr mgr/dashboard/ssl_server_port 8443
# 由于每个mgr节点都有自己的dashboard,因此可能需要单独配置他们,可以通过如下命令进行单独配置
# 将下面的$name替换为你的节点名称
$ ceph config set mgr mgr/dashboard/$name/server_addr $IP
$ ceph config set mgr mgr/dashboard/$name/server_port $PORT
$ ceph config set mgr mgr/dashboard/$name/ssl_server_port $PORT
# 确认mgr的dashboard地址
$ ceph mgr services
{
"dashboard": "https://centos-20-10:8443/"
}
创建登录用户
# 必须将密码写入文件中
$ echo 'cephpasswd' > ~/.cephpwd.txt
# 创建管理员权限的用户
$ ceph dashboard ac-user-create cephadmin -i ~/.cephpwd.txt administrator
{"username": "cephadmin", "lastUpdate": 1619572766, "name": null, "roles": ["administrator"], "password": "$2b$12$/4jnUOJF2Ak1iHAgXJx14uEcfBZeyke7zMtnZf2hCv4wIUdybC6zu", "email": null}
登录ceph dashboard
访问你的dashboard IP+端口,如:https://192.168.20.10:8443/
默认情况下,dashboard未开启对象网关的相关监控,如下:
dashboard启用rgw管理功能
1、确认rgw已正常安装
$ ceph -s # 查询rgw节点
cluster:
id: d94fee92-ef1a-4f1f-80a5-1c7e1caf4a4a
health: HEALTH_OK
services:
mon: 3 daemons, quorum centos-20-10,centos-20-5,centos-20-6 (age 3h)
mgr: centos-20-10(active, since 5h), standbys: centos-20-6, centos-20-5
mds: cephfs-demo:1 {0=centos-20-5=up:active} 2 up:standby
osd: 6 osds: 6 up (since 6h), 6 in (since 13d)
rgw: 2 daemons active (centos-20-10, centos-20-5) # 这里是rgw节点
如果未安装rgw,可以参考博文ceph集群之RGW高可用安装rgw。
$ ss -lnpt | grep radosgw # 查看rgw监听端口
LISTEN 0 128 *:80 *:* users:(("radosgw",pid=12380,fd=48))
浏览器访问rgw监听端口,可以看到如下信息:
2、创建rgw dashboard用户
# 创建用户名为rgw-dashboard
$ radosgw-admin user create --uid=rgw-dashboard --display-name=rgw-dashboard --system
............. # 记录下输出的key信息
"keys": [
{
"user": "rgw-dashboard",
"access_key": "2M3Q3UJGXQI5Z2SDXZ4O",
"secret_key": "VSbfqkLsf5B9JP9s1HRDu01gTyWZHxvNKa2LVcuy"
}
],
# 也可以通过如下指令去查看用户的keys
$ radosgw-admin user info --uid=rgw-dashboard
3、导入rgw用户的keys到dashboard
# 将key信息写入文件
$ echo -n "2M3Q3UJGXQI5Z2SDXZ4O" > ~/.access-key
echo -n "VSbfqkLsf5B9JP9s1HRDu01gTyWZHxvNKa2LVcuy" > ~/.secret-key
# 导入dashboard
$ ceph dashboard set-rgw-api-access-key -i ~/.access-key
ceph dashboard set-rgw-api-secret-key -i ~/.secret-key
# 关闭证书验证
$ ceph dashboard set-rgw-api-ssl-verify False
4、访问dashboard验证:
访问成功,齐活儿。
ceph启用prometheus模块
参考:官方文档。
启用prometheus模块
$ ceph mgr module enable prometheus
# 确认模块已开启
$ ceph mgr module ls | grep -A 5 enabled_modules
"enabled_modules": [
"dashboard",
"iostat",
"prometheus",
"restful"
],
访问节点的9283
端口,即可看到采集的指标:
可选配置
1、设置prometheus客户端的监听地址及端口
$ ceph config set mgr mgr/prometheus/server_addr 0.0.0.0
ceph config set mgr mgr/prometheus/server_port 9283
2、默认prometheus模块采集了所有pool的健康数据,如果你只想采集某些pool的,那么可以使用如下指令进行设置:
$ ceph config set mgr mgr/prometheus/rbd_stats_pools "pool1,pool2,poolN"
3、设置采集间隔,默认为15s:
$ ceph config set mgr mgr/prometheus/scrape_interval 20
安装prometheus服务
1、下载及配置prometheus
$ wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz
tar zxf prometheus-2.20.1.linux-amd64.tar.gz -C /opt/
ln -sf /opt/prometheus-2.20.1.linux-amd64 /opt/prometheus
ln -sf /opt/prometheus-2.20.1.linux-amd64/prometheus /usr/local/bin/
# 配置文件调整
# 替换为你本机IP
Local_IP=192.168.20.10
sed -i "s/localhost/${Local_IP}/g" /opt/prometheus/prometheus.yml
2、安装node_exporter
node_exporter用于采集主机的基本信息,如网络、磁盘、CPU等,所有ceph节点都建议安装。
$ wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar zxf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt/
ln -sf /opt/node_exporter-1.0.1.linux-amd64 /opt/node_exporter
nohup /opt/node_exporter/node_exporter &
ss -lnput | grep 9100 # 确定端口在监听
tcp LISTEN 0 128 [::]:9100 [::]:* users:(("node_exporter",pid=7352,fd=3))
3、prometheus配置target
$ vim /opt/prometheus/prometheus.yml
scrape_configs: # 此字段下新增job如下
- job_name: 'ceph'
honor_labels: true
static_configs:
- targets:
- 192.168.20.10:9283
- 192.168.20.6:9283
- 192.168.20.5:9283
- job_name: 'node_exporter'
static_configs:
- targets:
- 192.168.20.10:9100
- 192.168.20.6:9100
- 192.168.20.5:9100
# 上面的IP必须是当前处于active状态的mgr节点。
4、启动prometheus
$ nohup prometheus --config.file="/opt/prometheus/prometheus.yml" \
--web.enable-lifecycle --storage.tsdb.path=/opt/prometheus/data \
--storage.tsdb.retention.time=30d &
5、确认端口已监听
$ ss -napl | grep prometheus
tcp LISTEN 0 65535 :::9090 :::* users:(("prometheus",pid=15237,fd=9))
# 可以查看nohup日志是否有异常
$ tailf nohup.out
6、访问验证已采集到数据
prometheus接入grafana
关于prometheus与grafana的接入配置,这里不展开来说了,如果需要文档参考,可以参考我之前的博文 Prometheus+node_exporter+mysqld_exporter+grafana部署与配置 进行配置:
这里附加一个 官方提供 的dashboard,导入到集群后的展示效果如下: