iis服务器助手广告广告
返回顶部
首页 > 资讯 > 操作系统 >CentOS7如何搭建Prometheus监控Linux主机
  • 193
分享到

CentOS7如何搭建Prometheus监控Linux主机

2023-06-15 17:06:05 193人浏览 八月长安
摘要

这期内容当中小编将会给大家带来有关Centos7如何搭建prometheus监控linux主机,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。 简介prometheus可以拆分成多个节点进行指标收

这期内容当中小编将会给大家带来有关Centos7如何搭建prometheus监控linux主机,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

 简介

prometheus可以拆分成多个节点进行指标收集。

安装环境:CentOS7


安装prometheus

wget -c https://GitHub.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz tar zxvf prometheus-2.23.0.linux-amd64.tar.gz  -C /opt/ cd /opt/ ln -s prometheus-2.23.0.linux-amd64 prometheus cat > /etc/systemd/system/prometheus.service <<EOF [Unit] Description=prometheus After=network.target  [Service] Type=simple WorkingDirectory=/opt/prometheus ExecStart=/opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" LimitNOFILE=65536 PrivateTmp=true RestartSec=2 StartLimitInterval=0 Restart=always  [Install] WantedBy=multi-user.target EOF systemctl daemon-reload  systemctl enable prometheus systemctl start prometheus

配置Prometheus

这里配置的是监听/opt/prometheus/servers/目录下的JSON文件

cat > /opt/prometheus/prometheus.yml <<EOF # my global config global:   scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.   evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.   # 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']        - job_name: 'servers'     file_sd_configs:     - refresh_interval: 61s       files:         - /opt/prometheus/servers/*.json EOF systemctl restart prometheus

json格式


每个json文件需要是一个数组对象,如果不需要自定义标签,可以直接写到targets里面去也可以,可以有多个文件

[         {         "targets": [             "192.168.1.164:9100"         ],         "labels": {             "instance": "192.168.1.164",             "job": "node_exporter"         }     },     {         "targets": [             "192.168.1.167:9100"         ],         "labels": {             "instance": "192.168.1.167",             "job": "node_exporter"         }     } ]

安装node_exporter

安装到/opt/node_exporter路径下,保持默认的端口

https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz tar zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt/ cd /opt/ ln -s  node_exporter-1.0.1.linux-amd64 node_exporter cat > /etc/systemd/system/node_exporter.service <<EOF [Unit] Description=node_exporter After=network.target  [Service] Type=simple WorkingDirectory=/opt/node_exporter ExecStart=/opt/node_exporter/node_exporter LimitNOFILE=65536 PrivateTmp=true RestartSec=2 StartLimitInterval=0 Restart=always  [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable node_exporter systemctl start node_exporter

图形展示

直接安装grafana进行展示

yum -y install   https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm systemctl enable grafana-server systemctl start grafana-server

启动之后,grafana默认监听的是3000端口,直接使用浏览器进行访问就可以了,默认用户名密码是admin/admin,第一次登陆之后会提示修改。


配置数据源:鼠标左边的菜单 Configuration -> Data Source -> Add data source ->  选择prometheus -> url那栏填入prometheus的地址就可以了 -> 最后 Save & test 就可以了。

grafana.com/grafana/dashboards 官网已经有人做好的模板,我们直接import进来就可以了。

导入面板:鼠标左边的菜单 Dashboards -> Import -> 填入id -> Load ->  选择数据源就可以了。

我经常用的是:1860 、8919 这两个来查看node_exporter监控

安装这些服务都是使用systemd进行管理的,操作起来比较方便的。

这里没有设置告警,可以根据自己的需要设置对应的告警规则,使用alertmanager进行告警。

上述就是小编为大家分享的CentOS7如何搭建Prometheus监控Linux主机了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网操作系统频道。

--结束END--

本文标题: CentOS7如何搭建Prometheus监控Linux主机

本文链接: https://www.lsjlt.com/news/280944.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作