网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

centos7.8如何安装prometheus和grafana

小编给大家分享一下centos7.8如何安装prometheus和grafana,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

创新互联专业为企业提供南川网站建设、南川做网站、南川网站设计、南川网站制作等企业网站建设、网页设计与制作、南川企业网站模板建站服务,十载南川做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

安装准备

  • 虚拟机:centos7.8 2台

本实践中以 2台已安装centos7.8的虚机作为实践环境安装prometheus2.8.1和grafana,并在prometheus中配置对这2台主机的监控。

具体安装规划如下:

hostname

ip

os

cpu

memory

disk

备注

prometheus-host

172.22.3.148

centos7.8

2c

2g

20g

prometheus
grafana
node_exporter

prometheus-node

172.22.3.149

centos7.8

2c

2g

20g

node_exporter

  • 相关安装文件

https://github.com/prometheus/prometheus/releases/download/v2.24.0/prometheus-2.24.0.linux-amd64.tar.gz
https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm
https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

备注:如无说明,以下部署均在prometheus-host部署

安装prometheus

  • 下载

# cd /opt
# wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz
  • 安装

# cd /opt
# tar -zxf prometheus-2.8.1.linux-amd64.tar.gz
# mv prometheus-2.8.1.linux-amd64 prometheus
  • 启动

# cd /opt/prometheus
# ./prometheus
  • 创建service并设置自动启动

## 创建service
# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
## 设置自启动
# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
## 启动服务
# systemctl start prometheus
  • 访问prometheus

浏览器地址栏输入 http://172.22.3.148:9090

centos7.8如何安装prometheus和grafana

安装grafana

  • 下载

# cd /opt
# wget https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm
  • 安装

# cd /opt
# yum install grafana-7.3.6-1.x86_64.rpm
  • 启动

## 安装完成后会自动生成grafana-server的service
systemctl daemon-reload
systemctl start grafana-server
  • 设置自动启动

## 设置自启动
# systemctl enable grafana-server
  • 访问grafana并配置默认数据源

浏览器地址栏输入 http://172.22.3.148:3000

centos7.8如何安装prometheus和grafana

使用默认用户名密码 admin/admin登录

centos7.8如何安装prometheus和grafana

首次登录后需要设置新密码如上。

granfa安装后需要配置数据源

centos7.8如何安装prometheus和grafana

选择Prometheus,点击Select

centos7.8如何安装prometheus和grafana

只需要设置URL为http://localhost:9090

centos7.8如何安装prometheus和grafana

其它保持默认,直接点“Save & Test”按钮即可

centos7.8如何安装prometheus和grafana

弹出保存成功提示,点“Back”按钮返回。

centos7.8如何安装prometheus和grafana

可以看到grafana已经保存了一个数据源。

安装node_exporter并用prometheus配置主机监控

  • 下载

# cd /usr/local
# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
  • 安装

# cd /usr/local
# tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz
# mv node_exporter-1.0.1.linux-amd64/node_exporter ./bin/
  • 创建service并设置自动启动

## 创建service
# vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
## 设置自启动
# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.
## 启动服务
# systemctl start node_exporter
  • 在prometheus中配置对主机prometheus-host监控

修改prometheus配置文件prometheus.yml,在scrape_configs下增加如下配置

- job_name: 'prometheus-host'
    file_sd_configs:
      - files: ['/opt/prometheus/sd_config/prometheus-host.yml']
        refresh_interval: 5s

新增/opt/prometheus/sd_config/prometheus-host.yml文件,内容如下

cat /opt/prometheus/sd_config/prometheus-host.yml
- targets:
  - 172.22.3.149:9100

备注:每次修改配置完成,用promtool检测配置文件是否正确

# /opt/prometheus/promtool check config /opt/prometheus/prometheus.yml

重启prometheus

# systemctl restart prometheus

浏览器地址栏输入 http://172.22.3.148:9090/targets

centos7.8如何安装prometheus和grafana

可以看到targets已经增加了对主机prometheus-host的监控

  • 在grafana中配置面板显示对主机prometheus-host监控内容

centos7.8如何安装prometheus和grafana

点“+”按钮,弹出导入面板窗口

centos7.8如何安装prometheus和grafana

如图输入8919,点Load,grafana会直接从官方网站导入编号为8919的面板如下

centos7.8如何安装prometheus和grafana

选择数据源Prometheus,继续“Import”,显示node监控界面显示如下

centos7.8如何安装prometheus和grafana

在prometheus-nodes安装node_exporter并用prometheus配置主机监控

  • 安装步骤参考在prometheus-host安装node_exporter步骤

  • 在prometheus中配置对主机prometheus-nodes监控

修改prometheus配置文件prometheus.yml,在scrape_configs下增加如下配置

  - job_name: 'prometheus-nodes'
    file_sd_configs:
      - files: ['/opt/prometheus/sd_config/prometheus-nodes.yml']
        refresh_interval: 5s

新增/opt/prometheus/sd_config/prometheus-nodes.yml文件,内容如下

cat /opt/prometheus/sd_config/prometheus-nodes.yml
- targets:
  - 172.22.3.148:9100

重启prometheus

# systemctl restart prometheus

浏览器地址栏输入 http://172.22.3.148:9090/targets

centos7.8如何安装prometheus和grafana

可以看到targets已经增加了对主机prometheus-nodes的监控

访问grafana,也可以看到node监控界面多了prometheus-nodes的显示

centos7.8如何安装prometheus和grafana

以上是“centos7.8如何安装prometheus和grafana”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


名称栏目:centos7.8如何安装prometheus和grafana
新闻来源:http://bjjierui.cn/article/psoijg.html

其他资讯