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...

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生运维社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值