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๊ฐ ์ค์น๋ ๊ฒฝ์ฐ ๊ฑด๋๋ฐ์ด๋ ๋จ.
- VirtualBox ์ค์น
VirtualBox ๊ณต์ ํํ์ด์ง์์ ๋ค์ด๋ก๋ ํ ์ค์น - CentOS 7.9 ์ค์น
- ๋คํธ์ํฌ ์ค์ : NAT ๋๋ Bridge Adapter ์ ํ (์ธ๋ถ ์ ์ ๊ฐ๋ฅํ๋๋ก)
- SSH ์ ์ ์ค์ (์ต์ )
- 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 ๋ฐ์ดํฐ ์์ค ์ถ๊ฐ
- Grafana ๋ก๊ทธ์ธ (http://<CentOS_IP>:3000)
- ์ข์ธก ๋ฐ์์ "Configuration" → "Data Sources" ํด๋ฆญ
- "Add data source" ๋ฒํผ ํด๋ฆญ
- Prometheus ์ ํ
- URL์ http://localhost:9090 ์ ๋ ฅ ํ "Save & Test" ํด๋ฆญ
- ์ ์์ ์ผ๋ก ์ฐ๊ฒฐ๋์๋์ง ํ์ธ
7๏ธโฃ Grafana์์ ์๋ฒ ๋ชจ๋ํฐ๋ง ๋์๋ณด๋ ์ถ๊ฐ
- Grafana "Dashboards" → "Import" ํด๋ฆญ
- "Import via Grafana.com"์์ ID 1860 ์ ๋ ฅ (Node Exporter Full)
- Prometheus ๋ฐ์ดํฐ ์์ค ์ ํ ํ "Import" ํด๋ฆญ
- ์๋ฒ CPU, ๋ฉ๋ชจ๋ฆฌ, ๋คํธ์ํฌ ์ฌ์ฉ๋ ๋ฑ์ ํ์ธ
8๏ธโฃ ํ ์คํธ ๋ฐ ๊ฒ์ฆ
- Prometheus ์ํ ํ์ธ
- http://<CentOS_IP>:9090 ์ ์ํ์ฌ ์ ์ ์คํ ํ์ธ
- systemctl status prometheus
- Grafana ์ํ ํ์ธ
- http://<CentOS_IP>:3000 ์ ์ํ์ฌ ๋ฐ์ดํฐ ์์ค ๋ฐ ๋์๋ณด๋ ์ ์ ๋์ ํ์ธ
- systemctl status grafana-server
- Node Exporter ์ํ ํ์ธ
- http://<CentOS_IP>:9100/metrics ์ ์ํ์ฌ ๋ฉํธ๋ฆญ ๋ฐ์ดํฐ ํ์ธ
- systemctl status node_exporter
- ๋ก๊ทธ ๋ชจ๋ํฐ๋ง
- 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 {๋ณต์ฌํ ๋งํฌ} ๋ก ์ํํ๋ฉด ์ ์ ๋ค์ด๋ก๋ ๋ฐ์ ์ ์์ต๋๋ค!
๋ฐ์ํ