zoukankan      html  css  js  c++  java
  • Prometheus安装

    二进制包安装

    我们可以到 Prometheus.io 二进制安装包下载页面,根据自己的操作系统选择下载对应的安装包。下面我们将以 ubuntu server 作为演示。

    开始安装

    • linux amd64 (ubuntu server)
    • prometheus 1.6.2
    1. 下载 Prometheus Server

      1.1 创建下载目录,以便安装过后清理掉

      • $ mkdir ~/Download
      • $ cd ~/Download
    2. 使用 wget 下载 Prometheus 的安装包

      wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz
    1. 使用 tar 解压缩 prometheus-1.6.2.linux-amd64.tar.gz
    tar -xvzf ~/Download/prometheus-1.6.2.linux-amd64.tar.gz
    
    将文件重命名并移动到urs/local/prometheus中
    $ mv prometheus-1.6.3.linux-amd64 /usr/local/prometheus
    
    1. 验证是否安装成功
    cd /usr/local/prometheus
    ./prometheus --version
    
    如果你看到类似输出,表示你已安装成功:
    prometheus, version 1.6.2 (branch: master, revision: xxxx)
      build user:       xxxx
      build date:       xxxx
      go version:       go1.8.1
    
    1. 启动 Prometheus Server

    ./prometheus 如果 prometheus 正常启动,你将看到如下信息:

    INFO[0000] Starting prometheus (version=1.6.2, branch=master, revision=b38e977fd8cc2a0d13f47e7f0e17b82d1a908a9a)  source=main.go:88
    INFO[0000] Build context (go=go1.8.1, user=root@c99d9d650cf4, date=20170511-13:03:00)  source=main.go:89
    INFO[0000] Loading configuration file prometheus.yml     source=main.go:251
    INFO[0000] Loading series map and head chunks...         source=storage.go:421
    INFO[0000] 0 series loaded.                              source=storage.go:432
    INFO[0000] Starting target manager...                    source=targetmanager.go:61
    INFO[0000] Listening on :9090                            source=web.go:259
    

    通过启动日志,可以看到 Prometheus Server 默认端口是 9090。

    1. 设置自动启动: 创建Systemd服务
    • ps: 次数有实在 /etc/systemd/system/prometheus.service 处创建服务的。
    $ vim /usr/lib/systemd/system/prometheus.service
    
    [Unit]
    Description=Prometheus
    Documentation=https://prometheus.io/
    After=network.target
    
    [Service]
    Type=simple
    #User=prometheus
    ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
    
    
    systemctl daemon-reload
    systemctl restart prometheus  
    systemctl status prometheus
    
    • ps: 此处restart 因之前启动过了,第一次可以使用start
    • 见到这样的效果及标识自启动成功:
    ● prometheus.service - Prometheus
       Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2018-07-19 16:14:50 CST; 2s ago
         Docs: https://prometheus.io/
     Main PID: 1609 (prometheus)
       CGroup: /system.slice/prometheus.service
               └─1609 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
    
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.66114208Z caller=main.go:223 build_context="(go=go1.10.3, user=root@5258e0bd9cc1, date=20180712-14:02:52)"
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.661172135Z caller=main.go:224 host_details="(Linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 dev-function.novalocal (none))"
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.661198165Z caller=main.go:225 fd_limits="(soft=1024, hard=4096)"
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.662421315Z caller=web.go:415 component=web msg="Start listening for connections" address=0.0.0.0:9090
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.662396155Z caller=main.go:533 msg="Starting TSDB ..."
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=warn ts=2018-07-19T08:14:50.663013777Z caller=wal.go:234 component=tsdb msg="invalid segment file detected, truncating WAL" err="open /var/lib/prometheus/wal/0...theus/wal/000001
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.669715227Z caller=main.go:543 msg="TSDB started"
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.669777093Z caller=main.go:603 msg="Loading configuration file" filename=/usr/local/prometheus/prometheus.yml
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.670486293Z caller=main.go:629 msg="Completed loading of configuration file" filename=/usr/local/prometheus/prometheus.yml
    Jul 19 16:14:50 dev-function.novalocal prometheus[1609]: level=info ts=2018-07-19T08:14:50.670524244Z caller=main.go:502 msg="Server is ready to receive web requests."
    Hint: Some lines were ellipsized, use -l to show in full.
    
    

    当 Prometheus 启动后,你可以通过浏览器来访问 http://IP:9090,可以看到对应的页面

    总结

    可以看出 Prometheus 二进制安装非常方便,没有依赖,自带查询 web 界面。 在生产环境中,我们可以将 Prometheus 添加到 init 配置里,或者使用 supervisord 作为服务自启动。

  • 相关阅读:
    Windows7下面手把手教你安装Django
    windows系统下Python环境的搭建
    PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点
    结构化程序设计 ?
    编译性语言、解释性语言和脚本语言
    在linux中关闭防火墙
    Linux下Apache服务的查看和启动
    AWS中,如果使用了ELB,出现outofservice
    亚马逊的PuTTY连接AWS出现network error connection refused,终极解决方案。
    9.Node.js 包管理器npm
  • 原文地址:https://www.cnblogs.com/gmander/p/9321668.html
Copyright © 2011-2022 走看看