Prometheus deployment, operation and Grafana display

Table of contents

1. Deploy Prometheus

1. Environmental preparation work

2. puometheus deployment

2.1 Upload prometheus to the opt directory and unzip it

2.2 Modify the prometheus configuration file

2.3 Configure the system startup file and set auto-start at boot

2.4 Open prometheus and visit the web page for verification

2. Deploy Exporter (192.168.226.129)

1. Monitor the remote Linux host 192.168.226.129

1.1 Upload node_exporter to the opt directory and unzip it

1.2 Start node_exporter

1.3 Modify the configuration file of the prometheus server

1.4 Access the prometheus server

2. Monitor remote MySQL

2.1 Upload mysqld_exporter to the opt directory and unzip it

2.2 Enter the mysql database and authorize it

2.3 Create a configuration file for mysqld_exporter

2.4 Start components

2.5 Browser access the default port 9104

2.6 Modify the configuration file of the prometheus server

2.7 Access the prometheus server

3. Deploy Grafana for display

1. Download and install Grafana (192.168.226.130)

2. Configure data source

3. Import template

4. Display data for data sources

5. Import grafana monitoring template

6. Grafana graphically displays MySQL monitoring data


1. Deploy Prometheus

1. Environmental preparation work

serverIP addresscomponents
Prometheus server192.168.226.128Prometheus、node_exporter
agent server192.168.226.129node_exporter
grafana server192.168.226.130Grafana

2. puometheus deployment

2.1 Upload prometheus to the opt directory and unzip it

tar zxf prometheus-2.27.1.linux-amd64.tar.gz
mv prometheus-2.27.1.linux-amd64 /usr/local/prometheus
cd /usr/local/prometheus/
ls

2.2 Modify the prometheus configuration file

cat /usr/local/prometheus/prometheus.yml | grep -v "^#"
global: #For global configuration of prometheus, such as collection interval, crawl timeout, etc.
  scrape_interval: 15s #The time interval for collecting target host monitoring data, the default is 1m
  evaluation_interval: 15s #The time interval for triggering an alarm and generating an alert, the default is 1m
  # scrape_timeout is set to the global default (10s).
  scrape_timeout: 10s #Data collection timeout, default 10s
 
alerting: #Configuration for alertmanager instances, supporting static configuration and dynamic service discovery mechanisms
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093
 
rule_files: #Configuration for loading file paths related to alarm rules. You can use the file name wildcard mechanism.
  # - "first_rules.yml"
  # - "second_rules.yml"
 
scrape_configs: #Configuration for collecting time series data sources
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus" #Each collection of monitored instances is named with job_name, supporting static configuration (static_configs) and dynamic service discovery mechanism (*_sd_configs)
 
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
 
    static_configs: #Static target configuration, fixed to pull data from a certain target
      - targets: ["localhost:9090"]

2.3 Configure the system startup file and set auto-start at boot

[root@prometheus prometheus]# vim /usr/lib/systemd/system/prometheus.service
 
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io
After=network.target
 
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data/ \
--storage.tsdb.retention=15d \
--web.enable-lifecycle
  
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
 
[Install]
WantedBy=multi-user.target

2.4 Open prometheus and visit the web page for verification

 

 Monitored data can be viewed through http 9090/metrics

 

2. Deploy Exporter (192.168.226.129)

1. Monitor the remote Linux host 192.168.226.129

1.1 Upload node_exporter to the opt directory and unzip it

tar zxf node_exporter-1.1.2.linux-amd64.tar.gz
mv node_exporter-1.1.2.linux-amd64 /usr/local/bin/

1.2 Start node_exporter

./node_exporter
 
netstat -natp | grep :9100
 
Browser access: http 9100/metrics, you can see the indicator data collected by Node Exporter

 

1.3 Modify the configuration file of the prometheus server

 vim prometheus.yml

  - job_name: 'nodes'
    static_configs:
    - tarhets: ['192.168.226.129:9100']

 After changing the configuration file, restart the service

1.4 Access the prometheus server

2. Monitor remote MySQL

2.1 Upload mysqld_exporter to the opt directory and unzip it

tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter

2.2 Enter the mysql database and authorize it

Enter the database

create user 'exporter'@'%' identified by '123456';

grant process,replication client,select on *.* to 'exporter'@'%' identified by '123456';

flush privileges;

2.3 Create a configuration file for mysqld_exporter

vim /usr/local/mysqld_exporter/mysqld_exporter.cnf

[client]
​
user=exporter
​
password=123456

2.4 Start components

./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysqld_exporter.cnf

2.5 Browser access the default port 9104

2.6 Modify the configuration file of the prometheus server

vim prometheus.yml

- job_name: 'node_mysql'
    static_configs:
    - targets: ['192.168.226.129:9104']

 Restart the service and check the status

2.7 Access the prometheus server

3. Deploy Grafana for display

1. Download and install Grafana (192.168.226.130)

rpm -ivh /opt/grafana-7.3.6-1.x86_64.rpm
 
systemctl start grafana-server
systemctl enable grafana-server
 
netstat -natp | grep :3000
 
Browser access: http 3000, the default account and password are admin/admin

 

2. Configure data source

Next, we add the data collected by the Prometheus server as a data source to grafana so that grafana can obtain Prometheus data.

 

 

3. Import template

4. Display data for data sources

 Customize the name, click Save in dashboard to view

5. Import grafana monitoring template

Browser access: https://grafana.com/grafana/dashboards, search for node exporter on the page, select the appropriate panel, and click Copy ID or Download JSON
 
In the grafana page, + Create -> Import, enter the panel ID number or upload the JSON file, click Load to import the monitoring panel

 

6. Grafana graphically displays MySQL monitoring data

Modify the configuration file on grafana, and download and install the mysql monitoring dashboard (including related json files, which can be regarded as a monitoring template developed by developers)

 Import related json files in the grafana graphical interface
Open it with the firefox browser on the grafana server for easy uploading. Select 7362 for the template here.

 

 

 

Related Posts

What are the low-code platforms that support localization? Don’t miss this one

Dual-link hot backup (load sharing) experiment

[Linux] Common instructions (2)

Docker learning: start the container and mount the directory

[Linux Ladder] Chapter 2 · Linux system environment setup

Ruijie – Use username and password to log in to the router when logging in with Telent

SSH key

Developers, what exactly are Docker images, containers and repositories?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*