侧边栏壁纸
博主头像
zyixin

当你觉得为时已晚的时候,恰恰是最早的时候

  • 累计撰写 66 篇文章
  • 累计创建 0 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Prometheus+Grafana监控

zyixin
2022-04-01 / 0 评论 / 0 点赞 / 3,354 阅读 / 3,225 字
温馨提示:
本文最后更新于 2022-04-01,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1 Prometheus + Grafana实现监控

1.1 Prometheus server部署

首先从 官网的下载页面 获取 Prometheus 的最新版本和下载地址
下载地址:https://prometheus.io/download/
上传软件包到服务器,解压软件包,并检查 Prometheus 版本:

[root@prometheus ~]# cd /usr/local/src
[root@prometheus src]# rz -E
[root@prometheus src]# tar -zxf prometheus-2.32.1.linux-amd64.tar.gz
[root@prometheus src]# mv prometheus-2.32.1.linux-amd64 prometheus-2.32.1
[root@prometheus src]# cd prometheus-2.32.1;./prometheus --version
prometheus, version 2.32.1 (branch: HEAD, revision: 41f1a8125e664985dd30674e5bdf6b683eff5d32)
  build user:       root@54b6dbd48b97
  build date:       20211217-22:08:06
  go version:       go1.17.5
  platform:         linux/amd64

编辑配置文件

[root@prometheus src]# vim prometheus.yml
# 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: ["10.130.77.62:9090"]        ----修改localhost为本机IP

编辑服务启动文件,运行 Prometheus server

[root@prometheus src]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus server daemon
Documentation=https://prometheus.io/docs/
After=network.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/src/prometheus-2.32.1/prometheus \
    --config.file "/usr/local/src/prometheus-2.32.1/prometheus.yml" \
    --storage.tsdb.path "/usr/local/src/prometheus-2.32.1/data" \
    --storage.tsdb.retention.time=45d \
    --web.console.templates "/usr/local/src/prometheus-2.32.1/consoles" \
    --web.console.libraries "/usr/local/src/prometheus-2.32.1/console_libraries" \
    --web.max-connections=1024 \
    --web.external-url "http://10.130.77.62:9090" \
    --web.listen-address "10.130.77.62:9090" \
    --web.enable-lifecycle
Restart=no
[Install]
WantedBy=multi-user.target

-运行 Prometheus server
[root@prometheus src]# systemctl daemon-reload
[root@prometheus src]# systemctl start prometheus

页面访问prometheus,查看页面登陆是否正常
http://10.130.77.62:9090
prometheus

1.2 Grafana Server

首先从 官网的下载页面 获取 Grafana 的最新版本和下载地址
下载地址:https://grafana.com/grafana/download/8.3.1
上传软件包到服务器,解压软件包

[root@prometheus src]# cd /usr/local/src
[root@prometheus src]# rz -E
[root@prometheus src]# tar -zxvf grafana-enterprise-8.3.3.linux-amd64.tar.gz
[root@prometheus src]# mv grafana-enterprise-8.3.1.linux-amd64  grafana-enterprise-8.3.3
[root@prometheus src]# cd grafana-8.3.3/conf
[root@prometheus conf]# cp sample.ini grafana.ini
[root@prometheus conf]# cd ../bin/
[root@prometheus bin]# nohup ./grafana-server -config ../conf/grafana.ini   > /dev/null &

页面访问grafana,查看页面是否正常
http://10.130.77.62:3000
gragana

访问能力
将 Prometheus 服务端口 9090 、Grafana 服务端口 3000 透传公网实现访问。「 不需要使用 Nginx 代理,代理会造成访问问题。 」

1.3 Grafana-WebUI配置

访问 http://10.130.77.62:3000
会跳转到 Grafana 的 Login 界面,使用默认用户名/密码: admin/admin,首次登入后会跳转到密码修改页面。「 务必设置高复杂度密码 」
然后进行下面的监控配置
gragana配置

0

评论区