需要用到的安装包:
Prometheus官方网站:https://prometheus.io/
主程序:
下载对应系统的软件包这里使用的是2.36.0的Linux版本
https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-2.36.0.linux-amd64.tar.gz
信息采集器node_exporter
https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
Grafana官方网站:https://grafana.com/
这里通过清华源下载的rpm包,因为系统提示清华源证书过期,所以添加了–no-check-certificate命令。
下载对应系统的安装包,建议下载7.0-8.0之间的版本(因为老师教程是这么说的)
wget –no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-7.3.0-1.x86_64.rpm
开始安装
Prometheus的主程序和采集器解压之后可以直接运行。
主程序为:prometheus 配置文件:prometheus.yml
这里将Prometheus的主程序和采集器分别放置在了
/usr/local/prometheus/prometheus和/usr/local/node_exporter/node_exporter目录下
然后,编辑主程序系统自启动文件:vim /etc/systemd/system/prometheus.service
============================================================================================================================
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus –config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
============================================================================================================================
编辑信息采集器系统自启动文件:vim /etc/systemd/system/node_exporter.service
============================================================================================================================
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=on-failure
ExecStart=/usr/local/node_exporter/node_exporter
PIDFile=/usr/local/node_exporter/node_exporter.pid
[Install]
WantedBy=multi-user.target
============================================================================================================================
保存后不忘systemctl daemon-reload一下
加入开机自启
systemctl enable prometheus
systemctl enable node_exporter
然后进入Prometheus的配置文件,添加监控端口:
vim /usr/local/prometheus/prometheus.yml
============================================================================================================================
# my global config
global:
scrape_interval: 15s #设置刷新时间,默认1分钟
evaluation_interval: 15s # 设置评估时间,默认1分钟
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration#报警设置,暂时不管
alerting:
alertmanagers:
– static_configs:
– targets:
# – alertmanager:9093
# Load rules once and periodically evaluate them according to the global ‘evaluation_interval’.#规则文件设置,暂时不管
rule_files:
# – “first_rules.yml”
# – “second_rules.yml”
# A scrape configuration containing exactly one endpoint to scrape:
# Here it’s Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.#设置任务名称
– job_name: “prometheus”
# metrics_path defaults to ‘/metrics’
# scheme defaults to ‘http’.
static_configs:
– targets: [“localhost:9090″,”127.0.0.1:9100”]#设置任务监听主机和端口。这里添加了node_exporter服务的9100端口
============================================================================================================================
保存退出。
启动node_exporter和prometheus服务
systemctl start node_exporter
systemctl start prometheus
查询服务状态
systemctl status node_exporter
systemctl status prometheus
查询服务状态正常运行后可以继续安装grafana
切换至grafana的下载目录并安装
yum install grafana-7.3.0-1.x86_64.rpm
启动、查询、加入开机自启
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server
然后可以访问到服务器的默认3000端口。
配置grafana的数据来源和Dashboard
默认登陆用户名和密码为admin
进入后可修改
进入grafana图形化界面的Configuration——DataSources
添加Prometheus数据库
Url填写Prometheus服务端口http://127.0.0.1:9090
保存即可
在图形化界面Create——Import选项中,可以导入官方的图形化界面(网址:https://grafana.com/grafana/dashboards/)
这里下载的是:主机基础监控(cpu,内存,磁盘,网络)(搜索框搜索关键字即可)
安装完成后,在主界面载入Dashboard选择IP地址为node_exproter的端口127.0.0.1:9100
图形化界面显示成功
评论(已关闭)
评论已关闭