安装Prometheus及alertmanager

Prometheus是一个开源监控解决方案,用于收集和聚合指标作为时间序列数据。

1、首先我们需要准备prometheus和alertmanager的安装包

在线下载地址:Download | Prometheushttps://prometheus.io/download/

2、我们进行安装包的解压:

[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# cd /usr/local/upload/
[root@iZf8z2s66jr2bnch7gubzxZ upload]# ll
total 70284
-rw-r--r-- 1 root root 25710888 Oct 28 15:09 alertmanager-0.21.0.linux-amd64.tar.gz
-rw-r--r-- 1 root root 10111972 Oct 31 09:47 node_exporter-1.4.0.linux-amd64.tar.gz
-rw-r--r-- 1 root root 36142430 Oct 28 15:32 prometheus-2.5.0.linux-amd64.tar.gz
[root@iZf8z2s66jr2bnch7gubzxZ upload]# tar -zxf alertmanager-2.5.0.linux-amd64.tar.gz  -C /usr/local

3、对解压后的文件夹进行重命名

mv prometheus-2.5.0.linux-amd64 prometheus
cd prometheus
[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# ll
total 94956
drwxr-xr-x 2 3434 3434     4096 Nov  6  2018 console_libraries
drwxr-xr-x 2 3434 3434     4096 Nov  6  2018 consoles
drwxr-xr-x 3 root root     4096 Oct 28 15:40 data
-rw-r--r-- 1 3434 3434    11357 Nov  6  2018 LICENSE
-rw-r--r-- 1 3434 3434     2769 Nov  6  2018 NOTICE
-rwxr-xr-x 1 3434 3434 58074162 Nov  6  2018 prometheus
-rw-r--r-- 1 3434 3434      424 Oct 31 14:19 prometheus.yml
-rwxr-xr-x 1 3434 3434 39113694 Nov  6  2018 promtool
drwxr-xr-x 2 root root     4096 Oct 31 11:52 rules

        Promtool 是 Prometheus 提供的一个运维工具,用来对 Prometheus 进行检查,之前只有最简单的检查配置文件和规则文件的功能,现在已经有了更多的新功能,包括查询指标、debug 服务、对数据库进行检查等等。

./promtool --help
usage: promtool [<flags>] <command> [<args> ...]

Tooling for the Prometheus monitoring system.

Flags:
  -h, --help     Show context-sensitive help (also try --help-long and --help-man).
      --version  Show application version.

Commands:
  help [<command>...]
    Show help.

  check config <config-files>...
    Check if the config files are valid or not.

  check rules <rule-files>...
    Check if the rule files are valid or not.

  check metrics
    Pass Prometheus metrics over stdin to lint them for consistency and correctness.

    examples:

    $ cat metrics.prom | promtool check metrics

    $ curl -s http://localhost:9090/metrics | promtool check metrics

  update rules <rule-files>...
    Update rules from the 1.x to 2.x format.

  query instant <server> <expr>
    Run instant query.

  query range [<flags>] <server> <expr>
    Run range query.

  query series --match=MATCH [<flags>] <server>
    Run series query.

  query labels <server> <name>
    Run labels query.

  debug pprof <server>
    Fetch profiling debug information.

  debug metrics <server>
    Fetch metrics debug information.

  debug all <server>
    Fetch all debug information.

  test rules <test-rule-file>...
    Unit tests for rules.

4、编写Prometheus.service文件

[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

[Install]
WantedBy=multi-user.target

5、进行热部署一下

[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# systemctl enable prometheus

6、启动服务并且查看状态

[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# systemctl start prometheus    #启动
[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# systemctl restart prometheus    #重启
[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# systemctl status prometheus
● prometheus.service - https://prometheus.io
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-10-31 14:53:05 CST; 6s ago
 Main PID: 20022 (prometheus)
    Tasks: 10 (limit: 11710)
   Memory: 52.0M
   CGroup: /system.slice/prometheus.service
           └─20022 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.676138637Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1666936800000 max>
Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.67619124Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1666980000000 maxt>
Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.676234048Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1667044800000 max>
Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.676258935Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1667174400000 max>
Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.676294408Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1667109600000 max>
Oct 31 14:53:05 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:05.676317544Z caller=repair.go:35 component=tsdb msg="found healthy block" mint=1667181600000 max>
Oct 31 14:53:06 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:06.611605316Z caller=main.go:572 msg="TSDB started"
Oct 31 14:53:06 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:06.611657732Z caller=main.go:632 msg="Loading configuration file" filename=/usr/local/prometheus/>
Oct 31 14:53:06 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:06.612593514Z caller=main.go:658 msg="Completed loading of configuration file" filename=/usr/loca>
Oct 31 14:53:06 iZf8z2s66jr2bnch7gubzxZ prometheus[20022]: level=info ts=2022-10-31T06:53:06.612612556Z caller=main.go:531 msg="Server is ready to receive web requests."

访问本机地址:9090就能看到一下页面。

7、安装alertmanager重复以上步骤

注意:alertmanager.service步骤有所差异

[Unit]
Description=AlertManager
Documentation=
After=network.target
 
[Service]
WorkingDirectory=/usr/local/alertmanager
ExecStart=/usr/local/alertmanager/alertmanager 
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -KILL $MAINPID
Type=simple
KillMode=control-group
Restart=on-failure
RestartSec=100ms
 
[Install]
WantedBy=multi-user.target

8、安装好alertmanager后需关联Prometheus

[root@iZf8z2s66jr2bnch7gubzxZ prometheus]# cat prometheus.yml 
global:
  scrape_interval:     15s 
  evaluation_interval: 15s 

alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - "127.0.0.1:9093"     #alertmanager地址

rule_files:
   - "rules/*.yml"    #配置报警规则文件
scrape_configs:
  - job_name: 'prometheus'    #应用名
    static_configs:
    - targets: ['localhost:9090']    #地址
  - job_name: "node"
    basic_auth:    #认证
      username: "node"    
      password: "node@2013"
    static_configs:
    - targets: ['localhost:9100']    #地址

编辑好配置文件记得重启Prometheus应用!

这样的话一个简单的Prometheus就部署和启动完成了

 下图是alertmanager的访问地址:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值