Infra/Grapana

[Grapana] VirtualBox ํ™˜๊ฒฝ์—์„œ ํ”„๋กœ๋ฉ”ํ…Œ์šฐ์Šค + ๊ทธ๋ผํŒŒ๋‚˜ ๊ตฌ์ถ•

OriginMaster 2025. 3. 19. 22:32
๋ฐ˜์‘ํ˜•

๐Ÿ“Œ VirtualBox CentOS 7.9 ํ™˜๊ฒฝ์—์„œ Grafana & Prometheus ๊ตฌ์ถ• ๋ฐ ํ…Œ์ŠคํŠธ ์ ˆ์ฐจ

CentOS 7.9 ํ™˜๊ฒฝ์—์„œ Grafana ๋ฐ Prometheus๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ , ๋กœ๊ทธ ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์œ„ํ•œ ์„ค์ • ๋ฐ ํ…Œ์ŠคํŠธ๊นŒ์ง€ ์ง„ํ–‰ํ•˜๋Š” ์ ˆ์ฐจ๋ฅผ ์ •๋ฆฌ.


1๏ธโƒฃ VirtualBox ํ™˜๊ฒฝ ์„ค์ • (์„ ํƒ ์‚ฌํ•ญ)

์ด๋ฏธ CentOS 7.9๊ฐ€ ์„ค์น˜๋œ ๊ฒฝ์šฐ ๊ฑด๋„ˆ๋›ฐ์–ด๋„ ๋จ.

  1. VirtualBox ์„ค์น˜
    VirtualBox ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์—์„œ ๋‹ค์šด๋กœ๋“œ ํ›„ ์„ค์น˜
  2. CentOS 7.9 ์„ค์น˜
    • ๋„คํŠธ์›Œํฌ ์„ค์ •: NAT ๋˜๋Š” Bridge Adapter ์„ ํƒ (์™ธ๋ถ€ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋„๋ก)
  3. SSH ์ ‘์† ์„ค์ • (์˜ต์…˜)
  4. yum install -y epel-release yum install -y openssh-server systemctl enable sshd systemctl start sshd

2๏ธโƒฃ ๋ฐฉํ™”๋ฒฝ & SELinux ์„ค์ • (ํ•„์ˆ˜)

Prometheus, Grafana ํฌํŠธ๋ฅผ ์—ด์–ด์คŒ

firewall-cmd --permanent --add-port=9090/tcp  # Prometheus
firewall-cmd --permanent --add-port=3000/tcp  # Grafana
firewall-cmd --reload

# SELinux ๋น„ํ™œ์„ฑํ™” (ํ•„์š”ํ•œ ๊ฒฝ์šฐ)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

3๏ธโƒฃ Prometheus ์„ค์น˜ ๋ฐ ์„ค์ •

1. Prometheus ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜

cd /usr/local/
curl -LO https://github.com/prometheus/prometheus/releases/latest/download/prometheus-2.48.1.linux-amd64.tar.gz
tar xvf prometheus-*.tar.gz
mv prometheus-*/ prometheus
cd prometheus

2. Prometheus ์„ค์ • ํŒŒ์ผ ์ˆ˜์ •

vi /usr/local/prometheus/prometheus.yml
global:
  scrape_interval: 15s  # ๊ธฐ๋ณธ ์Šคํฌ๋žฉ ๊ฐ„๊ฒฉ (15์ดˆ)

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']

3. Prometheus ์‹คํ–‰

nohup /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml > /var/log/prometheus.log 2>&1 &

4. Prometheus ์„œ๋น„์Šค ๋“ฑ๋ก

cat <<EOF > /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target

[Service]
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=always

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus

5. Prometheus ์ƒํƒœ ํ™•์ธ

systemctl status prometheus
  • ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
  • ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ http://<CentOS_IP>:9090 ์ ‘์†ํ•˜์—ฌ Prometheus UI ํ™•์ธ

4๏ธโƒฃ Grafana ์„ค์น˜ ๋ฐ ์„ค์ •

1. Grafana ์„ค์น˜

yum install -y https://dl.grafana.com/oss/release/grafana-9.3.2-1.x86_64.rpm

2. Grafana ์„œ๋น„์Šค ์‹œ์ž‘

systemctl enable grafana-server
systemctl start grafana-server

3. Grafana ์ƒํƒœ ํ™•์ธ

systemctl status grafana-server

4. Grafana ์ ‘์†

์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ http://<CentOS_IP>:3000 ์ ‘์†

  • ๊ธฐ๋ณธ ๋กœ๊ทธ์ธ ์ •๋ณด:
    • ID: admin
    • PW: admin (์ฒ˜์Œ ๋กœ๊ทธ์ธ ์‹œ ๋ณ€๊ฒฝ ํ•„์š”)

