Home / How To / How to install Prometheus Monitoring and node_exporter on CentOS 8

How to install Prometheus Monitoring and node_exporter on CentOS 8



Prometheus is an open source monitoring system that allows you to collect metrics from all configured target systems. Prometheus implements a multidimensional data model with powerful issues, great visualization, accurate warning and comes with many integrations.

Prometheus was originally created by SoundCloud 2012, but has now become an independent open source project maintained independently of the open source community – all components are available under the Apache 2 license on Github.

In this tutorial I will show you how to install and configure Prometheus and node_exporter. We install Prometheus monitoring system and then configure the node_exporter to collect measurement values ​​from the server. We will use the latest CentOS 8 server for this tutorial guide.

Prerequisites

  • CentOS 8 server
  • Root permissions

What should we do?

  • Create a new user and download Prometheus
  • Configure Prometheus as a Systemd service
  • Configure Firewalld
  • Install and configure node_exporter
  • Add node_exporter to Prometheus Server

      Testing [1
    96590161-CreateanewuseranddownloadPrometheus[1965901] In this tutorial, the Prometheus service runs as a user with no root. So we have to create a new user that is not root in the system. We will create a new user named & # 39; prometheus & # 39 ;, and all prometheus services will run under the prometheus user.

    Create new & # 39; prometheus & # 39; users with the command below.

      useradd -m -s / bin / bash prometheus 

    A new user has been created. Log in to the user and download the prometheus with the wget command.

      su - prometheus 
    wget https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1. linux-amd64.tar.gz

     Download Prometheus source code

    Extract the prometheus-xx.xxtar.gz file and rename the directory to & # 39; prometheus & # 39 ;.

      takes -xf prometheus -2.13.1.linux-amd64.tar.gz 
    etc. prometheus-2.13.1.linux-amd64 / prometheus /

    Then create a new "data" directory that will used as a "tsdb" storage.

      mkdir -p ~ / prometheus / data 

    Now prometheus is being loaded to the server, and all prometheus files are in the & # 39; / home / prometheus / prometheus & # 39; directory.

     Extract archive file

    Step 2 - Configure Prometheus as a Systemd service

    In this step we configure Prometheus as a Systemd service. We create a new service file prometheus.service in the & # 39; / etc / systemd / system & # 39; directory.

    Go to directory & # 39; / etc / systemd / system / & # 39; and create a new service file & # 39; prometheus.service & # 39; with vim editor.

      cd / etc / systemd / system / 
    vim prometheus.service

    Paste the prometheus service configuration below.

    [Unit]
    Description = Prometheus Server
    Documentation = https: //prometheus.io/ docs / introduction / overview /
    After = network-online.target [Service]
    User = prometheus
    Restart = on-failed

    # Change this line if you download
    #Prometheus on different search users
    ExecStart = / home / prometheus / prometheus / prometheus
    --config.file = / home / prometheus / prometheus / prometheus.yml
    --storage.tsdb.path = / home / prometheus / prometheus / data

    [Install]
    WantedBy = multi-user.target

    Save and exit.

    Now reload the systemd system with the systemctl command below.

      ystemctl daemon-reload 

    Start the prometheus service and have it started every time at system startup.

      systemctl start prometheus 
    systemctl enable prometheus

     Configure prometheus service in systemd

    Prometheus is now running as a systemd service, check it with the command below.

      systemctl status prometheus 

    Make sure you get "Running" service status.

    Or check it with the netstat command below. [19659017] netstat -plntu

    Make sure you get the result shown below.

     Checking the status of prometheus service

    By default, Prometheus runs under the port & # 39; 9090 & # 39 ;.

    Step 3 – Configure Firewalld

    If you are using Firewalld in your system, add the 9090 port to the Firewalld list ports.

    Open port 9090 for Prometheus access using the firewall cmd commands below.

      firewall cmd --add-port = 9090 / tcp --permanent 
    firewall-c md - load

    Now check the firewall rules.

      firewall cmd - list-all 

    And you will get the TCP port & # 39; 9090 & # 39; on the list.

     Configure firewall

    Then open your browser and type the server IP address with port 9090.

    http://10.5.5.15:9090/graph [19659058] Write & # 39; prometheus_http_requests_total & # 39; in the question box and click & # 39; Execute & # 39; button.

     Prometheus System Monitor Dashboard

    And you will see HTTP requests to the prometheus server with all time information, HTTP status code and method etc.

    Step 4 – Install and configure node_exporter

    node_exporter is an exporter of machine measurements that can be run on * Nix and Linux systems.

    In this tutorial we install the node_exporter on the same server prometheus. We will monitor and get the meter for the prometheus server.

    Log in to the prometheus user and download & # 39; node_exporter & # 39; using the wget command.

      su - prometheus 
    wget https://github.com/prometheus /node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gzebrit19659018achteExtract the node_exporter and rename the directory to & # 39; node_exporter & # 39 ;.

      tar -xf node_exporter-0.18.1 .linux-amd64.tar.gz 
    mv node_exporter-0.18.1.linux-amd64 node_exporter

     Install and configure node_exporter

    Then we create a new service file for the node_exporter. Back to the root shell, go to the & # 39; / etc / systemd / system & # 39; directory and create a new node_exporter service file & # 39; node_exporter.service & # 39; with vim.

      cd / etc / systemd / system / 
    vim node_exporter.service [19659018] Paste the following configuration.

    [Unit]
    Description = Nodes Export
    Want = network-online.target
    After = network-online.target [Service]
    User = prometheus
    ExecStart = / home / prometheus / node_exporter / node_exporter

    [Install]
    WantedBy = default.target

    Save and exit.

    Reload now the systemd system.

      systemctl daemon-reload 

    Then start node_exporter service and enable it to start each time at system startup.

      systemctl start node_exporter 
    systemctl enable node_exporter

     Start node_exporter

    The node_exporter service is now running on the server - check it using the node_exporter netstat command.

      systemctl status node_exporter 
    netstat -p lntu

    And you will get the node exporter running on standard port 9100.

     Check node_exporter status

    Step 5 - Add node_exporter to Prometheus Server

    In this step, the node_exporter adds to the prometheus server. Log in to the prometheus user and edit the & # 39; prometheus.yml & # 39; configuration file.

    Login to the prometheus user.

      su - prometheus 

    Go to directory & # 39; prometheus & # 39; and edit the configuration file & # 39; prometheus.yml & # 39; .

      cd ~ / prometheus / 
    vim prometheus.yml

    Under the line "scrape_config", add new job name node_exporter by copy paste the configuration below.

      - job name: & # 39; node_exporter & # 39; 
    static_configs:
    - target: ['localhost:9100']

    Save and exit.

    Now restart the prometheus service.

      systemctl restart prometheus 

    The node_exporter has been added to the prometheus server.

     restart the prometheus service

    Step 6 - Test Prometheus and node_exporter

    Open your browser and then enter the server's IP address.

    http: //10.5.5.15:9090/??19459005????19459021????19199009002 Write memo collectors & # 39; node_memory_MemAvailable_bytes & # 39; in the question box and click & # 39; Execute & # 39; button.

    And you will get the result as below. [19659002]   Test Prometheus

    You will have available memory on the server instance & # 39; localhost: 9100 & # 39; and the job name & # 39; node exporter & # 39 ;.

    Or, if you want to access node_export's raw data, you must add node_exporter port 9100 to the firewall.

      firewall-cmd --add-port t = 9100 / tcp --permanent 
    firewall-cmd - load

    And then enter the server's IP address with port 9100.

    http://10.5.5.15:9100/ metrics

    And you will get the node_export raw data shown below.

     Prometheus Metrics

    As a result, installation and configuration of the prometheus monitoring system with node_exporter on CentOS 8 Server has been successfully completed.

    Reference


Source link