Cactiを使ってみる

今日はCactiをインストールします。
今回はCentOS5.4で。

セットアップ方針

  • 必要なソフトウェアをソースファイルとRPMパッケージを使ってセットアップ
  • RPMパッケージは入っていなければ先に yum install 入れておく
  • とりあえずSSL対応にしておくためにopensslも入れておく
  • ソースからインストールするソフトウェア類は/usr/local/cacti以下にまとめる

ソースファイルからインストールするソフト

RPMパッケージを使ってインストールするソフト
  • libxml2
  • libxml2-devel
  • libjpeg
  • libjpeg-devel
  • libpng
  • libpng-devel
  • zlib
  • zlib-devel
  • gd
  • gd-devel
  • libart_lgpl
  • libart_lgpl-devel
  • freetype
  • freetype-devel
  • net-snmp-libs
  • net-snmp
  • net-snmp-utils
  • net-snmp-devel

セットアップ手順

何も考えずにがしがし進めます。

OpenSSLのインストール

ソースファイルからインストールします。

# tar -xvzf openssl-1.0.0-beta4.tar.gz 
# cd openssl-1.0.0-beta4
# ./config --prefix=/usr/local/cacti/openssl-1.0.0-beta4
# make
# make test
# make install
# ln -s /usr/local/cacti/openssl-1.0.0-beta4 /usr/local/cacti/openssl
Apacheのインストール

ソースファイルからインストールします。

# tar -xvzf httpd-2.2.14.tar.gz 
# cd httpd-2.2.14
# ./configure --prefix=/usr/local/cacti/httpd-2.2.14 --with-mpm=prefork \
--with-ssl=/usr/local/cacti/openssl --enable-ssl --enable-rewrite --enable-so
# make
# make install
# ln -s /usr/local/cacti/httpd-2.2.14 /usr/local/cacti/httpd
MySQLのインストール

ソースファイルからインストールします。
#なんとなく、nobodyユーザを使ってみる。本当は専用ユーザがいいのでしょうが。

# tar -xvzf mysql-5.1.41.tar.gz 
# cd mysql-5.1.41
# ./configure --prefix=/usr/local/cacti/mysql-5.1.41 \
--with-charset=ujis --with-extra-charset=all --with-mysqld-user=nobody
# make
# make install
# ln -s /usr/local/cacti/mysql-5.1.41 /usr/local/cacti/mysql

MySQLの初期設定を行います。

  • データベースの初期化をします。
# /usr/local/cacti/mysql/bin/mysql_install_db
  • データベース領域の権限を変更します。
# chown -R nobody:nobody /usr/local/cacti/mysql-5.1.41
  • 起動確認をします。
# /usr/local/cacti/mysql/bin/mysqld_safe --old-passwords &
  • データベース管理ユーザのパスワードを設定します。
# /usr/local/cacti/mysql/bin/mysqladmin -u root password <<変更するパスワード>>
  • データベースにログインして、パスワード設定をされていないユーザを削除します。
# /usr/local/cacti/mysql/bin/mysql -u root -p
Enter password: <<データベース管理ユーザのパスワード入力>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.41 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> DELETE FROM user WHERE password='';
Query OK, 4 rows affected (0.00 sec)

mysql> exit
Bye
PHPのインストール

ソースファイルからインストールします。

# tar -xvzf php-5.2.12.tar.gz 
# cd php-5.2.12
# ./configure --prefix=/usr/local/cacti/php-5.2.12 --with-apxs2=/usr/local/cacti/httpd/bin/apxs \
--with-mysql=/usr/local/cacti/mysql --with-gd --with-png-dir --with-jpeg-dir --with-zlib-dir \
--enable-sockets --enable-mbstring --without-pgsql
# make
# make test
# make install
# ln -s /usr/local/cacti/php-5.2.12 /usr/local/cacti/php

ApachePHP用の設定を追加します。

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
  • 動作確認のためにApacheを起動します。
# /usr/local/cacti/httpd/bin/apachectl configtest
「Syntax OK」と出力されることを確認して
# /usr/local/cacti/httpd/bin/apachectl start
  • ドキュメントルート以下にphpinfo.php を作成し、PHPの動作確認をします。
 <?php
     phpinfo();
 ?>
  • phpinfo.php にブラウザでアクセスして、以下のような画面が表示されればOKです。

RRDToolのインストール

ソースファイルからインストールします。

# tar -xvzf rrdtool-1.2.27.tar.gz
# cd rrdtool-1.2.27
# ./configure --prefix=/usr/local/cacti/rrdtool-1.2.27
# make
# make install
# ln -s /usr/local/cacti/rrdtool-1.2.27 /usr/local/cacti/rrdtool
Cactiのインストール
  • ファイルを展開して、ドキュメントルート以下に配置します。
# tar -xvzf cacti-0.8.7e.tar.gz
# mv cacti-0.8.7e /usr/local/cacti/httpd/htdocs/cacti
  • 公式パッチを適用します。
# cd /usr/local/cacti/httpd/htdocs/cacti/
# pwd
/usr/local/cacti/httpd/htdocs/cacti
# patch -p1 -N < /usr/local/src/cacti/cli_add_graph.patch
patching file cli/add_graphs.php
# patch -p1 -N < /usr/local/src/cacti/cross_site_fix.patch
patching file graph.php
patching file include/top_graph_header.php
patching file lib/html_form.php
patching file lib/timespan_settings.php
# patch -p1 -N < /usr/local/src/cacti/snmp_invalid_response.patch
patching file include/global_arrays.php
patching file lib/snmp.php
# patch -p1 -N < /usr/local/src/cacti/template_duplication.patch
patching file cli/repair_templates.php
patching file docs/README
patching file lib/export.php
patching file lib/import.php
patching file lib/utility.php
  • MySQLを起動して、データベースの初期設定を行います。
