简介
这里介绍使用prometheus+grafana+node_exporter实现linux系统的监控。
下面针对这三个组件进行具体的说明
prometheus
prometheus是一套开源的监控与报警与时间序列数据库的组合。
grafana
grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。
node_exporter
node_exporter是采集器,负责将采集的数据存储到prometheus数据库,然后grafana取promethues数据库的数据进行展示。
部署granfna
访问官网 https://grafana.com/
Win安装
解压并双击
Linux安装
命令行安装
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.1-1.x86_64.rpm
sudo yum install grafana-enterprise-8.4.1-1.x86_64.rpm
启动并查看端口
//启动
systemctl start grafana-server
//查看端口
netstat -lntp|grep grafana
访问
访问http://localhost:3000/
默认账号密码 admin/admnin
命令参考
systemctl 提供了一组子命令来管理单个的 unit,其命令格式为:
systemctl [command] [unit]
command 主要有:
start:立刻启动后面接的 unit。
stop:立刻关闭后面接的 unit。
restart:立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思。
reload:不关闭 unit 的情况下,重新载入配置文件,让设置生效。
enable:设置下次开机时,后面接的 unit 会被启动。
disable:设置下次开机时,后面接的 unit 不会被启动。
status:目前后面接的这个 unit 的状态,会列出有没有正在执行、开机时是否启动等信息。
is-active:目前有没有正在运行中。
is-enable:开机时有没有默认要启用这个 unit。
kill :不要被 kill 这个名字吓着了,它其实是向运行 unit 的进程发送信号。
show:列出 unit 的配置。
mask:注销 unit,注销后你就无法启动这个 unit 了。
unmask:取消对 unit 的注销。
部署prometheus
下载安装包
访问https://prometheus.io/download/直接下载安装包或者 使用命令行进行下载
wget https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-amd64.tar.gz
使用命令
tar -xvf prometheus-2.33.3.linux-amd64.tar.gz
创建文件夹
解压prometheus-2.33.3.linux-amd64.tar.gz并复制到/usr/local/bin/下
分别创建 /ect/prometheus 和 /var/lib/prometheus文件夹
配置prometheus.service
vi /usr/lib/systemd/system/prometheus.service
写入以下内容
[Unit]
Description=Prometheus: the monitoring system
Documentation=http://prometheus.io/docs/
[Service]
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.target
复制配置文件至 /etc/prometheus目录
cp -p /root/prometheus-2.33.3.linux-amd64/prometheus.yml /etc/prometheus
加载并启动服务
systemctl daemon-reload && systemctl restart prometheus
systemctl status prometheus
安装node_exporter
下载安装包
访问 https://github.com/prometheus/node_exporter/releases 直接下载安装包或者 使用命令行进行下载
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
配置
解压node_exporter-1.3.1.linux-amd64.tar.gz并复制到/usr/local/bin
编辑配置文件
vi /etc/systemd/system/node_exporter.service
把以下内容并写入node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
加载服务并启动以及查看状态
systemctl daemon-reload && systemctl restart node_exporter && systemctl enable node_exporter
配置prometheus.yml并启动
访问:http://xxxx:9090
登录grafana
配置数据源
设置要读取的服务
只写入url其他默认
导入仪表盘
点击import进入主界面
点击右上角进行保存