当前位置:网站首页>Prometheus primary body test

Prometheus primary body test

2022-06-23 21:28:00 Bess Croft

Preface

Why did I choose Prometheus (Prometheus)?Prometheus Is in accordance with the Google SRE The concept of operation and maintenance , It is practical and forward-looking . It's also based on Go Language development , Good performance , Installation and deployment are also simple , Even cross platform ( Include arm platform ). As the basis for service and business monitoring ,Prometheus It's a very good choice .

What is Prometheus ?

We quote official terms here :

Prometheus Is an open source system monitoring and alerting toolkit , It can collect system information , And send it to one or more monitoring centers .Prometheus Collect and store its indicators as time series data , That is, the indicator information is stored together with the time stamp recording it , And optional key value pairs called tags .

Here we introduce the figure of the official website , explain Prometheus And some of its ecosystem components :

install

There are many ways to install , Binary packages or Docker Fine , Here we choose binary packages .

Installation environment

Here I use Ubuntu 20.04, Don't ask me why , This is the machine with the largest memory (24G Memory ), It's just , It is arm64 Architecturally , So the following tutorial is running on arm64 On the server of the architecture , Of course , You can also use this tutorial in amd64 Installation under architecture , Including Tencent cloud KVM And lightweight application servers , There are only a few nuances , Let's talk about .

install Prometheus

download Prometheus

You can go to the official website , perhaps GitHub Of Publish the page Download installation package , What I download here is GitHub Bags in the warehouse .

  • If you are amd64 Architecture server
wget https://github.com/prometheus/prometheus/releases/download/v2.31.0/prometheus-2.31.0.linux-amd64.tar.gz
tar xfz prometheus-2.31.0.linux-amd64.tar.gz
sudo cp prometheus-2.31.0.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.31.0.linux-amd64/promtool /usr/local/bin/
  • If you are arm64 Architecture server
wget https://github.com/prometheus/prometheus/releases/download/v2.31.0/prometheus-2.31.0.linux-arm64.tar.gz
tar xfz prometheus-2.31.0.linux-arm64.tar.gz
sudo cp prometheus-2.31.0.linux-arm64/prometheus /usr/local/bin/
sudo cp prometheus-2.31.0.linux-arm64/promtool /usr/local/bin/

The main difference , Just download different packages , The latter configuration is almost the same

To configure Prometheus

  • Check
prometheus --version

Carry out orders , As shown in the figure below , It was successful !

We just unzipped the folder below , You can find a subdirectory prometheus , Then you can find a configuration file prometheus.yml . We need to put prometheus.yml This initial configuration file is copied to /etc/prometheus Under the table of contents , Then the simple configuration can be started . Of course , You can also configure it according to your own needs , Please refer to the official The configuration document .

sudo mkdir -p /etc/prometheus
sudo cp prometheus.yml /etc/prometheus/
  • The default partial configuration is as follows :
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

We can see that the port is 9090 , You can change it to something else as needed .

start-up Prometheus

Now let's start to see

prometheus --config.file "/etc/prometheus/prometheus.yml"
  • If something goes wrong , You can use prometool Tool to check your profile .
promtool check config "/etc/prometheus/prometheus.yml"

If you output the following prompt , It means there's no problem !

Checking /etc/prometheus/prometheus.yml
  SUCCESS: 0 rule files found

To configure service Way to run Prometheus

  • Create a new one service file
sudo vim /etc/systemd/system/prometheus.service
  • Edit the following content and save it !
[Unit]
Description=prometheus

[Service]
User=root
ExecStart=prometheus --config.file "/etc/prometheus/prometheus.yml"
Restart=on-abort

[Install]
WantedBy=multi-user.target
  • Set boot up
sudo systemctl enable prometheus
  • start-up Prometheus
sudo systemctl start prometheus

This is the end of it !

To configure HTTPS And reverse proxy

If your server is HTTPS Of , Then configuration is required HTTPS Certificate and private key of , Here I use Let's Encrypt Certificate , You can download it on the official website . I won't tell you how to operate it , If you don't , You should learn how to use Nginx, And learn to configure HTTPS certificate .

  • To configure Nginx Reverse proxy

Here I release my configuration , You can according to your needs , Reference use :

location /
{
    proxy_pass http://127.0.0.1:9090;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    
    add_header X-Cache $upstream_cache_status;
    
    #Set Nginx Cache
    add_header Cache-Control no-cache;
}

Prometheus Start listening to the local loopback address localhost:9090 , Therefore, the public network cannot be accessed directly , I don't really recommend that you open the firewall , This can bring certain security protection .

preview

At this time, let's visit the domain name , You can see the page !

Here's a hint , This is not a production environment , Just to practice and learn , So it doesn't matter , The production environment does not recommend this ! Can pass ssh Port forwarding method to achieve remote access .

原网站

版权声明
本文为[Bess Croft]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112241012162835.html