Prometheus: Prometheus+Grafana installation configuration

I. Basic Environment

 

system

IP

Monitor host

CentOS 7

192.168.56.200

Monitored host

CentOS 7

192.168.56.201

II. Prometheus server installation

The following operations are performed on the monitoring host (192.168.56.200).

2.0 turn off the machine firewall

# systemctl stop firewalld
# systemctl disable firewalld

2.1 install go environment

Because Prometheus is developed by go language, you need to install go environment on monitoring host before installing Prometheus. Here, the source code compilation is used for installation.

Due to the domestic network environment, if you can access the Internet scientifically, you can download the latest version of the installation package from this address: https://golang.org/dl/ .

If you can't access the Internet scientifically, you can download from this link: link: https://pan.baidu.com/s/1gefGeXmoFmjGxSGxgCuQfw ﹣ extraction code: cz6l

After downloading the installation package, upload it to the / usr/local directory of the monitoring host.

Unzip the installation package

# tar -xvf go1.13.1.linux-amd64.tar.gz

2.1.2 configure environment variables

Add the / usr/loacl/go/bin directory to the PATH variable. Add to / etc/profile or $HOME/.profile

# vim /etc/profile
// Add on last line
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
// wq After saving and exiting source Once
# source /etc/profile

Execute go version. If the version number is displayed, the Go environment is installed successfully.

2.2 installing Prometheus

Download address of installation package: https://prometheus.io/download/#prometheus 

2.2.1 installation

Upload the downloaded installation package to / usr/local directory

Unzip the installation package:

#  tar -xvf prometheus-2.4.0.linux-amd64.tar.gz
#  mv prometheus-2.4.0.linux-amd64/ prometheus

2.2.2 boot

The configuration file for Prometheus is located in / usr/local/Prometheus/prometheus.yml, where the default configuration is used.

Enter the unzipped folder and start Prometheus.

#  cd prometheus
#  ./prometheus --config.file=/usr/local/prometheus/prometheus.yml &

2.2.3 verification

The browser opens http://192.168.56.200:9090 (IP:9090 port) to open the monitoring page of Prometheus

2.2.4 start as a service

Ctrl+C ends the Prometheus process. Create Prometheus service, and let Prometheus start up automatically in the way of service.

Add system service

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

Write the following to a file

[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
 
[Service]
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --web.listen-address=:9090
Restart=on-failure
[Install]
WantedBy=multi-user.target

Start the service, set the startup status and check the service startup status

#  systemctl daemon-reload
#  systemctl enable prometheus
#  systemctl start prometheus
#  systemctl status prometheus

III. installation of Grafana

The monitoring page of Prometheus is not so intuitive. We installed grafana to make the monitoring data more intuitive

3.1 installation of grafana

The installation here adopts the way of source compilation. Download the installation package and install it in the monitoring host (192.168.56.200) / usr/local directory

# wget https://dl.grafana.com/oss/release/grafana-6.4.3-1.x86_64.rpm 
# yum localinstall grafana-6.4.3-1.x86_64.rpm 

If there is no wget tool, install the wget tool first:

# yum -y install wget

3.2 start grafana

Set the grafana service to start automatically and start the service

#  systemctl daemon-reload
#  systemctl enable grafana-server.service
#  systemctl start grafana-server.service

3.3 visit grafana

The browser can access http://192.168.56.200:3000 (IP:3000 port) to open the grafana page. The default user name and password are admin. The first login will require changing the default login password

 

3.4 add Prometheus data source

(1) click "Add data source" on the main interface

(2) select Prometheus

(3) fill in data source settings

Fill in the IP address where Prometheus service is located at the URL. Here, we install Prometheus service and Grafana on the same machine, and directly fill in localhost

Click the [save & test] button below to save the settings

(4) Dashboards page select "Prometheus 2.0 Stats"

Click the Dashboards tab and select Prometheus 2.0 Stats

(5) view monitoring

Click the Grafana icon, switch to the main page of Grafana, then click Home, select the Prometheus 2.0 Stats we just added, and you can see the monitoring data

 

This completes the configuration of Prometheus server and Grafana.

IV. install node exporter

The following operations are performed on the monitored host (192.168.56.201).

4.0 turn off the machine firewall

# systemctl stop firewalld
# systemctl disable firewalld

4.1. Install node exporter

Download the node exporter installation package at https://github.com/prometheus/node'exporter/releases/download/v0.18.1/node'exporter-0.18.1.linux-arm64.tar.gz

Upload the downloaded installation package to the / usr/local directory of the monitored host (192.168.56.201)

Unzip the installation package

#  tar -zvxf node_exporter-0.18.1.linux-amd64.tar.gz
#  mv node_exporter-0.18.1.linux-amd64/ node_exporter

4.2. Start node exporter

Enter the unzipped node exporter folder and start the node exporter

#  cd node_exporter
#  ./node_exporter

4.3, validation

Access in browser http://192.168.56.201:9100/metrics If there is data, the service is started successfully

4.4. Set node ﹣ exporter to start in the way of service and set it to start automatically

Ctrl+C ends the node ﹣ exporter process, creates Prometheus service, and enables Prometheus to start up automatically in the way of service.

Add system service

#  vim /etc/systemd/system/node_exporter.service

Write the following to a file

[Unit]
Description=node_exporter
After=network.target 

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

Start the service, set the startup status and check the service startup status

#  systemctl daemon-reload
#  systemctl enable node_exporter
#  systemctl start node_exporter
#  systemctl status node_exporter

This completes the configuration of node > exporter.

V. modify Prometheus configuration and monitor Linux machine

The following operations are performed on the monitoring host (192.168.56.200).

5.1. Modify Prometheus configuration

Enter the installation folder of Prometheus and open the Prometheus configuration file

#  cd /usr/local/prometheus
#  vim prometheus.yml

Add the following under the "graph" config tab to configure monitoring

- job_name: 'Linux'
    static_configs:
    - targets: ['192.168.56.201:9100']
      labels:
        instance: Linux

Here is the full contents of Prometheus.yml file

# 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']

  - job_name: 'Linux'
    static_configs:
    - targets: ['192.168.56.201:9100']
      labels:
        instance: Linux

Save exit, restart Prometheus service

#  systemctl restart prometheus

Browser access http://192.168.56.200:9090/targets View monitoring information

As you can see, the Linux machine has joined in.

5.2. Configure Grafana

Add dashboard

Grafana officially provides us with many dashboard pages, which can be downloaded and used directly. Browser access https://grafana.com/grafana/dashboards Download the required dashboard page

Select Prometheus as the data source, and then select the first dashboard

Copy dashboard Id

Then open our Grafana monitoring page, open the dashboard management page

Click the [import] button

Then copy in the dashboard Id we just copied

Grafana will automatically recognize the dashboard Id.

Then click the [change] button to generate a random UID, click the input box below, select the data source Prometheus we created earlier, and finally click the [Import] button to complete the Import.

After importing successfully, the Dashboard will be opened automatically, and you can see the node monitoring we just set up

Now Prometheus+Grafana is installed and configured, and the Linux machine is monitored and configured.

Tags: Linux vim CentOS firewall

Posted on Fri, 01 Nov 2019 08:20:23 -0700 by fypstudent