zoukankan      html  css  js  c++  java
  • Prometheus入门到放弃(1)之Prometheus安装部署

    规划:

    IP 角色 版本
    10.10.0.13 prometheus-server 2.10
    10.10.0.11 node_exporter 0.18.1
    10.10.0.12 node_exporter 0.18.1

    1、下载

    官网:https://prometheus.io/download/

    [root@prometheus-server ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz

    2、创建运行用户

    [root@prometheus-server ~]# groupadd -r prometheus
    [root@prometheus-server ~]# useradd -r -g prometheus -d / -s /sbin/nologin -c "prometheus user" prometheus

    3、安装

    安装这里介绍两种方式:

    1、docker部署

    2、二进制部署 (本文采用)

      3.1 二进制部署


    [root@prometheus-server ~]# tar -xf prometheus-2.10.0.linux-amd64.tar.gz
    [root@prometheus-server ~]# mkdir /etc/prometheus
    [root@prometheus-server ~]# mkdir /var/lib/prometheus
    [root@prometheus-server ~]# cp prometheus-2.10.0.linux-amd64/prometheus /usr/local/bin/
    [root@prometheus-server ~]# cp prometheus-2.10.0.linux-amd64/prometheus.yml /etc/prometheus/
    [root@prometheus-server ~]# chown -R prometheus:prometheus /etc/prometheus
    [root@prometheus-server ~]# chown -R prometheus:prometheus /var/lib/prometheus/
    [root@prometheus-server ~]# vim /usr/lib/systemd/system/prometheus.service
    ## 配置启动脚本
    [Unit]
    Description=prometheus
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/usr/local/bin/prometheus
     --config.file=/etc/prometheus/prometheus.yml
     --storage.tsdb.path=/var/lib/prometheus
     --storage.tsdb.retention=15d
     --web.read-timeout=5m
     --web.max-connections=10
     --query.max-concurrency=20
     --query.timeout=2m
     --web.enable-lifecycle
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    ## 启动
    [root@prometheus-server ~]# systemctl enable prometheus
    [root@prometheus-server ~]# systemctl start prometheus
    [root@prometheus-server ~]# netstat -anlptu|grep :9090
    tcp        0      0 127.0.0.1:39868         127.0.0.1:9090          ESTABLISHED 3080/prometheus    
    tcp6       0      0 :::9090                 :::*                    LISTEN      3080/prometheus    
    tcp6       0      0 ::1:52200               ::1:9090                ESTABLISHED 3080/prometheus    
    tcp6       0      0 127.0.0.1:9090          127.0.0.1:39868         ESTABLISHED 3080/prometheus    
    tcp6       0      0 ::1:9090                ::1:52200               ESTABLISHED 3080/prometheus

    参数解释:

         --config.file=/etc/prometheus/prometheus.yml       ### prometheus配置文件
         --storage.tsdb.path=/var/lib/prometheus                ### prometheus 存储数据路径
         --storage.tsdb.retention=15d                                 ### prometheus采集数据保留时间
         --web.read-timeout=5m                                         ### 请求链接的最大等待时间           
         --web.max-connections=10                                  ### 最大链接数
         --query.max-concurrency=20                               ### 最大支持的并发查询量
         --query.timeout=2m                                             ### 单个查询超时时间
         --web.enable-lifecycle                                         ### 热加载

       3.2 docker部署

    官方介绍:https://github.com/prometheus/prometheus/tree/master

    docker方式部署需要先创建prometheus.yml文件

    [root@prometheus-server ~]# mkdir /opt/prometheus/
    [root@prometheus-server ~]# vim /opt/prometheus/prometheus.yml
    # my global config
    global:
      scrape_interval:     15s # 抓取数据的周期,默认为1min 
      evaluation_interval: 15s # 更新rules文件的周期,默认为1min
      # scrape_timeout is set to the global default (10s).
    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
        static_configs:
        - targets: ['localhost:9090']
    ## 运行
    [root@prometheus-server ~]# docker run -d -p 9090:9090 --user="root" --name prometheus -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /opt/prometheus/data:/prometheus prom/prometheus

     说明:

      1、--user:指定运行用户

      2、需要宿主机创建prometheus.yml配置文件

    3、浏览器访问

    启动后,直接浏览器访问端口9090

    这样,prometheus服务就安装好了。

  • 相关阅读:
    014-More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
    013-一个Activity怎么调用另一个Activity的方法返回数据(转)
    012-关于EditText中的getText()方法的返回值类型以及string的转换问题(转)
    011-frament中不能调用getSystemService()方法
    010-Android开发解决控件超出屏幕,不能正常显示的问题
    009-在Fragment中实现Activity跳转功能
    Oracle分区表
    Oracle构造列
    Oracle集合
    Oracle多对多、维表
  • 原文地址:https://www.cnblogs.com/tchua/p/11101445.html
Copyright © 2011-2022 走看看