Prometheus+Granafa入门

本文选择prometheus-2.26.1+grafana-7.5.7 

Prometheus:

  二进制文件安装:

  下载对应版本:
      官网:https://prometheus.io/download/
      github: https://github.com/prometheus/prometheus/releases
     

解压文件夹 并移动到/opt目录并创建prometheus数据目录

tar zxvf grafana-7.5.7.linux-amd64.tar.gz
mv prometheus-2.26.1.linux-amd64 /opt/prometheus
mkdir /opt/prometheus/data

prometheus配置文件:若没有需求,无需修改

      /opt/prometheus/prometheus.yml

# my global config
global:  #全局配置
  scrape_interval:     15s # 抓取间隔,默认继承global值1 minute.
  evaluation_interval: 15s # 评估规则间隔minute.
  # scrape_timeout is set to the global default (10s).抓取超时时间,默认继承global值,默认10秒

# Alertmanager configuration
alerting: #prometheus将报警规则推送到指定的alertmanager实例地址
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:  #prometheus根据这些规则信息,会推送报警信息到alertmanager中
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs: #指定抓取配置,prometheus的数据采集通过此片段配置
  # 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: 'node_service'
    static_configs:
    - targets: ['172.16.11.1:61111']

创建prometheus服务启动脚本,交由systemd管理。

vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
Restart=on-failure

[Install]
WantedBy=multi-user.target

服务启动、关闭

systemctl start  prometheus.service
systemctl stop   prometheus.service
systemctl enable prometheus.service

服务正常启动

[root@iZ0pu065btqsav6itfybi6Z prometheus]# ss -tnlp |grep 9090
LISTEN     0      128       [::]:9090                  [::]:*                   users:(("prometheus",pid=32274,fd=8))

浏览器打开:http://xxx.xx.xx.xx:9090/即可使用

数据采集

     prometheus已安装完毕,但无数据;使用Node Exporter采集数据【node_exporter-1.1.2】

           下载地址:https://github.com/prometheus/node_exporter/releases

    

tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz
mv node_exporter-1.1.2.linux-amd64/ node_exporter

安装启动Node_Exporter

cp /opt/node_exporter/node_exporter  /usr/local/bin/
chmod +x /usr/local/bin/node_exporter
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target


[Service]
ExecStart=/usr/local/bin/node_exporter --log.level=error --web.listen-address=:9100
ExecStop=/usr/bin/killall node_exporter
User=nobody
MemoryLimit=300M
CPUQuota=100%
[Install]
WantedBy=multi-user.target


systemctl start node_exporter.service
[root@iZ0pu065btqsav6itfybi6Z ~]# ss -tnlp |grep 9100
LISTEN     0      128       [::]:9100                  [::]:*                   users:(("node_exporter",pid=464,fd=3))

浏览器打开:http://xxx.xx.xx.xx:9100/metrics 即可查看node_exporter数据

Granafa安装:

    下载地址:https://github.com/grafana/grafana/releases

    下载并安装

tar zxvf grafana-7.5.7.linux-amd64.tar.gz
mv grafana-7.5.7 /opt/grafana
vim /etc/systemd/system/grafana.service
[Service]
ExecStart=/opt/grafana/bin/grafana-server --config=/opt/grafana/conf/defaults.ini  --homepath=/opt/grafana

[Install]
WantedBy=multi-user.target

[Unit]
Description=Grafana
After=network.target

systemctl start grafana

[root@iZ0pu065btqsav6itfybi6Z conf]# ss -tnlp |grep 3000
LISTEN     0      128       [::]:3000                  [::]:*                   users:(("grafana-server",pid=2680,fd=12))

浏览器打开:http://xxx.xx.xx.xx:3000/  默认账号密码admin / admin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值