Prometheus(二)安装启动
2019-07-17 本文已影响0人
咩咩的毛球
一、安装
- 放在:/usr/local/prometheus/
- Linux 安装 Prometheus
$ wget https://github.com/prometheus/prometheus/releases/download/v1.6.3/prometheus-1.6.3.linux-amd64.tar.gz
$ tar xzvf prometheus-1.6.3.linux-amd64.tar.gz
$ mv prometheus-1.6.3.linux-amd64 /usr/local/prometheus
- 查看
root@VM-0-9-ubuntu:/# cd /usr/local/prometheus/
root@VM-0-9-ubuntu:/usr/local/prometheus# ./prometheus --version
prometheus, version 1.6.3 (branch: master, revision: c580b60c67f2c5f6b638c3322161bcdf6d68d7fc)
build user: root@a6410e65f5c7
build date: 20170522-09:15:06
go version: go1.8.1
- 配置Prometheus
在prometheus目录下有一个名为prometheus.yml的主配置文件。其中包含大多数标准配置及prometheus的自检控配置,默认配置文件如下:
$ vim /usr/local/prometheus/prometheus.yml
# 全局配置
global:
scrape_interval: 15s # 默认抓取间隔, 15秒向目标抓取一次数据。
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# 这个标签是在本机上每一条时间序列上都会默认产生的,主要可以用于联合查询、远程存储、Alertmanger时使用。
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# 这里就表示抓取对象的配置
# 这里是抓去promethues自身的配置
scrape_configs:
# job name 这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:"prometheus"}的标签。
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
# 重写了全局抓取间隔时间,由15秒重写成5秒。
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- 创建用户
单独创建一个专门用于运行prometheus的用户,不用root运行程序是一种好习惯。主目录为/var/lib/prometheus,用作prometheus的数据目录。
$ groupadd prometheus
$ useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
- 创建Systemd服务
$ vim /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus -config.file=/usr/local/prometheus/prometheus.yml -storage.local.path=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
-
启动Prometheus
$ systemctl start prometheus
-
验证Prometheus是否启动成功
root@VM-0-9-ubuntu:/usr/local/prometheus# systemctl status prometheus
● prometheus.service - prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-17 14:06:09 CST; 14s ago
Main PID: 5572 (prometheus)
Tasks: 7
Memory: 12.1M
CPU: 135ms
CGroup: /system.slice/prometheus.service
└─5572 /usr/local/prometheus/prometheus -config.file=/usr/local/prometheus/prometheus.yml -storage.local.path=/var/lib/prometheus
Jul 17 14:06:09 VM-0-9-ubuntu systemd[1]: Started prometheus.
Jul 17 14:06:09 VM-0-9-ubuntu prometheus[5572]: time="2019-07-17T14:06:09+08:00" level=info msg="Starting prometheus (version=1.6.3, branch=master, revision=c
- 访问自带Web
- Prometheus 自带一个比较简单的Web,可以查看表达式搜索结果、报警配置、prometheus配置,exporter状态等。自带Web默认在http://ip:9090。
- Prometheus 也自带exporter,我们通过请求 http://ip:9090/metrics 可以查看从exporter中能具体抓到哪些数据。