GrowthForecast導入作業記録[CentOS7/MariaDB/Systemd]

インフラ周りのちょっとしたデータをグラフ化したかったので、GrowthForecastを使おうと思い立ちました。デフォルトのsqliteでも良かったのですが、後々手を加えられそうなMariaDBでインストールしました。

環境情報

CentOS7.2を使っていきました。

# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

前提パッケージインストール

まずは本家ページに沿って必要なパッケージをインストールします。wgetも次の手順で利用するのでインストールしておきます。

# yum -y groupinstall "Development Tools"
# yum -y install pkgconfig glib2-devel gettext libxml2-devel pango-devel cairo-devel

MariaDB準備

CentOS7なのでMySQLでなくMariaDB準備します。

MariaDBインストール

MariaDBリポジトリからインストールします。

# cat <<EOS > /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOS
# yum -y install MariaDB-server MariaDB-client MariaDB-devel

MariaDB起動設定

サービス登録して起動しておきます。

# systemctl enable mariadb.service
# systemctl start mariadb.service

Perl環境準備

インストール準備

perlbrewのインスト-ルします。まずは準備でwget入れておきます。

# yum -y install wget

growthforecast用のユーザを作成してスイッチします。

# useradd growthforecast
# su - growth forecast

Perlbrewインストール

perlbrewインストールします。

$ wget get -O - http://install.perlbrew.pl | bash
$ echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.bash_profile
$ source ~/.bash_profile

Perl 5.22.1のインストール

Perl 5.22.1をインストールします。

$ perlbrew available
  perl-5.24.0-RC3
  perl-5.22.1
  perl-5.20.3
  perl-5.18.4
  perl-5.16.3
  perl-5.14.4
  perl-5.12.5
  perl-5.10.1
  perl-5.8.9
  perl-5.6.2
  perl5.005_04
  perl5.004_05
  perl5.003_07
$ perlbrew install perl-5.22.1
$ perlbrew switch perl-5.22.1

CPANのインストール

cpanmのインストールします。

$ curl -L https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm | perl - App::cpanminus

MariaDBへの接続のためDBD::mysqlをインストールします。

DBS::mysqlのインストールにはopenssl-develが必要です。

# yum -y install openssl-devel 

DBD::mysqlインストールします。

# su - growthforecast
$ cpanm -n DBD::mysql

補則】openssl-devel入ってないと以下のようなエラーがでます。

LD_RUN_PATH="/usr/lib64" "/home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/perl" myld cc  -shared -O2 -L/usr/local/lib -fstack-protector-strong dbdimp.o mysql.o  -o blib/arch/auto/DBD/mysql/mysql.so     \
   -L/usr/lib64 -lmysqlclient -lpthread -lz -lm -ldl -lssl -lcrypto     \
  
/bin/ld: cannot find -lssl
/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
make: *** [blib/arch/auto/DBD/mysql/mysql.so] Error 1
-> FAIL Installing DBD::mysql failed. See /home/growthforecast/.cpanm/work/1461584907.19233/build.log for details. Retry with --force to force install it.

GrowthForecastインストール

GrowthForecast用のDB作成

GrowthForecastインストール前に、まずはDB作成から。

# mysql
MariaDB > create database growthforecast;
MariaDB > grant create,alter,delete,insert,update,select on growthforecast.* to 'growthforecast'@'localhost' identified by 'password';

GrowthForecastインストール

やっと準備できたのでGrowthForecastインストールします。

# su - growthforecast
$ cpanm -n GrowthForecast

DBユーザとパスワードを変数としてExportして、--with-mysqlオプション付きでGrowthForecastを起動します。

$ export MYSQL_USER=growthforecast
$ export MYSQL_PASSWORD=password
$ growthforecast.pl --data-dir /home/growthforecast/growthforecast  --with-mysql dbi:mysql:growthforecast;hostname=localhost

挙動確認テスト

GrowthForecastはフォアグラウンドで起動されますので、別のコンソールからデータを投入してみます。こちらのサンプルでvmstatのデータを投入します。

$ wget get -O - https://raw.githubusercontent.com/hiro-su/gf-sample/master/post-sample.sh | bash

エラーが起きずに、投入したデータが流れている状態になれば成功です。

デフォルトのポート番号は5125になるので、以下のURLでグラフを見てみます。

http://192.168.x.x:5125/

vmstatの情報のグラフが見えてます。

しかし、この時点だとグラフが文字化けしてしまっています。

これは、以下のパッケージを導入することで解消できます。

# yum -y install bitmap-console-fonts

文字化け解消されてますね。

systemdへサービス登録

フォアグラウンドで動いているのでsystemdからサービス起動できるように登録します。

色々方法あるかと思いますが、etcの下に設定ファイル作ってあげる方法にしようと思います。

# cat <<EOF > /etc/growthforecast.conf
MYSQL_USER=growthforecast
MYSQL_PASSWORD=password
EOF

以下のようなsystemd定義ファイルを作成してあげます。先ほどの設定ファイルを「EnvironmentFile」で見るようにしてあげて、MariaDBをサービス起動前提に設定しています。

# cat <<EOF > /etc/systemd/system/growthforecast.service
[Unit]
Description=GrowthForecast
Requisite=mariadb.service

[Service]
Type=simple
EnvironmentFile=/etc/growthforecast.conf
ExecStart=/home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/growthforecast.pl --data-dir /home/growthforecast/growthforecast --with-mysql dbi:mysql:growthforecast;hostname=localhost
User=growthforecast
Group=growthforecast

[Install]
WantedBy=multi-user.target
EOF

systemdに読み込んで起動してみます。

# systemctl daemon-reload
# systemctl start growthforecast.service 

無事にsystemdの管理下に置かれたようです。

# systemctl status growthforecast.service 
●  growthforecast.service - GrowthForecast
   Loaded: loaded (/etc/systemd/system/growthforecast.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-04-29 08:27:32 EDT; 37s ago
 Main PID: 2416 (growthforecast.)
   CGroup: /system.slice/growthforecast.service
           ├─2416 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/p...
           ├─2417 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/p...
           ├─2418 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           ├─2419 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           ├─2420 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           ├─2421 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           ├─2422 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           ├─2423 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...
           └─2424 /home/growthforecast/perl5/perlbrew/perls/perl-5.22.1/bin/g...

Apr 29 08:27:32 growthforecastst systemd[1]: Started GrowthForecast.
Apr 29 08:27:32 growthforecastst systemd[1]: Starting GrowthForecast...
Apr 29 08:27:33 growthforecast growthforecast.pl[2416]: 08:27:33 worker_1min.1...
Apr 29 08:27:33 growthforecast growthforecast.pl[2416]: 08:27:33 worker_1min.1...
Apr 29 08:27:33growthforecastt growthforecast.pl[2416]: 08:27:33 worker.1     ...
Apr 29 08:27:33 growthforecast growthforecast.pl[2416]: 08:27:33 worker.1     ...
Apr 29 08:27:33 growthforecast growthforecast.pl[2416]: 08:27:33 web.1        ...
Apr 29 08:27:33 growthforecast growthforecast.pl[2416]: 08:27:33 web.1        ...
Hint: Some lines were ellipsized, use -l to show in full.

systemd管理下に置かれているので停止は以下のコマンドになります。

systemctl stop growthforecast.service

有効化して再起動時に自動起動するようにしておきます。

systemctl enable growthforecast.service

チューニング

こちらのサイトにとても詳しく纏まっています。

https://github.com/sonots/growthforecast-tuning

参考サイト

本家

http://kazeburo.github.io/GrowthForecast/

全般の参考にさせていただきました。

http://nuke.hateblo.jp/entry/20121207/1354845362

GrowthForecastの文字化けについての解決時に参考にさせていただきました。

http://nullpopopo.blogcube.info/2012/08/fluent_and_growthforecast_install02.html

Systemd/NetworkManager/Firewalldについて詳しく書かれている数少ない日本語書籍かと思います。

CentOS7システム管理ガイドsystemd/NetworkManager/Firewalld徹底攻略

CentOS7システム管理ガイドsystemd/NetworkManager/Firewalld徹底攻略