Prometheus+Grafana搭建监控系统

我不是女神ヾ 2023-05-31 15:30 66阅读 0赞

1. prometheus安装

Prometheus 主程序,主要是负责存储、抓取、聚合、查询方面

直接官网下载:https://prometheus.io/download/

20180907155431266

解压执行命令:tar zxf prometheus-2.3.2.linux-amd64.tar.gz

编辑解压目录下的prometheus.yml,执行命令:vi prometheus.yml

20180907155438471

scrape_interval: 15s # 默认15秒到目标处抓取数据

job name 这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:”prometheus”}的标签。

采用后台启动方式,在解压目录下执行命令如下:

nohup ./prometheus —config.file=prometheus.yml &

使用浏览器打开该机器的 http://部署机器:9090 ,或者 http://localhost:9090/ 即可以看到Prometheus的graph页面

20180907155446959

20180907155451844

2. node_exporter安装

node_exporter对于主机的关键度量指标状态监控

下载地址:https://prometheus.io/download/

20180907155551448

解压执行命令:tar zxf node_exporter-0.16.0.linux-amd64.tar.gz

采用后台启动方式,在解压目录下执行命令如下:

nohup ./node_exporter &

在prometheus.yml中增加配置:

20180907155515446

  1. - job_name: 'ysy_test_server'
  2. static_configs:
  3. - targets: ['ip:9100']
  4. labels:
  5. instance: ysy_test_server_151

重新启动prometheus(启动命令参考prometheus安装过程中的)

浏览器访问:http://部署机器:9090/targets

20180907155529261

3. mysqld_exporter安装

mysqld_exporter对于mysql监控

下载地址:https://prometheus.io/download/

201809071556065

解压执行命令:tar zxf mysqld_exporter-0.11.0.linux-amd64.tar.gz

mysqld_exporter需要连接到MySQL,需要授权

mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO ‘test’@’localhost’ identified by ‘test123’;

mysql> GRANT SELECT ON performance_schema.* TO ‘test’@’localhost’;

创建 .my.cnf

  1. [client]
  2. user=test
  3. password=test123

#如果mysql的端口不为3306,需要配置socket指定对应的mysql.sock

socket=”/var/lib/mysql/mysql.sock”

采用后台启动方式,在解压目录下执行命令如下:

  1. nohup ./mysqld_exporter --config.my-cnf=".my.cnf" &

在prometheus.yml中增加配置:

20180907155617169

  1. - job_name: 'ysy_test_db'
  2. static_configs:
  3. - targets: ['ip:9104']
  4. labels:
  5. instance: ysy_test_db_1

重新启动prometheus(启动命令参考prometheus安装过程中的)

浏览器访问:http://部署机器:9090/targets

2018090715562546

4. Grafana安装

Grafana是一个可视化面板(Dashboard),有着非常漂亮的图表和布局展示,功能齐全的度量仪表盘和图形编辑器,支持Graphite、zabbix、InfluxDB、Prometheus

下载地址:https://grafana.com/grafana/download

20180907155633614

执行命令:

  1. wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.3-1.x86_64.rpm
  2. sudo yum localinstall grafana-5.2.3-1.x86_64.rpm

一波操作完看到如下内容表示安装成功:

###

/etc/grafana/grafana.ini

###

sudo /bin/systemctl daemon-reload

sudo /bin/systemctl enable grafana-server.service

###

sudo /bin/systemctl start grafana-server.service

启动执行命令:

  1. sudo /bin/systemctl start grafana-server.service

访问页面http://服务器IP:3000 ,默认账号、密码admin/admin

20180907155642921

看到这界面,恭喜你,成功了

登录执行设置数据源

20180907155649735

进入配置界面

20180907155656661

20180907155708386

配置成功之后可以把默认dashboards的导入

20180907155715215

这时候你再进入到datasource可以看到刚配置的数据源;

20180907155722259

20180907155728700

点击Prometheus 2.0 Stats:

20180907155734811

5. Grafana安装

grafana-dashboards是一个可视化面板,有着非常漂亮的图表和布局展示,功能齐全仪表盘展示等

下载地址:

https://github.com/percona/grafana-dashboards

下载到本地

20180907155741334

或者clone下载

  1. git clone https://github.com/percona/grafana-dashboards.git

也可以下载tag版本

我下载的是grafana-dashboards-1.13.0

导入dashboards

20180907155747414

2018090715575439

20180907155759370

201809071558062

20180907155812870

6. 踩坑提醒

  1. 如果设置了防火墙,注意端口的开放
  2. 注意操作系统,我使用的操作系统是centos7.3

转载请注明:https://blog.csdn.net/javanian/article/details/82498018

发表评论

表情:
评论列表 (有 0 条评论,66人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Zabbix监控系统

    引言: zabbix是目前系统监控领域的佼佼者,其开源且提供了强大完善的Web界面,并且兼容各种不同的设备和系统,支持多种平台,其背后的公司为Zabbix持续演进提供了技术支持