温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos7.8如何安装prometheus和grafana

发布时间:2021-06-17 10:49:35 来源:亿速云 阅读:368 作者:小新 栏目:云计算

小编给大家分享一下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”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI