
少し前までは、fluentd+elasticsearch+kibanaというダッシュボードが流行っていた気がしますが、elasticsearchはJavaで動いているため非常に多くのメモリを消費するという欠点(?)がありました。
今回導入するのは比較的軽いgrafana+prometheusとなります。
grafanaがビジュアライズダッシュボードの役割をし、
prometheusがデータの収集を行います。
grafanaと相性の良いinfluxDBも導入します。
grafanaのインストール
まずはgrafanaからインストールします。
yum install https://dl.grafana.com/oss/release/grafana-5.4.3-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
ついでに、grafana-serverの起動と自動起動も設定します。
起動すると、http://localhost(またはサーバIP):3000/login でログインできるようになります。
管理ユーザは admin
パスワードはデフォルトでは admin となっていますが、初回ログイン時にパスワードの変更を促されます。(Skipも可)
influxDBのインストール
後々いろいろと便利なinfluxDBもインストールします。
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.3.x86_64.rpm
sudo yum localinstall influxdb-1.7.3.x86_64.rpm
systemctl start influxdb
systemctl enable influxdb
こちらも同様にインストール後、起動及び自動起動の設定を行います。
prometheusのインストール
データを収集するprometheusをインストールします。
といってもprometheusはバイナリで配布されているので設置するだけで動作します。
インストールとテスト起動
mkdir /usr/local/src/prometheus
cd /usr/local/src/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.6.1/prometheus-2.6.1.linux-amd64.tar.gz
tar zxvf prometheus-2.6.1.linux-amd64.tar.gz
cd prometheus-2.6.1.linux-amd64/
./prometheus
[Ctrl-Cで終了]
必要な場所にファイルを移動します。
mkdir /opt/prometheus
cp -av ./* /opt/prometheus
chmod 755 /opt/prometheus/
chown -R root:root /opt/prometheus/
mkdir /etc/prometheus
ln -s /opt/prometheus/console_libraries /etc/prometheus/console_libraries
ln -s /opt/prometheus/consoles /etc/prometheus/consoles
ln -s /opt/prometheus/prometheus.yml /etc/prometheus/prometheus.yml
設定
/etc/prometheus/prometheus.yml を編集します。
OPTIONS="--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.libraries=/etc/prometheus/console_libraries --web.console.templates=/etc/prometheus/consoles"
prometheusを自動起動させるためにsystemdに登録
/etc/systemd/system/prometheus.service を作成して編集します。
[Unit]
Description=Prometheus Service
After=network.target
[Service]
Type=simple
EnvironmentFile=-/etc/default/prometheus
ExecStart=/opt/prometheus/prometheus $OPTIONS
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
systemd を reload し、自動起動を設定
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status -l prometheus を実行すると正常に動作しているかをチェックすることが出来ます。
prometheus で使用する node_exporter を導入する
node_exporterはprometheusで取れないシステム情報を取得するのに便利です。
mkdir /opt/node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
tar zxvf node_exporter-0.170.linux-amd64.tar.gz
mv node_exporter-0.17.0.linux-amd64/node_exporter /opt/node_exporter
node_exporterの起動と自動起動
/etc/systemd/system/node_exporter.service をsystemdで使用できるようにするため新規で作成します。
[Unit]
Description=Node exporter for prometheus
After=network.target
[Service]
Type=simple
EnvironmentFile=-/etc/default/node_exporter
ExecStart=/opt/node_exporter/node_exporter $OPTIONS
PrivateTmp=true
[Install]
WantedBy=multi-user.target
node_exporterをprometheusに設定
/etc/prometheus/prometheus.yml を編集します。
targets: の部分に node_exporter を設定します。
- targets: ['localhost:9090','localhost:9100']
localhost:9090がprometheus、localhost:9100は node_exporter を意味します。
これで一通りgrafana+prometheusでの設定ができました。