Cài đặt Prometheus + Grafana

image-47 Cài đặt Prometheus + Grafana

Giới thiệu

Prometheus và Grafana là bộ đôi công cụ giám sát và trực quan hóa mạnh mẽ được sử dụng rộng rãi trong các hệ thống hiện đại. Trong khi Prometheus chịu trách nhiệm thu thập và lưu trữ dữ liệu từ các ứng dụng và hệ thống, Grafana cung cấp giao diện trực quan để phân tích và hiển thị dữ liệu đó dưới dạng biểu đồ. Bài viết này sẽ hướng dẫn bạn từng bước cài đặt Prometheus và Grafana trên hệ thống, giúp bạn xây dựng một nền tảng giám sát hiệu quả và toàn diện.

Update package & Timedatectl

apt update
timedatectl set-timezone "Asia/Ho_Chi_Minh"
timedatectl set-ntp true
systemctl restart systemd-timesyncd

Xác định phiên bản của prometheus

https://github.com/prometheus/prometheus/releases
export RELEASE="2.20.1"

Tải và giải nén gói cài đặt

wget https://github.com/prometheus/prometheus/releases/download/v${RELEASE}/prometheus-${RELEASE}.linux-amd64.tar.gz
tar xvf prometheus-${RELEASE}.linux-amd64.tar.gz
cd prometheus-${RELEASE}.linux-amd64/

Tạo user cho dịch vụ Prometheus

groupadd --system prometheus
grep prometheus /etc/group
useradd -s /sbin/nologin -r -g prometheus prometheus

Tạo thư mục chứa file cấu hình Prometheus

mkdir -p /etc/prometheus/{rules,rules.d,files_sd}  /var/lib/prometheus

Chuyển các file thực thi binary vào thư mục local bin và copy thư mục consoles, file config

cp prometheus promtool /usr/local/bin/
cp -r consoles/ console_libraries/ /etc/prometheus/
cp prometheus.yml /etc/prometheus/

Gán quyền cho user prometheus

chown -R prometheus:prometheus /etc/prometheus/  /var/lib/prometheus/
chmod -R 775 /etc/prometheus/ /var/lib/prometheus/

Tạo file systemd cho dịch vụ prometheus

nano /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus systemd service unit
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
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 \
--web.listen-address=0.0.0.0:9090 \
--storage.tsdb.retention.time=1y
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target

Enable và khởi động dịch vụ prometheus

systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

Truy cập tại : http://<IP_HOST>:9090

Cài đặt Grafana trên Ubuntu 18

Đầu tiên, bạn thêm repository của Grafana vào máy chủ

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add

Update các gói phần mềm từ repository này và cài đặt Grafana.

apt-get update
apt-get install grafana -y

Kích hoạt và khởi động dịch vụ

systemctl start grafana-server
systemctl enable grafana-server.service

Truy cập <IP_HOST>: :3000


Việc cài đặt Prometheus và Grafana là bước quan trọng để xây dựng một hệ thống giám sát hiện đại và mạnh mẽ. Với Prometheus thu thập dữ liệu chính xác và Grafana trực quan hóa thông tin, bạn có thể dễ dàng theo dõi, phân tích và tối ưu hóa hiệu suất hệ thống. Hãy bắt đầu triển khai ngay hôm nay để tận dụng tối đa lợi ích từ bộ công cụ giám sát hàng đầu này!

I am gaining experience and developing my skills in the field of information technology. My focus areas include basic network administration, troubleshooting, and supporting IT infrastructure. I am keen on learning and growing in various aspects of IT, from system setup and maintenance to exploring new technologies and methodologies.

Post Comment