其他分享
首页 > 其他分享> > Prometheus之Prometheus部署

Prometheus之Prometheus部署

作者:互联网

文章目录

1. 基础环境准备

# 查看系统版本
$ cat  /etc/redhat-release 
CentOS Linux
release 7.7.1908 (Core)


# 查看系统内核
$ uname -r
3.10.0-1062.18.1.el7.x86_64


# 安装目录
$ pwd
/application/prometheus
# 数据存储目录
$ pwd
/application/data/prometheus_data

2. 安装Prometheus

# 下载prometheus安装包
$ wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz 
# 解压安装包
$ tar xzvf prometheus-2.9.2.linux-amd64.tar.gz
$ mv prometheus-2.9.2.linux-amd64 ../prometheus
# 创建启动用户
$ groupadd prometheus
$ useradd -g prometheus -s /sbin/nologin prometheus

# 创建prometheus存储目录并授权
$ mkdir -p /application/data/prometheus_data
$ chown -R prometheus.prometheus prometheus_data/

prometheus.yml配置文件说明

global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s 
  # 我们可以附加一些指定标签到采样点度量标签列表中, 用于和第三方系统进行通信, 包括:federation, remote storage, Alertmanager
  external_labels:
    # 下面就是拉取自身服务采样点数据配置
    monitor: 'codelab-monitor'
scrape_configs:
  # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上
  - job_name: 'prometheus'
    # 覆盖global的采样点,拉取时间间隔5s
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']


3. 启动Prometheus

3.1 创建Prometheus系统服务

$ vim /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/application/prometheus/prometheus --config.file=/application/prometheus/prometheus.yml --storage.tsdb.path=/application/data/prometheus_data --web.enable-lifecycle
Restart=on-failure
[Install]
WantedBy=multi-user.target


# 注释
# 指定配置文件
--config.file="prometheus.yml"
# 指定监听地址端口
--web.listen-address="0.0.0.0:9090" 
# 最大连接数
--web.max-connections=512
# tsdb数据存储的目录,默认当前data/
--storage.tsdb.path="data/"
# premetheus 存储数据的时间,默认保存15天
--storage.tsdb.retention=15d 


3.2 启动Prometheus


$ systemctl start prometheus
$ systemctl status prometheus
$ systemctl enable prometheus


# 通过此命令查看如果没有报错信息则安装成功
$ systemctl status prometheus
● prometheus.service - prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-05-13 10:14:52 CST; 11h ago
 Main PID: 13860 (prometheus)
   CGroup: /system.slice/prometheus.service
           └─13860 /application/prometheus/prometheus --config.file=/application/prometheus/prometheus.yml --storage.tsdb.path=/application/data/prometh...

May 13 15:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T07:00:04.817Z caller=compact.go:499 component=tsdb msg="write bloc...174513ms
May 13 15:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T07:00:04.826Z caller=head.go:540 component=tsdb msg="head GC compl...234353ms
May 13 17:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T09:00:04.820Z caller=compact.go:499 component=tsdb msg="write bloc...605426ms
May 13 17:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T09:00:04.830Z caller=head.go:540 component=tsdb msg="head GC compl...238041ms
May 13 17:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T09:00:04.885Z caller=compact.go:444 component=tsdb msg="compact bl...809555ms
May 13 19:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T11:00:04.820Z caller=compact.go:499 component=tsdb msg="write bloc...184914ms
May 13 19:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T11:00:04.830Z caller=head.go:540 component=tsdb msg="head GC compl...213823ms
May 13 19:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T11:00:04.891Z caller=compact.go:444 component=tsdb msg="compact bl...302863ms
May 13 21:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T13:00:04.818Z caller=compact.go:499 component=tsdb msg="write bloc...528048ms
May 13 21:00:04 wulu-prometheus-1 prometheus[13860]: level=info ts=2020-05-13T13:00:04.832Z caller=head.go:540 component=tsdb msg="head GC compl...203503ms

4. promtool工具日常使用

$ ./promtool check config ./prometheus.yml    # 检查prometheus.yml配置文件语法
Checking ./prometheus.yml
  SUCCESS: 0 rule files found
$ ./promtool check rules ./rules.yml     # 检查rules.yml配置文件语法
Checking ./rules.yml
  SUCCESS: 0 rule files found


标签:00,13,05,部署,prometheus,13860,Prometheus,tsdb
来源: https://blog.csdn.net/xcndafad/article/details/112143180