|
|
楼主 |
发表于 2021-8-10 11:28:56
|
显示全部楼层
1.Ceph的Dashboard只适合查看集群状态,生产环境中最好还是把监控ceph纳入到已有的zabbix或Prometheus监控系统中;由于Prometheus是一个restful风格的api,它是通过http或https接口进行数据指标采集的,但是很多被监控的应用并没有http接口,因此需要借助各自应用的exporter进行间接采集;3 m# M% r/ D9 t
2.mgr的prometheus_exporter和node_exporter
. O. C) d% ? S 1.由于Ceph底层是rados协议没有http接口,所以也需要有单独的exporter进行采集,只需要在ceph的一个节点上安装prometheus_exporter,获得cephX授权后通过mon或mgr查询ceph集群信息后,把采集到的数据转为与prometheus兼容的格式并通过http协议响应prometheus的拉取请求;好在这个prometheus_exporter是直接内置在Ceph的mgr模块中的,只需要启用该模块即可;* C* a0 ~) U4 G7 i$ E8 o
2.由于mgr内嵌的prometheus_exporter只是监控Ceph系统本身的数据,而每个ceph节点主机的cpu、内存信息还是需要部署node_exporter进行数据采集监控的;8 h1 ^( ~6 a% _( D
3.1.创建运⾏Prometheus Server进程的系统⽤⼾,并为其创建家⽬录/var/lib/prometheus作为数据存储⽬录;如果公司内部中已有prometheus,可省略下面部分的安装过程,直接进行监控ceph的配置部分即可;+ a9 z* _4 g. H: A$ q
~]# useradd -r -m -d /var/lib/prometheus prometheus #创建数据目录- x% q* H9 P7 B) G4 C0 c9 Z" I
~]# tar xf prometheus-2.7.2.linux-amd64.tar.gz -C /usr/local/4 ~2 B% [' i+ W( D9 T8 b, R0 e
#官方下载二进制包解压0 Z$ Q7 U/ B+ p" f x6 G
~]# ln /usr/local/prometheus-2.7.2.linux-amd64 /usr/local/prometheus* K9 S8 g+ B% v) m* L& l }
#创建软链接
+ a1 o* T! F3 i' c7 w4 V ~]# prometheus --version #查看prometheus版本
# O8 Z8 g+ ~ N; L+ v 创建Prometheus专⽤的Unit File文件放在/usr/lib/systemd/system/目录下
# o5 ~4 _/ l, U ~]# vim /usr/lib/systemd/system/prometheus.service! u8 Q$ E$ O4 Y2 ~! W: T6 V
[Unit]. H# D9 h- \) N& m: s5 p5 H$ B
Documentation=https://prometheus.io4 _; \" A5 T/ h9 t2 ]
After=network.target
, S/ T# j2 q6 Q$ @0 W& w% J } [Service]
- W( o" t+ m" o7 j; G EnvironmentFile=-/etc/sysconfig/prometheus
7 W! d9 K% Z8 U User=prometheus j% b2 U$ r9 v4 _4 ^- W
ExecStart=/usr/local/prometheus/prometheus \# {. w& P( l: V! k
--storage.tsdb.path=/var/lib/prometheus \
8 n" j( \2 O8 r5 H2 C! B --config.file=/usr/local/prometheus/prometheus.yml \
& l* R' Z+ l! r/ A& j. f) O --web.listen-address=0.0.0.0:9090 \
& y" w. e, S" O% h+ y --web.external-url=5 ] u9 S0 H5 k" }. B
Restart=on-failure$ _+ `* ^9 ^* w
StartLimitInterval=1
1 _: p( ~8 w0 X- W# `# q RestartSec=3
5 V& h3 n7 R2 Y' O1 M [Install]
. `( S% j% w/ J WantedBy=multi-user.target
' y' e4 V2 S5 `+ V1 K3.2.每个Ceph节点安装node_exporter采集ceph节点主机的数据
7 _* \$ s( V& H o2 `7 B+ p ~]# tar xf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/ 8 }6 g4 f9 {; N2 s
~]# ln -sv /usr/local/node_exporter-0.17.0.linux-amd64 /usr/local/node_exporte/ l! P. y' T! p6 {9 i
~]# useradd -r -m -d /var/lib/prometheus prometheus
/ f/ E; W( U B) k) U' {- { 创建运⾏Prometheus Server进程的系统⽤⼾,并为其创建家⽬录/var/lib/prometheus作为数据存储⽬录1 ^# p' C7 f0 y6 ?7 y0 }
~]# vim /usr/lib/systemd/system/node_exporter.service$ S3 e7 v* ?+ \# F& G9 s
[Unit]
4 ]- Y7 w2 j" b" K Documentation=https://github.com/prometheus/node_exporter4 K7 L6 P2 \: i, Q2 d x$ K
After=network.target* w4 q% N- v! y& P D; j
[Service]
; J! Q Y* X5 E7 l$ y7 y EnvironmentFile=-/etc/sysconfig/node_exporter
. e' s5 C1 a8 m [' T7 A ~ User=prometheus& m/ q* q3 B' w. @8 b. f
ExecStart=/usr/local/node_exporter/node_exporter \
+ x* V% Q. g, ?" u: ~ $NODE_EXPORTER_OPTS! _; K8 q% H7 ]; |9 I# @% C$ J+ h$ U
Restart=on-failure% t) V" Q, _' g
StartLimitInterval=1
# g5 `6 P5 C( ^, v/ m; [# t RestartSec=3
; Z/ u( z5 e+ E9 _$ j- @ [Install]4 y9 Y: |5 |! ?, g+ e6 _+ @) Y7 d( d
WantedBy=multi-user.target
# a: }& r+ R8 Z ~]# systemctl daemon-reload && systemctl start node_exporter.service) C1 G1 v/ w* n6 n
~]# s -tunpl |grep 9100 #查看监控端口
9 v: Z# f$ o) y( S1 _ tcp LISTEN 0 128 :::9100 :::* users:(("node_exporter",pid=6776,fd=3))
7 J7 h4 k( T, ?' P5 a } ~]# curl localhost:9100/metrics #测试会否采集到指标数据% i; K% _8 Z! [, E
3.3.启用Ceph-mgr中的promethues模块: P, `+ T; \6 ^$ l( X
~]# ceph mgr module enable prometheus9 S9 G8 f) v" I1 Y. r( [
#Prometheus模块默认监听于TCP协议的9283端⼝( B- q) p" ^( O1 E
~]# ceph mgr services7 n2 e7 N' O( W0 z% e; n
{
- W, k; }/ p- H( \" M: H# a9 z* ? "dashboard": "http://stor02.cre.io:8080/",
- Y) i0 f: y0 U* H& f "prometheus": "http://stor02.cre.io:9283/"5 X' [, \3 W( @/ Z$ H% }0 R9 B5 D
}/ O# d9 r# F+ D
~]# ss -tunpl |grep 9283, } p9 o! S/ K. _ j9 x: G
tcp LISTEN 0 5 :::9283 :::* users:(("ceph-mgr",pid=1071,fd=22))
" c* c9 T% t, N8 ]) ?/ G% M #会在Mgr所在的存储节点上开启9283端口/ Q( C+ ^ [3 H& z, U' t
3.4.Prometheus的主配置⽂件为prometheus.yml字段和格式解释
3 H7 h+ ?* {3 ^- ?+ f6 ]5 c prometheus.yml文件主要由global、rule_files、scrape_configs、alerting、remote_write和remote_read⼏个配置段组成,其中:
' o, V* g" D: b/ q 1.global:全局配置段;4 l E, E4 }, S" q* L5 S/ @$ n$ z4 Q
2.scrape_configs:配置要监控的目标对象
* o, F, V3 X- }" A: v @/ ` scrape配置集合,⽤于定义监控的⽬标对象(target)的集合,以及描述如何抓取(scrape)相关指标数据的配置参数;通常,每个scrape配置对应于⼀个单独的作业(job),⽽每个targets可通过静态配置(static_configs)直接给出定义,也可基于Prometheus⽀持的服务发现机制进⾏⾃动配置;! r" r0 M* H7 X, ~1 e
3.alertmanager_configs:指定配置监控的报警规则4 ]% h2 _, L: |) }
可由Prometheus使⽤的Alertmanager实例的集合,以及如何同这些Alertmanager交互的配置参数;每个Alertmanager可通过静态配置(static_configs)直接给出定义,也可基于Prometheus⽀持的服务发现机制进⾏⾃动配置;6 z$ z5 z: e5 X
4.remote_write:' q ]" Q) R& p- a' p8 s. u+ y
配置"远程写"机制,Prometheus需要将数据保存于外部的存储系统(例如InfluxDB)时定义此配置段,随后Prometheus将样本数据通过HTTP协议发送给由URL指定适配器(Adaptor);
# s/ I3 a6 u& V( F& U 5.remote_read:5 b/ g+ ^% `7 k4 s
配置"远程读"机制,Prometheus将接收到的查询请求交给由URL指定适配器(Adpater)执⾏,Adapter将请求条件转换为远程存储服务中的查询请求,并将获取的响应数据转换为Prometheus可⽤的格式( U# }8 @' x9 P
2.1.scrape配置段. k7 D; b% Y$ \, R. P
1.使⽤static_configs静态配置Job的语法格式:( L' T* M8 e- ^; C6 H
# The targets specified by the static config.: ~0 o3 M9 m1 L' m' U" Z
targets:' W1 p5 k9 b9 C, W( D$ v% P! ]
[ - '<host>' ]* Y5 `3 G( _/ ?
# Labels assigned to all metrics scraped from the targets.+ T" W3 D3 E# Y; }" l! v( B; c
labels:6 y; \$ [6 q5 A9 g
[ <labelname>: <labelvalue> ... ]
: ~) \/ k( S: } @7 ` 2.使⽤file_sd_configs基于文件发现机制配置Job的语法格式
* P/ n! C5 e9 g2 I' q' ~ [" k& b# D5 H# u ^
{ f& p) B5 i6 d7 R8 r3 r
"targets": [ "<host>", ... ],
+ `* S, h- p$ G: w/ e: ]* y "labels": {2 J. a( ?# E: U. T
"<labelname>": "<labelvalue>", ...
6 Q1 y7 A" l6 F/ H% ]2 H }1 k; j- z( X, I* e' x: u
},
8 N* C8 b4 X) |3 X ...
q+ u' n, y! j7 w! I, }. h ]2 D. [. q* \% ]4 _$ _6 J5 [
3.5.配置prometheus监控ceph集群和ceph存储节点主机
6 x' g, |7 n; H0 v8 E' u" }- v ~]# vim /etc/prometheus/prometheus.yml; ^! n3 C2 S0 l
scrape_configs:' A; T: I5 T1 d0 w0 n9 m
- job_name: 'prometheus'
# D" `) b# X0 R% \ static_configs:5 E! D; }& }& `
- targets: ['111.231.143.40:9090']
) U' X$ F/ m3 o2 }( e' M - job_name: 'node_exporter'
% l N; i) d" O% s3 b6 c- @: B static_configs:6 E a }& y) h
- targets: ['stor01.cre.io:9100']
+ J& S+ |) x% K" O! h2 @- E - targets: ['stor02.cre.io:9100']
3 i/ Q% A- S) ?0 b, X - targets: ['stor03.cre.io:9100'] Q5 s1 u9 P/ c$ X$ v5 h3 {' m' D7 _
- job_name: 'ceph'
0 \/ A2 {7 M- }9 b5 } # honor_labels: true9 l( u, M0 Z, f
static_configs:
0 U7 y# c5 T# ?# Z2 W - targets: ['stor02.cre.io:9283']% { e- l8 [! z2 D
注意事项:
4 X" y- s6 T9 g 1.job_name=node_exporter设置ceph集群的3个主机节点,job_name=ceph设置manager所在节点的主机名和Prometheus模块的端口;
3 G+ `2 Y; i$ d9 V+ V2 u) d8 } 2.注意prometheus中的targets中要写主机的FQDN格式的主机名,否者ceph dashboard中host details中不能正常显示监控数据,因为ceph dashboard是使用FQDN格式的主机名查询监控信息,如果prometheus中写的是IP会导致查询不到;而grafana使用IP查询,所以在grafana中不会有这种错误;
9 {+ r5 ~# C$ J* I+ B) M 3.honor_labels=true必须有且设置为true,否者会导致CephDashbaord中显示grafana某些面板没有数据出现(这个待验证,个人认为可以设置此参数);
7 Q) C3 e) h& V0 G* \# a# n" @ 4.如果ceph集群中部署了多个manager,需要在job_name=ceph中添加多个targets将所有magr的地址都写上;(本ceph集群只部署了一个mgr)8 ]' S c& ^' @+ O
~]# systemctl daemon-reload
: n7 v) j( ?, R+ I) V: Z9 X: p~]# systemctl start prometheus && systemctl enable prometheus #设置开启自启
R7 u& X! }, R5 ]7 Y验证配置是否抓取到数据:
/ p+ x/ B- w' R 登录prometheus地址:http://192.168.10.10:9090,查看Targets页面上的prometheus、3个node、ceph mgr是否都是UP的即可:
; m3 p# k' P$ H0 t) |' D2 K |
|