Bài viết này hướng dẫn bạn cài đặt Prometheus trên Linux.
Bạn cũng có thể tham khảo Prometheus là gì tại đây.
Bước 1: Update package trên server.
sudo apt update -y
Bước 2: Download Prometheus
Truy cập đến trang downloads (tại đây) của Prometheus để lấy bản mới nhất cho Linux
Bước 3: Đổi tên thư mục giải nén thành prometheus-files.
Sau khi Download file trên, giải nén và đổi tên thư mục giải nén thành prometheus-files.
curl -LO url -LO https://github.com/prometheus/prometheus/releases/download/v2.22.0/prometheus-2.22.0.linux-amd64.tar.gz tar -xvf prometheus-2.22.0.linux-amd64.tar.gz mv prometheus-2.22.0.linux-amd64 prometheus-files
Bước 4: Tạo user prometheus, các folder và set quyền cần thiết.
sudo useradd --no-create-home --shell /bin/false prometheus sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus sudo chown prometheus:prometheus /etc/prometheus sudo chown prometheus:prometheus /var/lib/prometheus
Bước 5: Copy folder prometheus-files và thay đổi quyền cho user prometheus.
Copy folder prometheus-files giải nén trước đó đến /usr/local/bin và thay đổi quyền cho user prometheus.
sudo cp prometheus-files/prometheus /usr/local/bin/ sudo cp prometheus-files/promtool /usr/local/bin/ sudo chown prometheus:prometheus /usr/local/bin/prometheus sudo chown prometheus:prometheus /usr/local/bin/promtool
Bước 6: Move các thư mục console và console_libraries từ prometheus-files
Move các thư mục console và console_libraries từ prometheus-files đến thư mục /etc/prometheus
sudo cp -r prometheus-files/consoles /etc/prometheus sudo cp -r prometheus-files/console_libraries /etc/prometheus sudo chown -R prometheus:prometheus /etc/prometheus/consoles sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
Setup cấu hình Prometheus
Tất cả cấu hình của Prometheus sẽ nằm ở file /etc/prometheus/prometheus.yml.
Bước 1:
Tạo file prometheus.yml
sudo vi /etc/prometheus/prometheus.yml
Bước 2: Copy nội dung bên dưới vào file prometheus.yml
global: scrape_interval: 10s scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090']
Bước 3: Thay đổi owner của file cho user prometheus
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
Setup file prometheus service
Bước 1: Tạo file prometheus.service
sudo vi /etc/systemd/system/prometheus.service
Bước 2: Copy nội dung bên dưới vào file vừa tạo
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
Bước 3: Reload service systemd và start service prometheus
sudo systemctl daemon-reload sudo systemctl start prometheus
Kiểm tra trạng thái của dịch vụ Prometheus với lệnh bên dưới
sudo systemctl status prometheus
Như vậy bạn đã hoàn tất cài đặt, sau đó bạn có thể truy cập web UI của Prometheus theo địa chỉ:
http://IP:9090/
=============Mẫu chèn đối với các bài viết liên quan đến VPS – Server =============
P.A Việt Nam cung cấp đa dạng các cấu hình Máy Chủ Ảo và Máy Chủ Riêng
Cloud Server
Cloud Server Pro
Máy Chủ Riêng
Tham khảo các ưu đãi: https://www.pavietnam.vn/vn/tin-khuyen-mai/