原创

树莓派Prometheus+grafana安装教程最新版

一、环境准备:查看电脑的系统结构

我之前在网上花了1000左右大洋买的一台树莓派,然后重装系统为Centos7

可以看到下面的命令,我的系统架构:Architecture: aarch64,有些在官网上找不到,可以去GITHUB找编译好的包下载安装。

[root@localhost yum.repos.d]# rpm -qi centos-release

Name : centos-release
Version : 7
Release : 9.2009.0.el7.centos
Architecture: aarch64
Install Date: Fri 30 Oct 2020 09:27:45 AM CST
Group : System Environment/Base
Size : 50635
License : GPLv2
Signature : RSA/SHA256, Mon 26 Oct 2020 09:24:53 PM CST, Key ID 6c7cb6ef305d49d6
Source RPM : centos-release-7-9.2009.0.el7.centos.src.rpm
Build Date : Fri 23 Oct 2020 11:00:29 PM CST
Build Host : aarch64-02.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
Summary : CentOS Linux release file
Description :
CentOS Linux release files

二、Prometheus安装

1、下载地址
https://prometheus.io/download/
选择Architecture: armv7,否则会安装不上。
2、创建启动用户
[root@prometheus-service prometheus]# groupadd prometheus
[root@prometheus-service prometheus]# useradd -g prometheus -s /sbin/nologin prometheus
3、解压并迁移改名
[root@prometheus-service opt]# tar xf prometheus-2.36.0.linux-armv7.tar.gz
[root@prometheus-service opt]# mv prometheus-2.36.0.linux-armv7   /usr/local/prometheus
4、授权用户
chown -R prometheus.prometheus /usr/local/prometheus
5、创建数据存储目录
mkdir -p /usr/local/prometheus/data
6、启动添加到systemd
cd /etc/systemd/system/
touch prometheus.service

[Unit] 
Description=Prometheus Monitoring System 
Documentation=Prometheus Monitoring System 

[Service] ExecStart=/usr/local/prometheus/prometheus \ 
    --config.file=/usr/local/prometheus/prometheus.yml \ 
    --storage.tsdb.path=/usr/local/prometheus/data \ 
    --web.listen-address=:9090 

[Install] 
WantedBy=multi-user.target

7、启动服务
service prometheus restart
./prometheus --config.file=prometheus.yml

8、测试结果
http://192.168.84.192:9090/graph

9、检查配置命令
/usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml

10、web页面查询暴露数据
http://192.168.84.192:9100/metrics

三、node_exporter安装

1、下载地址
https://prometheus.io/download/
选择Architecture: armv7,否则会安装不上。

2、创建启动用户
[root@prometheus-service prometheus]# groupadd prometheus 
[root@prometheus-service prometheus]# useradd -g prometheus -s /sbin/nologin prometheus
3、下载地址
https://prometheus.io/download/#node_exporter
4、解压并且改名
[root@node-exporters opt]# tar xf node_exporter-1.3.1.linux-armv7.tar.gz -C /usr/local/ 
[root@node-exporters opt]# mv /usr/local/node_exporter-1.3.1.linux-armv7/  /usr/local/node_exporter
5、添加node_exproter至systemd
cd /etc/systemd/system/
touch  node_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target


[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/node_exporter/node_exporter \
          --web.listen-address=0.0.0.0:9100 \
          --collector.systemd \
          --collector.systemd.unit-whitelist=(sshd|nginx).service
Restart=on-failure
[Install]
WantedBy=multi-user.target

6、启动服务
service node_exporter  restart

7、查看服务是否启动命令
netstat -lntup 


四、grafana安装

1、下载地址

2、安装命令
sudo yum install grafana-8.5.5-1.aarch64.rpm

3、启动命令
systemctl restart grafana-server.service

4、登录
帐号:admin 密码:admin123

5、页面地址(IP根据实际而定)
http://192.168.84.192:3000

五、导入模板及常用模板ID


1、监控容器,推荐ID
3146:Kubernetes Pods
8685:K8s Cluster Summary
10000:Cluster Monitoring for Kubernetes
8588:Kubernetes Deployment Statefulset Daemonset metrics
315:Kubernetes cluster monitoring (via Prometheus)

2、Linux服务器监控模板ID:
8919:1 Node Exporter Dashboard 22/04/13 ConsulManager自动同步版
9276:1.主机基础监控(cpu,内存,磁盘,网络)

3、Windows服务器监控模板ID:
10467

4、监控协议http/icmp/tcp/dns/
9965:Blackbox Exporter Dashboard

5、mysql监控
7362:

6、nginx
9614
 





  <a href="http://www.wanghaifeng.net" title="欢迎各位开发与测试的朋友们!请扫码关注我!谢谢支持!" target="_blank">小蜜蜂博客</a>




正文到此结束
本文目录