1 安装node_exporter
目标监控主机操作系统:Ubuntu Server 20.04
一键安装脚本:
sudo useradd --no-create-home --shell /bin/false node_exporter
&& cd /opt && wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
&& tar xvf node_exporter-0.18.1.linux-amd64.tar.gz
&& sudo mv node_exporter-0.18.1.linux-amd64 /opt/node_exporter
&& sudo chown node_exporter:node_exporter /opt/node_exporter -R
&& sudo touch /etc/systemd/system/node_exporter.service
&& sudo echo '[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/opt/node_exporter/node_exporter --collector.systemd
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/node_exporter.service
&& sudo systemctl daemon-reload
&& sudo systemctl enable node_exporter
&& sudo systemctl start node_exporter
&& sudo journalctl -f --unit node_exporter
安装完成后访问:http://${host}:9100/
,确认服务正常启动,如下图所示:
2 安装Prometheus时间序列数据库
Prometheus通过基于HTTP的pull方式采集时序数据,可以通过服务发现或者静态配置去获取要采集的目标服务器,支持单主节点工作,支持多种可视化图表及仪表盘。
在中控节点安装Prometheus,一键安装脚本:
sudo mkdir -p /opt/promethes
&& touch /opt/promethes/promethes.yml
&& sudo echo 'global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
scrape_interval: 5s
static_configs:
- targets: ['${host1}:9100','${host2}:9100', ...]
' > /opt/promethes/promethes.yml
&& docker run -d --restart=always
-p 9090:9090
-v /opt/promethes/promethes.yml:/etc/prometheus/prometheus.yml
prom/prometheus
- 加粗的targets的值是待监控的主机列表
安装完成后访问:http://${host}:9090/
,确认服务正常启动,如下图所示:
3 安装Grafana图形化监控控制台
- Grafana是一个开源的度量分析与可视化套件。 纯Javascript 开发的前端工具,通过访问库(如InfluxDB),展示自定义报表、显示图表等。Grafana的UI更加灵活,有丰富的插件,功能强大。
在中控节点(host0)安装Grafana,一键安装脚本:
sudo apt-get install -y apt-transport-https
&& sudo apt-get install -y software-properties-common wget
&& wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
&& echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
&& sudo apt-get update
&& sudo apt-get install grafana
安装完成后访问:http://${host0}:3000/
,确认服务正常启动
3.1 配置默认Prometheus数据源
左侧菜单Configuration → Data Sources
,点击/编辑默认Prometheus数据源,配置URL为:http://localhost:9090
,Save & Test
3.2 安装Node Exporter Dashboard
- 插件地址:https://grafana.com/grafana/d…
- 如何安装:https://grafana.com/docs/graf…
- 以配置文件的方式导入,配置文件
4 参考
- nwesterhausen/node_exporter_setup.md
- Node Exporter 接口说明
- Prometheus Installation
- Prometheus Getting Started
- 使用Node Exporter采集主机数据