# /usr/local/cacti/mysql/bin/mysqld_safe &
# cd /usr/local/cacti/httpd/htdocs/cacti/
# /usr/local/cacti/mysql/bin/mysqladmin -u root -p create cacti
Enter password: <<データベース管理ユーザのパスワード入力>>
# /usr/local/cacti/mysql/bin/mysql -u root -p < cacti.sql cacti
Enter password: <<データベース管理ユーザのパスワード入力>>
# /usr/local/cacti/mysql/bin/mysqladmin -u root -p reload
Enter password: <<データベース管理ユーザのパスワード入力>>
  • データベースの設定を行います。
# /usr/local/cacti/mysql/bin/mysql -u root -p
Enter password: <<データベース管理ユーザのパスワード入力>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.41 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use cacti
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_cacti           |
+---------------------------+
| cdef                      |
| cdef_items                |
| colors                    |
| data_input                |
| data_input_data           |
| data_input_fields         |
| data_local                |
| data_template             |
| data_template_data        |
| data_template_data_rra    |
| data_template_rrd         |
| graph_local               |
| graph_template_input      |
| graph_template_input_defs |
| graph_templates           |
| graph_templates_gprint    |
| graph_templates_graph     |
| graph_templates_item      |
| graph_tree                |
| graph_tree_items          |
| host                      |
| host_graph                |
| host_snmp_cache           |
| host_snmp_query           |
| host_template             |
| host_template_graph       |
| host_template_snmp_query  |
| poller                    |
| poller_command            |
| poller_item               |
| poller_output             |
| poller_reindex            |
| poller_time               |
| rra                       |
| rra_cf                    |
| settings                  |
| settings_graphs           |
| settings_tree             |
| snmp_query                |
| snmp_query_graph          |
| snmp_query_graph_rrd      |
| snmp_query_graph_rrd_sv   |
| snmp_query_graph_sv       |
| user_auth                 |
| user_auth_perms           |
| user_auth_realm           |
| user_log                  |
| version                   |
+---------------------------+
48 rows in set (0.04 sec)
  • cacti用のユーザに権限を設定します。
mysql> grant all on cacti.* to cactiuser@localhost identified by '<<cactiuserのパスワード>>';
Query OK, 0 rows affected (0.01 sec)
  • データベースからログアウトします。
mysql> exit
Bye
  • 設定ファイルの設定を確認します。
# vi /usr/local/cacti/httpd/htdocs/cacti/include/config.php

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "<<cactiuserのパスワード>>";
$database_port = "3306";
*/5 * * * * /usr/local/cacti/php/bin/php /usr/local/cacti/httpd/htdocs/cacti/poller.php > /dev/null 2>&1
Spine(cactid)のインストール

ソースファイルからインストールします。
snmp_v3_fix.patch」のパッチを当てたら下のエラーメッセージが出て、
コンパイル通らなかったので、こいつ以外のパッチを当てました。
autoconfを新しくしろと…。

aclocal.m4:20: warning: this file was generated for autoconf 2.63.
You have another version of autoconf.  It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically `autoreconf'.
configure.ac:12: error: Autoconf version 2.62 or higher is required
aclocal.m4:7169: AM_INIT_AUTOMAKE is expanded from...
configure.ac:12: the top level
autom4te: /usr/bin/m4 failed with exit status: 63
make: *** [configure] エラー 1
  • でインストール作業です。
# tar -xvzf cacti-spine-0.8.7e.tar.gz
# cd cacti-spine-0.8.7e
# patch -p1 -N < /usr/local/src/cacti/mysql_client_reconnect.patch
patching file sql.c
# patch -p1 -N < /usr/local/src/cacti/ping_reliability.patch
patching file ping.c
patching file ping.h
# ./configure --prefix=/usr/local/cacti/cacti-spine-0.8.7e --with-mysql=/usr/local/cacti/mysql
# make
# make install
# ln -s /usr/local/cacti/cacti-spine-0.8.7e /usr/local/cacti/cacti-spine
  • 設定ファイルの確認をします
# vi /usr/local/cacti/cacti-spine-0.8.7e/etc/spine.conf
DB_Host         localhost
DB_Database     cacti
DB_User         cactiuser
DB_Pass         <<cactiuserのパスワード>>
DB_Port         3306
Cactiの初期設定

初期設定を行います。

  • http://ホスト/cacti にアクセスすると、以下の画面が表示されます。

[Next]をクリックします。

  • [New Install]が選択されていることを確認します。

[Next]をクリックします。

  • [NOT FOUND] の項目については適切なパスを指定します。

[Finish] をクリックします。

  • ログイン画面が表示されるので初期パスワードの[user:admin][pass:admin]でログインします。

  • ログインすると管理画面が表示されます。


ここまでいけばインストールはOKかと。

おまけ:Cactiインストール初期設定時に表示されたエラー

Cactiの初期設定作業を行う時に、今回いくつかエラーが表示されてしまいました。
対処したことを書いておきます。

  • その1

初期設定画面にブラウザからアクセスしたら、こんなエラーが表示されました。

PHPをconfigureする場合に--enable-socketsオプションを付けていないとこうなってしまうようです。

以下のページを参考にさせていただきました。

  • その2

こんなエラーも表示されました。

当初、RRDToolの1.4系をインストールしたのですが、どうやらそれがいけなかった模様です。
RRDToolは1.2系じゃないと駄目なようです。
#確かにREADMEは「RRDTool 1.0.49+ or 1.2.x」となっていた…。


まずはインストールまで。また時間を作って触ってみようと思います。
今日はこんなところで。