ArticlesLinux ServerOpensourceUbuntu

การติดตั้ง Prometheus บน Ubuntu 22.04

Prometheus เป็นระบบ Monitoring แบบโอเพนซอร์สที่เป็นที่นิยมสำหรับการเก็บข้อมูลการทำงานของระบบและการเฝ้าดูสถานะของแอปพลิเคชัน ในบทความนี้เราจะแสดงวิธีการติดตั้ง Prometheus บน Ubuntu 22.04

ทำการสร้าง User prometheus ด้วยคำสั่ง

useradd -m -s /bin/bash prometheus
su - prometheus

ทำการดาวน์โหลด Prometheus จาก github

ให้ใช้ wget เพื่อดาวน์โหลดไฟล์ Binary ของ Prometheus:

wget https://github.com/prometheus/prometheus/releases/download/v2.50.1/prometheus-2.50.1.linux-amd64.tar.gz

หลังจากดาวน์โหลดไฟล์แล้ว ให้แตกไฟล์และเริ่มต้น Prometheus:

tar -xf prometheus-2.50.1.linux-amd64.tar.gz
mv prometheus-2.50.1.linux-amd64/ prometheus/
mkdir -p ~/prometheus/data
exit

ทำการสร้างไฟล์เพื่อใช้ Run เป็น  Service บน Ubuntu โดยใช้คำสั่ง

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

เพื่อทำการสร้างไฟล์ จากนั้นให้ทำการเพิ่มคำสั่งต่อไปนี้ในไฟล์ prometheus.service

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=prometheus
Restart=on-failure
ExecStart=/home/prometheus/prometheus/prometheus \
--config.file=/home/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus/prometheus/data

[Install]
WantedBy=multi-user.target

เมื่อทำการสร้างไฟล์ prometheus.service ให้ทำการเปิดการใช้งานด้วยคำสั่ง

systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

เมื่อ Prometheus ทำงานอย่างถูกต้อง คุณสามารถเข้าถึงหน้าต่างของการตั้งค่าโดยใช้เว็บเบราว์เซอร์ได้ที่ http://localhost:9090

สรุป

การติดตั้ง Prometheus บน Ubuntu 22.04 เป็นกระบวนการที่ง่ายและสะดวก โดยใช้ขั้นตอนที่ได้กล่าวมาข้างต้น คุณสามารถเริ่มต้นใช้งาน Prometheus ในการเฝ้าดูและรวบรวมข้อมูลการทำงานของระบบของคุณได้ทันที

Related Posts