普罗米修斯prometheus的安装与监控linux

您所在的位置:网站首页 林内热水器型号对照表图片 普罗米修斯prometheus的安装与监控linux

普罗米修斯prometheus的安装与监控linux

2023-11-05 11:53| 来源: 网络整理| 查看: 265

golang的安装

普罗米修斯是go开发的,所以需要安装go环境。

先下载golang,下载地址:https://studygolang.com/dl,

这里选择的是:https://studygolang.com/dl/golang/go1.16.5.linux-amd64.tar.gz

上传至/usr/local目录下并解压

添加环境变量

export GO_HOME=/usr/local/go export PATH=$PATH:$GO_HOME/bin 验证go环境是否安装成功。 # go version go version go1.16.5 linux/amd64 普罗米修斯prometheus的安装 下载prometheus,下载地址:https://github.com/prometheus/prometheus/releases

这里使用的是https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz

上传至/usr/local目录下并解压

将prometheus安装为系统服务

# cat /etc/systemd/system/prometheus.service [Unit] Description=Prometheus [Service] Type=simple Restart=on-failure RestartSec=5 ExecStart=/usr/local/prometheus-2.27.1.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.27.1.linux-amd64/prometheus.yml [Install] WantedBy=multi-user.target 启动prometheus # systemctl enable prometheus # systemctl start prometheus # systemctl status prometheus ● prometheus.service - Prometheus Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled) Active: active (running) since Sun 2021-06-06 02:15:28 EDT; 1s ago Main PID: 9565 (prometheus) CGroup: /system.slice/prometheus.service └─9565 /usr/local/prometheus-2.27.1.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.27.1.linux-amd64/prometheus.yml Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.354Z caller=head.go:755 component=tsdb msg="On-disk memory mappable chunks replay c…ion=14.216µs Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.354Z caller=head.go:761 component=tsdb msg="Replaying WAL, this may take a while" Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.362Z caller=head.go:813 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1 Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.363Z caller=head.go:813 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1 Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.363Z caller=head.go:818 component=tsdb msg="WAL replay completed" checkpoint_replay…n=9.195162ms Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.370Z caller=main.go:828 fs_type=XFS_SUPER_MAGIC Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.370Z caller=main.go:831 msg="TSDB started" Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.370Z caller=main.go:957 msg="Loading configuration file" filename=/usr/local/promet...etheus.yml Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.421Z caller=main.go:988 msg="Completed loading of configuration file" filename=/usr/local/pro…µs Jun 06 02:15:28 node07 prometheus[9565]: level=info ts=2021-06-06T06:15:28.421Z caller=main.go:775 msg="Server is ready to receive web requests." Hint: Some lines were ellipsized, use -l to show in full. 验证,浏览器输入:http://192.168.0.207:9090/,出现如下界面说明安装成功了。

在这里插入图片描述

node_exporter的安装

prometheus只是监控数据,那么数据的来源呢,由XXX_exporter进行收集,如果是监控linux系统,那么就要安装node_exporter。

下载node_exporter,下载地址:https://github.com/prometheus/node_exporter/releases

这里使用的是:https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz

上传至/usr/local目录下并解压

安装为系统服务

# cat /etc/systemd/system/node_exporter.service [Unit] Description=node-exporter [Service] Type=simple Restart=on-failure RestartSec=5 ExecStart=/usr/local/node_exporter-1.1.2.linux-amd64/node_exporter [Install] WantedBy=multi-user.target 启动node_exporter,并设置为随开机启动。 # systemctl daemon-reload # systemctl start node_exporter # systemctl status node_exporter # systemctl enable node_exporter 验证,浏览器输入:http://192.168.0.207:9100/

正常会出现如下界面:

在这里插入图片描述

将node_exporter与prometheus建立联系,在prometheus.yml最后添加如下内容: - job_name: 'linux' static_configs: - targets: ['192.168.0.207:9100']

可以使用./promtool check config prometheus.yml对yml文件格式进行校验。

重启prometheus。

重启后,可以打开http://192.168.0.207:9090/targets查看监听的目标。

在这里插入图片描述

grafana的安装

prometheus只是监控,而grafana对这些数据进行图形化的展示,下面采用yum进行安装。

官方参考教程:https://grafana.com/docs/grafana/latest/installation/rpm/

配置yum源 # cat /etc/yum.repos.d/grafana.repo [grafana] name=grafana baseurl=https://packages.grafana.com/oss/rpm repo_gpgcheck=1 enabled=1 gpgcheck=1 gpgkey=https://packages.grafana.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt 安装 # yum update # yum makecache # yum install -y grafana 启动,并设置为随系统开机启动 # systemctl daemon-reload # systemctl start grafana-server # systemctl status grafana-server # systemctl enable grafana-server 验证,浏览器输入http://192.168.0.207:3000/,默认密码admin/admin

在这里插入图片描述

prometheus与grafana之间建立联系

在http://192.168.0.207:3000/datasources/new添加数据源,选择prometheus。

在这里插入图片描述

输入prometheus的地址http://192.168.0.207:9090/保存即可,其余都默认。

在这里插入图片描述

导入dashboard,打开http://192.168.0.207:3000/dashboard/import,可以在https://grafana.com/grafana/dashboards寻找合适的模板,复制模板ID直接导入即可。

在这里插入图片描述 在这里插入图片描述

最终效果图如下:

在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3