美文网首页
Prometheus安装

Prometheus安装

作者: 习惯了沉默乄 | 来源:发表于2020-01-09 20:42 被阅读0次

    一、安装Prometheus

    配置文件目录

    mkdir -p /etc/prometheus
    

    配置文件

    [root@izs3l77ihmekj0z ~]# cat /etc/prometheus/prometheus.yml 
    # my global config
    global:
      scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # 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']
    

    数据目录

    mkdir -p /data/prometheus
    chmod -R 777 /data
    

    安装

    docker run -d --restart=always --name prometheus -p 9090:9090 -v /etc/prometheus:/etc/prometheus -v /data/prometheus:/data -v /etc/localtime:/etc/localtime prom/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.retention=90d --storage.tsdb.path=/data   --storage.remote.read-sample-limit=5e6 --storage.remote.flush-deadline=60s --web.read-timeout=2m --query.timeout=2m --web.enable-lifecycle --web.enable-admin-api --query.max-concurrency=100 --alertmanager.timeout=10s
    

    验证

    Prometheus

    二、安装node-exporter

    安装

    docker run -d --restart=always --name=node-exporter -p 9100:9100 prom/node-exporter
    

    数据采集验证

    node-exporter

    创建job配置目录

    mkdir -p /etc/prometheus/files
    

    创建targets配置文件(可以自定义需要的标签)

    [root@prometheus files]# pwd
    /etc/prometheus/files
    [root@prometheus files]# cat prometheus.yml 
    [{
            "labels": {
                    "monitortype": "system",
                    "name": "192.168.153.130"
            },
            "targets": ["192.168.153.130:9100"]
    }]
    

    修改prometheus配置文件

    [root@prometheus prometheus]# cat prometheus.yml 
    # my global config
    global:
      scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # 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'
        scrape_interval: 60s
        honor_labels: true
        metrics_path: '/metrics'
        
        scheme: http
        file_sd_configs:
        - files:
          - /etc/prometheus/files/prometheus.yml
    

    重载配置

    curl -X POST http://localhost:9090/-/reload
    

    验证

    prometheus

    三、安装Grafana

    数据目录

    mkdir -p /data/grafana
    chmod -R 777 /data/grafana
    

    安装

    docker run -d -p 3000:3000 --name=grafana -v /data/grafana:/var/lib/grafana grafana/grafana
    

    验证

    grafana登录页面
    配置Prometheus数据源
    数据源配置
    数据源配置
    数据源配置
    新建系统监控
    新建DashBoard
    新建DashBoard
    新建DashBoard 新建DashBoard
    系统监控

    相关文章

      网友评论

          本文标题:Prometheus安装

          本文链接:https://www.haomeiwen.com/subject/bcuyactx.html