|
|
1.Ceph的Dashboard只适合查看集群状态,生产环境中最好还是把监控ceph纳入到已有的zabbix或Prometheus监控系统中;由于Prometheus是一个restful风格的api,它是通过http或https接口进行数据指标采集的,但是很多被监控的应用并没有http接口,因此需要借助各自应用的exporter进行间接采集;
" l( K$ F8 g% P2 |9 T0 [, s2.mgr的prometheus_exporter和node_exporter4 J% H4 L" L( ?- l5 m% {
1.由于Ceph底层是rados协议没有http接口,所以也需要有单独的exporter进行采集,只需要在ceph的一个节点上安装prometheus_exporter,获得cephX授权后通过mon或mgr查询ceph集群信息后,把采集到的数据转为与prometheus兼容的格式并通过http协议响应prometheus的拉取请求;好在这个prometheus_exporter是直接内置在Ceph的mgr模块中的,只需要启用该模块即可;) L( l! m$ J( X
2.由于mgr内嵌的prometheus_exporter只是监控Ceph系统本身的数据,而每个ceph节点主机的cpu、内存信息还是需要部署node_exporter进行数据采集监控的;) F/ l" P6 q5 }, R
3.1.创建运⾏Prometheus Server进程的系统⽤⼾,并为其创建家⽬录/var/lib/prometheus作为数据存储⽬录;如果公司内部中已有prometheus,可省略下面部分的安装过程,直接进行监控ceph的配置部分即可;
i/ ^# n/ g/ Y1 u ~]# useradd -r -m -d /var/lib/prometheus prometheus #创建数据目录
! _0 k, q+ s/ z' j. n ~]# tar xf prometheus-2.7.2.linux-amd64.tar.gz -C /usr/local/+ c( Y. ]6 O% u0 H1 u
#官方下载二进制包解压
9 z& w9 ~0 ^7 k! k+ p8 i ~]# ln /usr/local/prometheus-2.7.2.linux-amd64 /usr/local/prometheus H" p% v* v1 K
#创建软链接# v5 }: V. k% p2 V. H5 \ g
~]# prometheus --version #查看prometheus版本6 O; l. u. F# L$ G f2 R
创建Prometheus专⽤的Unit File文件放在/usr/lib/systemd/system/目录下7 P" q: g# G9 u. b
~]# vim /usr/lib/systemd/system/prometheus.service
" l$ S% W% r w+ K/ Q- _ [Unit]( \8 R9 k9 w! H; e
Documentation=https://prometheus.io
* P6 H* e% ` b/ J: u After=network.target! r+ i6 ?9 ] r- n$ R9 c! s
[Service]7 |. i4 Q8 ^$ Y/ M E9 j* o& n
EnvironmentFile=-/etc/sysconfig/prometheus
9 b3 Z. B! a0 b! r+ j+ ^ User=prometheus! I# ^ z+ M) E8 v
ExecStart=/usr/local/prometheus/prometheus \& s# h- F4 e W' B
--storage.tsdb.path=/var/lib/prometheus \
9 A! }4 k3 f4 W# e7 ] --config.file=/usr/local/prometheus/prometheus.yml \+ I$ O2 G& C) ^# G
--web.listen-address=0.0.0.0:9090 \
! c* u* P% u" v( G --web.external-url=
/ e1 ?, n* O' m; z Restart=on-failure
0 i8 w: b) Z2 ~8 s4 o" j, \ StartLimitInterval=1. w. X3 l) W5 A+ j5 w- |
RestartSec=3
' j1 t$ }, j& U9 g) e7 E- |5 d: j [Install], b# ^$ h" @: X$ O9 v
WantedBy=multi-user.target
0 o# \6 V2 q. p2 i1 R! ~3.2.每个Ceph节点安装node_exporter采集ceph节点主机的数据
# Z$ ]% I6 }/ \6 ]. E; W) R& M% @ ~]# tar xf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/ 9 G! J3 f$ Q! [1 C3 A& J- x
~]# ln -sv /usr/local/node_exporter-0.17.0.linux-amd64 /usr/local/node_exporte6 [# e, D( a! d& ]8 f% U
~]# useradd -r -m -d /var/lib/prometheus prometheus
: R4 G( G/ z+ K& k5 K! K 创建运⾏Prometheus Server进程的系统⽤⼾,并为其创建家⽬录/var/lib/prometheus作为数据存储⽬录% _8 l* [9 ` O4 L- G1 c, @
~]# vim /usr/lib/systemd/system/node_exporter.service$ I7 J+ ]# N6 S: }% b
[Unit]
; [. u8 i2 z2 z! K" M9 U Documentation=https://github.com/prometheus/node_exporter
9 Q9 d2 w; `2 K, e. M- G. C. c After=network.target$ f; W! e+ Q! a2 x2 X: S0 [
[Service]+ q) t; f* T0 i) f1 }* _$ j# |
EnvironmentFile=-/etc/sysconfig/node_exporter! i' Y2 X2 S# O" X" J" j5 c
User=prometheus
' f9 `' D6 k% s8 l0 F0 n ExecStart=/usr/local/node_exporter/node_exporter \
8 @+ H8 e* g& I, l* J# g: V $NODE_EXPORTER_OPTS
' Y3 S2 x6 K0 I/ y( X! V Restart=on-failure; x8 O% }6 k/ ^' W! V
StartLimitInterval=1. j1 H [+ Z4 X) [& b
RestartSec=3
6 \! z% v B+ n [! u [Install]
) d3 p/ M1 q3 ^ WantedBy=multi-user.target
6 s6 n, w1 G. w- R+ a ~]# systemctl daemon-reload && systemctl start node_exporter.service2 z8 P N4 J! B3 t, }% f" R, `
~]# s -tunpl |grep 9100 #查看监控端口
^4 C) S# P: B& y tcp LISTEN 0 128 :::9100 :::* users:(("node_exporter",pid=6776,fd=3)), \0 \! @( f( O9 ~7 Y+ x& C
~]# curl localhost:9100/metrics #测试会否采集到指标数据3 Q X1 s/ O0 _7 p
3.3.启用Ceph-mgr中的promethues模块% s% @$ ^# N8 F
~]# ceph mgr module enable prometheus
9 ^! h0 K% a p' E/ b #Prometheus模块默认监听于TCP协议的9283端⼝0 [' X0 w0 z! ?5 ]: E$ |
~]# ceph mgr services/ d$ b" j$ L- |, D2 Q
{# [' T5 ]1 W2 R" w) w& @
"dashboard": "http://stor02.cre.io:8080/"," A6 ?0 C, {0 ]- M# O6 I
"prometheus": "http://stor02.cre.io:9283/"2 w7 a( N. T7 v5 `- x( K+ I
}
% v8 v( T+ ?- b. b8 G# C% ` ~]# ss -tunpl |grep 9283
+ I7 v7 J2 f/ e3 k' b3 G- X/ x tcp LISTEN 0 5 :::9283 :::* users:(("ceph-mgr",pid=1071,fd=22))
/ S. \8 Q, H* I a4 J7 K7 s9 b #会在Mgr所在的存储节点上开启9283端口
3 q: N1 _+ z7 D3.4.Prometheus的主配置⽂件为prometheus.yml字段和格式解释
8 b( G7 r# P& u) h prometheus.yml文件主要由global、rule_files、scrape_configs、alerting、remote_write和remote_read⼏个配置段组成,其中:
, g2 ~! ]; q" B( Y) { 1.global:全局配置段;
, g, F8 M% u/ p- C, J0 \8 ^1 V 2.scrape_configs:配置要监控的目标对象3 d1 f+ X8 A: i$ R* k% ~
scrape配置集合,⽤于定义监控的⽬标对象(target)的集合,以及描述如何抓取(scrape)相关指标数据的配置参数;通常,每个scrape配置对应于⼀个单独的作业(job),⽽每个targets可通过静态配置(static_configs)直接给出定义,也可基于Prometheus⽀持的服务发现机制进⾏⾃动配置;
/ N, K T3 H; p I7 |. I- Y y 3.alertmanager_configs:指定配置监控的报警规则0 b8 t9 O( l" h. Z# ?0 D
可由Prometheus使⽤的Alertmanager实例的集合,以及如何同这些Alertmanager交互的配置参数;每个Alertmanager可通过静态配置(static_configs)直接给出定义,也可基于Prometheus⽀持的服务发现机制进⾏⾃动配置;7 q; h7 _$ @! D/ P5 @4 J! X1 `
4.remote_write:* r" s0 h5 _. _2 T) `
配置"远程写"机制,Prometheus需要将数据保存于外部的存储系统(例如InfluxDB)时定义此配置段,随后Prometheus将样本数据通过HTTP协议发送给由URL指定适配器(Adaptor);
0 ]$ ~# a p+ f; L 5.remote_read:
2 i- ]/ d, e: r2 S$ _ 配置"远程读"机制,Prometheus将接收到的查询请求交给由URL指定适配器(Adpater)执⾏,Adapter将请求条件转换为远程存储服务中的查询请求,并将获取的响应数据转换为Prometheus可⽤的格式' Q6 e! o g& a. o, \
2.1.scrape配置段( Y; E6 i# C8 Z5 g
1.使⽤static_configs静态配置Job的语法格式:
- j9 g4 ~- D0 | # The targets specified by the static config.1 k3 M! X& Y+ j: D( k0 t
targets:
- q- K% ]1 w8 C0 x! f [ - '<host>' ]
& c& u5 L5 Y/ I, K8 s # Labels assigned to all metrics scraped from the targets.
5 `; e) R/ A/ b' b! S labels:
8 `* I* I3 d/ O2 w- C/ D [ <labelname>: <labelvalue> ... ]* Y1 P, J% P- t6 p; I
2.使⽤file_sd_configs基于文件发现机制配置Job的语法格式1 y. o& F4 Y L8 q. U4 A8 }% K
[
- e. W4 ?( O& T4 G6 k9 y {, d0 C: K# M R8 q" D* B2 F
"targets": [ "<host>", ... ],
1 Z/ O/ S7 k4 B5 Y "labels": {& n* H+ N% k8 f+ [
"<labelname>": "<labelvalue>", ...* N4 X3 K/ c3 A( P- p2 n
}
3 j T# r- l0 m0 ~; G },
) w( g4 g0 B* A9 C ...- t( c, U) ~6 j/ R8 [
]
% L0 q8 _7 t: K3.5.配置prometheus监控ceph集群和ceph存储节点主机
) G. q# A) A6 s4 c+ _ ~]# vim /etc/prometheus/prometheus.yml' D4 a& W6 }5 E# h9 ~- o9 h" |
scrape_configs:
5 w/ O. l; H1 L: K8 q" \ - job_name: 'prometheus'
& a* [6 q2 P8 l. Q& M4 {4 k8 h static_configs:; b- X9 H) X1 b% q; h9 _' p/ u
- targets: ['111.231.143.40:9090']
! W' ]9 I* K8 J1 J1 t& k z - job_name: 'node_exporter'
" J7 O3 E: l. B+ [2 k# o( A6 M static_configs:5 [. e, j( @9 |9 H0 l( Z. H
- targets: ['stor01.cre.io:9100']
* E; Y7 P+ O3 X9 C: F - targets: ['stor02.cre.io:9100']: s5 V( M) U9 I; J8 s
- targets: ['stor03.cre.io:9100']
; c% m/ c: ?6 u/ a7 c7 z8 S - job_name: 'ceph'3 C1 T* d: u0 p0 p1 ~& n m
# honor_labels: true
; W+ R4 E x, [0 l4 Z+ f/ Z static_configs:" G& s6 i# V1 c* E4 z
- targets: ['stor02.cre.io:9283']
% ~ ~/ e; a4 U- D& n9 q s! c 注意事项: {9 d! p6 }3 B# \: v0 U9 a! f7 {
1.job_name=node_exporter设置ceph集群的3个主机节点,job_name=ceph设置manager所在节点的主机名和Prometheus模块的端口;
/ H) w6 |. F. i. U$ [) z 2.注意prometheus中的targets中要写主机的FQDN格式的主机名,否者ceph dashboard中host details中不能正常显示监控数据,因为ceph dashboard是使用FQDN格式的主机名查询监控信息,如果prometheus中写的是IP会导致查询不到;而grafana使用IP查询,所以在grafana中不会有这种错误;
: r1 n8 K; o4 B Q! q0 w) \ 3.honor_labels=true必须有且设置为true,否者会导致CephDashbaord中显示grafana某些面板没有数据出现(这个待验证,个人认为可以设置此参数);! z' Q1 Z- n0 h) s5 @7 N
4.如果ceph集群中部署了多个manager,需要在job_name=ceph中添加多个targets将所有magr的地址都写上;(本ceph集群只部署了一个mgr)8 {5 ^3 N4 }8 `. [ E6 o5 [
~]# systemctl daemon-reload
0 O! j* E7 ~$ _+ _) ]9 \( z) i~]# systemctl start prometheus && systemctl enable prometheus #设置开启自启
5 a4 f" h" e+ _验证配置是否抓取到数据:
# \# X0 M5 c) A0 y/ z. Z5 F 登录prometheus地址:http://192.168.10.10:9090,查看Targets页面上的prometheus、3个node、ceph mgr是否都是UP的即可: |
|