一、规划
1、服务器
server IP | 软件/插件 | 用途 | 备注 |
---|---|---|---|
10.20.10.4 | Promethue+Grafana | 数据存储+web展示 | Grafana 展示 |
10.20.10.5 | Telegraf | 数据采集 | telegraf插件部署到远程服务器 |
… | … | … | … |
2、软件/版本
-
Promethue
version:2.26.0 download: https://prometheus.io/download/
-
Telegraf
version:1.18.1 download: https://portal.influxdata.com/downloads/ https://dl.influxdata.com/telegraf/releases/telegraf-1.18.1-1.x86_64.rpm
-
Grafana
version:7.5.3 download:https://grafana.com/grafana/download/7.5.3
二、部署
2.1 Promethue 部署
1、服务器上传或wget下载 prometheus 安装包
wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz
2、解压
tar -zxvf prometheus-2.26.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.26.0.linux-amd64/ /usr/local/prometheus
3、配置system管理
vim /lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
4、启动
systemctl start prometheus.service
netstat -lntp | grep 9090
5、验证
浏览器访问 http://10.20.10.4:9090/ 就可以访问到prometheus的主界面。
# http://10.20.10.4:9090/graph
# 这里只能只能查看到promethue采集到的自身服务器数据,因为还没和telegraf进行通信,所以采集不了其他服务器数据
2.2 Telegraf 部署
1、服务器上传或wget下载 Telegraf 安装包
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.18.1-1.x86_64.rpm
# 该服务部署在被采集数据的服务器上,其采集到的数据将会通过API形式存储到Promethue上并通过Grafana进行展示
2、安装
yum localinstall -y telegraf-1.18.1-1.x86_64.rpm
3、启动
systemctl start telegraf.service
# 配置文件:/etc/telegraf/telegraf.conf
# 子配置文件:/etc/telegraf/telegraf.d/*.conf
4、Telegraf 配置
vim /etc/telegraf/telegraf.conf
[[outputs.prometheus_client]]
# ## Address to listen on
listen = ":9273"
5、重启 telegraf
systemctl restart telegraf.service
6、Promethue 配置
vim /usr/local/prometheus/prometheus.yml
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'info'
static_configs:
- targets: ['10.20.10.5:9273']
7、重启 promethue
systemctl restart prometheus.service
8、再次验证 Promethue 采集的数据
浏览器访问:http://10.20.10.4:9090/graph
#在输入框输入关键字查看是否采集到其他服务器数据
2.3 Grafana 部署
1、安装
# 服务器上传或wget下载grafana-7.5.3-1.x86_64.rpm安装包。
yum localinstall -y grafana-7.5.3-1.x86_64.rpm
2、启动
systemctl start grafana-server
systemctl enable grafana-server
3、验证
浏览器访问 http://10.20.10.4:3000/ 就到了登录界面
默认登录用户:admin
默认登录密码:admin
4、导入相关模板(或自定义)
比较简单,导入详细过程省略。
# 注意导入后的模板的变量,可能要做相关的修改。
三、验证
如下图,数据采集成功:
四、FAQ
部署都非常简单,基本上不会出现什么问题,主要注意的是在导入 Grafana 模板时变量和数据源的修改,以及相应的参数调整。对于使用Promethue进行监控,需要对Linux系统有扎实的理论基础,因为要做很多的数学运算。