Site icon Learning & Doing

Install grafana dan Prometheus di centos 7

grafana

Pada kesempatan di hari ini , saya akan membahas cara Install grafana dan Prometheus di centos 7, grafana sendiri merupakan tools untuk monitoring resurce sebuah server .

Langsung saja kita mulai .

  1. Install Prometheus
- Membuat user
useradd --no-create-home -s /bin/false prometheus
- Membuat direktori
mkdir /etc/prometheus
mkdir /var/lib/prometheus
- membuat hak akses
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus
- download dan konfig prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.linux-amd64.tar.gz
tar xvzf prometheus-2.13.1.linux-amd64.tar.gz
mv prometheus-2.13.1.linux-amd64/* /var/lib/prometheus/
chown -R prometheus:prometheus /var/lib/prometheus
mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
ln -s /var/lib/prometheus/prometheus /usr/local/bin/prometheus
- membuat service
nano /usr/lib/systemd/system/prometheus.service

[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=/var/lib/prometheus/consoles \
--web.console.libraries=/var/lib/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

- Start service
systemctl enable --now prometheus.service
systemctl status prometheus.service
systemctl start prometheus.service

2. Install Node exporter

- download dan config node exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar xvf node_exporter-0.18.1.linux-amd64.tar.gz
mkdir -p /var/lib/prometheus/node_exporter
mv node_exporter-0.18.1.linux-amd64/* /var/lib/prometheus/node_exporter
chown -R prometheus:prometheus /var/lib/prometheus/node_exporter/

- membuat service
nano /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
ExecStart=/var/lib/prometheus/node_exporter/node_exporter

[Install]
WantedBy=default.target

- start service
systemctl enable --now node_exporter.service
systemctl status node_exporter.service
systemctl start node_exporter.service

3. Install Grafana

- repo

nano /etc/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

yum makecache fast -y

- install grafana

yum install -y grafana

systemctl enable --now grafana-server.service
systemctl status grafana-server.service

- akses web grafana

http://ipaddr:3000

user : admin
pass : admin 

4. Setting prometheus dan grafana

-- setting prometheus
nano /etc/prometheus/prometheus.yml

global:
  scrape_interval: 15s

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

  - job_name: 'node_exporter'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9100']

- restart service

systemctl restart prometheus.service

- akses web

http://ipaddr:9090
http://ipaddr:9090/targets

-- setting grafana
- Add Data Source

Buka menu Configuration -> Data Source -> Add Data Source -> pilih prometheus

isi :

Url -> http://localhost:9090
basic auth -> enable -> isi user + pass grafana 

-> save and test 
Exit mobile version