5๏ธโƒฃ Node Exporter ์„ค์น˜ (์„œ๋ฒ„ ๋ฆฌ์†Œ์Šค ๋ชจ๋‹ˆํ„ฐ๋ง)

1. Node Exporter ๋‹ค์šด๋กœ๋“œ ๋ฐ ์‹คํ–‰

cd /usr/local/
curl -LO https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-1.6.1.linux-amd64.tar.gz
tar xvf node_exporter-*.tar.gz
mv node_exporter-*/ node_exporter

2. Node Exporter ์‹คํ–‰

nohup /usr/local/node_exporter/node_exporter > /var/log/node_exporter.log 2>&1 &

3. Node Exporter ์„œ๋น„์Šค ๋“ฑ๋ก

cat <<EOF > /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target

[Service]
User=root
ExecStart=/usr/local/node_exporter/node_exporter
Restart=always

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter

4. Prometheus์— Node Exporter ์ถ”๊ฐ€

/usr/local/prometheus/prometheus.yml ํŒŒ์ผ ์ˆ˜์ •

  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9100']
systemctl restart prometheus

6๏ธโƒฃ Grafana์—์„œ Prometheus ๋ฐ์ดํ„ฐ ์†Œ์Šค ์ถ”๊ฐ€

  1. Grafana ๋กœ๊ทธ์ธ (http://<CentOS_IP>:3000)
  2. ์ขŒ์ธก ๋ฐ”์—์„œ "Configuration" → "Data Sources" ํด๋ฆญ
  3. "Add data source" ๋ฒ„ํŠผ ํด๋ฆญ
  4. Prometheus ์„ ํƒ
  5. URL์— http://localhost:9090 ์ž…๋ ฅ ํ›„ "Save & Test" ํด๋ฆญ
  6. ์ •์ƒ์ ์œผ๋กœ ์—ฐ๊ฒฐ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

7๏ธโƒฃ Grafana์—์„œ ์„œ๋ฒ„ ๋ชจ๋‹ˆํ„ฐ๋ง ๋Œ€์‹œ๋ณด๋“œ ์ถ”๊ฐ€

  1. Grafana "Dashboards" → "Import" ํด๋ฆญ
  2. "Import via Grafana.com"์—์„œ ID 1860 ์ž…๋ ฅ (Node Exporter Full)
  3. Prometheus ๋ฐ์ดํ„ฐ ์†Œ์Šค ์„ ํƒ ํ›„ "Import" ํด๋ฆญ
  4. ์„œ๋ฒ„ CPU, ๋ฉ”๋ชจ๋ฆฌ, ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉ๋Ÿ‰ ๋“ฑ์„ ํ™•์ธ

8๏ธโƒฃ ํ…Œ์ŠคํŠธ ๋ฐ ๊ฒ€์ฆ

  1. Prometheus ์ƒํƒœ ํ™•์ธ
    • http://<CentOS_IP>:9090 ์ ‘์†ํ•˜์—ฌ ์ •์ƒ ์‹คํ–‰ ํ™•์ธ
  2. systemctl status prometheus
  3. Grafana ์ƒํƒœ ํ™•์ธ
    • http://<CentOS_IP>:3000 ์ ‘์†ํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์†Œ์Šค ๋ฐ ๋Œ€์‹œ๋ณด๋“œ ์ •์ƒ ๋™์ž‘ ํ™•์ธ
  4. systemctl status grafana-server
  5. Node Exporter ์ƒํƒœ ํ™•์ธ
    • http://<CentOS_IP>:9100/metrics ์ ‘์†ํ•˜์—ฌ ๋ฉ”ํŠธ๋ฆญ ๋ฐ์ดํ„ฐ ํ™•์ธ
  6. systemctl status node_exporter
  7. ๋กœ๊ทธ ๋ชจ๋‹ˆํ„ฐ๋ง
  8. tail -f /var/log/prometheus.log tail -f /var/log/grafana/grafana.log tail -f /var/log/node_exporter.log

 

โœ” ๋งŒ์•ฝ Grapana ๋ฐ Prometheus๊ฐ€ ์ œ๋Œ€๋กœ ๋‹ค์šด๋กœ๋“œ ๋˜์ง€ ์•Š์„๊ฒฝ์šฐโ“

 

๊ณต์‹ ํ™ˆํŽ˜์ด์ง€ (https://prometheus.io/download) ์— ์ ‘์†ํ•˜์—ฌ ํ˜„์žฌ ๋ฒ„์ „์˜ ํŒŒ์ผ์„ '๋งํฌ ์ฃผ์†Œ ๋ณต์‚ฌ'ํ•˜์—ฌ

$curl -LO {๋ณต์‚ฌํ•œ ๋งํฌ} ๋กœ ์ˆ˜ํ–‰ํ•˜๋ฉด ์ •์ƒ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๋ฐ˜์‘ํ˜•