Windows Server に Cacti をインストールする手順を紹介します。
IISをインストールします。インストール手順はこちらの記事を参照してください。
Active Perlをインストールします。インストール手順はこちらの記事を参照してください。
PHPをインストールします。(2017年時点では)バージョンは5系のものを利用します。最新のVersion Release 1.2.2xを利用する場合は、PHP 7をインストールします。
インストール手順はこちらの記事を参照してください。
MariaDBをインストールします。インストール手順はこちらの記事を参照してください。
RRDtoolをインストールします。インストール手順はこちらの記事を参照してください。
net-snmpをインストールします。インストール手順はこちらの記事を参照して下さい。
CactiのWebサイト(https://www.cacti.net/)にアクセスします。左側のメニューの[Downloads]セクションの[Cacti]リンクをクリックします。
ダウンロードページが表示されます。[Windows in ZIP format]のリンクをクリックすると、Windows版のCactiをダウンロードできます。
Windows版のCactiをダウンロードできました。
ZIPファイルを展開します。
展開したファイルを"C:\inetpub\wwwroot\cacti" ディレクトリに配置します。
Spineをダウンロードしてインストールします。手順の詳細はこちらの記事を確認してください。
PHPのファイル名(index.php)をデフォルトドキュメントに設定します。設定手順の詳細はこちらの記事を参照してください。
こちらの記事の手順を参照して、PHPのsnmpモジュールを有効化します。
php.iniファイルを編集して、モジュール等を読み込む設定にします。php.iniファイルが存在しない場合は、php.exe ファイルがあるディレクトリと同じ位置にphp.iniファイルを作成して配置します。
バージョン1.2以降はgettextを有効にする必要があります。
[PHP]
extension_dir = "ext"
extension=php_pdo_mysql.dll
extension=php_com_dotnet.dll
extension=php_sockets.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_openssl.dll
extension=php_gd2.dll
extension=php_snmp.dll
extension=php_gmp.dll
extension=php_gettext.dll
max_execution_time = 60
file_uploads = On
;fastcgi.impersonate = 1
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
;session.save_path = c:\php\Session
error_log = C:\inetpub\wwwroot\log\php_errors.txt
;opcache.enable = On
;opcache.cli_enable = On
memory_limit=1000M
[Date]
date.timezone = "Asia/Tokyo"
[PHP]
extension_dir = "ext"
extension=php_pdo_mysql.dll
extension=php_com_dotnet.dll
extension=php_sockets.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_openssl.dll
extension=php_gd2.dll
extension=php_snmp.dll
extension=php_gmp.dll
max_execution_time = 30
file_uploads = On
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
error_log = C:\inetpub\wwwroot\log\php_errors.txt
[Date]
date.timezone = "Asia/Tokyo"
MariaDBのタイムゾーンの設定をします。手順の詳細はこちらの記事を確認してください。
MySQLのサイトからタイムゾーンのファイルをダウンロードします。ダウンロード後、MySQLのコマンドプロンプトから、
mysql --user=root --password mysql < c:\timezone_posix.sql
コマンドを実行します。
続いてSQLのプロンプトから
show variables like '%time_zone%';
コマンドを実行します。下記の結果が返ります。
+------------------+---------------+
| Variable_name | Value |
+------------------+---------------+
| system_time_zone | ???? (?W????) |
| time_zone | Asia/Tokyo |
+------------------+---------------+
2 rows in set (0.01 sec)
time_zone の値が "Asia/Tokyo" に設定されていればOKです。
my.ini ファイルを変更します。"default-time-zone"を追記し、タイムゾーンの設定をします。また、Cactiに適したデータベースのパラメーターをmy.iniファイルに記述します。デフォルトでは"C:\Proguram Files\MariaDB XX.X\data" ディレクトリにあります。
[mysqld]
datadir=C:/Program Files/MariaDB 10.2/data
port=3306
innodb_buffer_pool_size=255M
character-set-server=utf8
[client]
port=3306
plugin-dir=C:/Program Files/MariaDB 10.2/lib/plugin
[mysqld]
datadir=C:/Program Files/MariaDB 10.2/data
port=3306
default-time-zone='Asia/Tokyo' #データベースのタイムゾーン設定を入れ終わるまで有効化しない (DBが起動できなくなる。)
collation-server=utf8mb4_unicode_ci
character-set-server=utf8mb4
character-set-client=utf8mb4
max_heap_table_size=98M
tmp_table_size=64M
join_buffer_size=64M
innodb_buffer_pool_size=489M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_buffer_pool_instances=5
[client]
port=3306
plugin-dir=C:/Program Files/MariaDB 10.2/lib/plugin
SQLのコマンドプロンプトで下記のコマンドを実行します。
スタートメニューの[MariaDB]またはMySQLのプログラムメニューの"MySQL Client"をクリックします。
パスワード入力プロンプトが表示されます。インストール時に設定した、Rootのパスワードを入力します。
認証が通ると、SQLの入力プロンプトが表示されます。
"create database cacti;"SQLコマンドを入力します。
[Enter]キーを押してSQLを実行します。Query OK のメッセージが表示されます。
MySQL/MariaDB のコマンドプロンプトで下記のコマンドを実行します。
スタートメニューの[MariaDB]またはMySQLのプログラムメニューの"Command Prompt"をクリックします。
MariaDB用のコマンドプロンプトのウィンドウが表示されます。
"mysql --user=root --password cacti < C:\Inetpub\wwwroot\cacti\cacti.sql"コマンドを実行します。
"Enter password:"のパスワード入力プロンプトが表示されます。MariaDBのrootのパスワードを入力します。
処理には若干の時間がかかります。処理が完了するとコマンド入力待ちの状態になります。
SQLのコマンドプロンプトで下記のコマンドを実行します。
(cactiuserのパスワード)の部分に任意のパスワードを設定します。
"MySQL Client"を起動し、SQLコマンドプロンプトに、"GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY '(cactiユーザーのパスワード)'"のコマンドを入力します。
SQLを実行します。正常に実行できると"Query OK" のメッセージが表示されます。
"FLUSH privileges;" のコマンドを続けて実行します。
作成した cactiuser のアカウントが TimeZoneテーブルにアクセスできるよう下記のコマンドを実行します。
grant select on mysql.time_zone_name to 'cactiuser'@'localhost' identified by '(cactiuser のパスワード)';
C:\InetPub\wwwroot\cacti\include\config.php ファイルを修正します。
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/* make sure these values reflect your actual database/host/user/password */
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'cactiuser';
$database_port = '3306';
$database_ssl = false;
/* when the cacti server is a remote poller, then these entries point to
* the main cacti server. otherwise, these variables have no use.
* and must remain commented out. */
#$rdatabase_type = 'mysql';
#$rdatabase_default = 'cacti';
#$rdatabase_hostname = 'localhost';
#$rdatabase_username = 'cactiuser';
#$rdatabase_password = 'cactiuser';
#$rdatabase_port = '3306';
#$rdatabase_ssl = false;
/* the poller_id of this system. set to '1' for the main cacti
* web server. otherwise, you this value should be the poller_id
* for the remote poller. */
$poller_id = 1;
/* set the $url_path to point to the default URL of your cacti
* install ex: if your cacti install as at
* http://serverip/cacti/ this would be set to /cacti/.
*/
$url_path = '/cacti/';
/* default session name - session name must contain alpha characters */
$cacti_session_name = 'Cacti';
/* save sessions to a database for load balancing */
$cacti_db_session = false;
/* optional parameters to define scripts and resource paths. these
* variables become important when using remote poller installs
* when the scripts and resource files are not in the main cacti
* web server path. */
//$scripts_path = '/var/www/html/cacti/scripts';
//$resource_path = '/var/www/html/cacti/resource/';
今回変更する場所は "$database_password"のパスワード部分を変更します。
$database_password = '(データベースユーザー作成時に設定したパスワードを指定する)';
に空のログファイルを作成します。
ディレクトリのアクセス権を設定します。wwwroot(c:\Inetpub\wwwroot)に設置したcactiのディレクトリの"resource"ディレクトリをクリックして選択します。
右クリックしてポップアップメニューを表示します。メニューの[プロパティ]をクリックします。
ディレクトリのプロパティダイアログが表示されます。
[セキュリティ]のタブをクリックします。下図の画面が表示されます。[編集]ボタンをクリックします。アクセス許可ダイアログが表示されます。
上部の[グループまたはユーザー名]のリストボックスから"IIS_IUSRS"のユーザーをクリックして選択します。下部の[アクセス許可]の項目で[フル コントロール]または、[変更]にチェックを入れます。
同様の手順でアクセス権を変更し
のディレクトリに対して書き込み権限を追加します。
WebブラウザでCactiのディレクトリ(http://(ホスト名)/cacti/)にアクセスします。下図の[License Agreement]の画面が表示されます。
画面下部の[Accept GPL License Agreement]のチェックボックスにチェックをします。チェック後、画面の下部の[Next]ボタンをクリックします。
[Pre-Installation Checks]画面が表示されます。設定が正しくできていれば、下図の画面が表示され、次の画面に進めます。画面の最下部の[Next]ボタンをクリックします。
タイムゾーンの設定ができていない場合、下図のエラーが表示され、次に進むことはできません。
[Installation Type]の画面が表示されます。
コンボボックスには"New Primary Server" と "New Remote Poller" の選択肢があります。今回は最初のサーバーですので、"New Primary Server" を選択します。選択後[次に]のボタンをクリックします。
[Critical Binary Locations and Versions]の画面が表示されます。必要なバイナリがインストールされていればグリーンのチェックのマークが表示されます。赤のアイコンが表示されている場合は、インストールされているかの確認、またはインストールパスを設定します。設定後[Next]ボタンをクリックします。
[Directory Permission Checks]の画面が表示されます。書き込み権限が付与されているかのチェックが実行されます。書き込み権限がついていない場合は、ディレクトリのアクセス権を変更します。設定後[Next]ボタンをクリックします。
[Template Setup]の画面が表示されます。
インストールするテンプレートにチェックをつけます。チェック後[Finish]ボタンをクリックします。
Windows版のCactiの場合、PHPの実行時間タイムアウト("Fatal error: Maximum execution time of 50 seconds exceeded.")や、500エラーが発生する可能性があります。その場合は、インストールするテンプレートにチェックをせず、設定完了後にテンプレートをインストールします。
設定が完了すると、下図のログイン画面が表示されます。初期ID"Admin" 初期パスワード"Admin" を入力してログインボタンをクリックします。
[Change Password]のダイアログが表示されます。新しいパスワードを設定します。
変更後、下図のCactiの画面が表示されます。
グラフを表示した場合に、グラフが表示されない場合の対処法です。
Error: opening '(rrd ファイルのパス)': Bad file descriptor
のメッセージが表示される場合は、RRDToolは実行できていますが、
rrdファイルが開けないことが原因です。
[ディレクトリのアクセス権の設定]を参照してc:\Inetpub\wwwroot\cacti\rra
のフォルダにアクセス権を追加します。
グラフの画像が表示されない場合は、RRDToolが実行できない可能性が高いです。
グラフの設定画面を表示します。画面右上の[Turn On Graph Debug Mode]のリンクをクリックします。~
[Turn On Graph Debug Mode]のリンクをクリックするとデバッグモードになり、画面にグラフの画像を生成するためのRRDToolのコマンドが表示されます。
コマンドのパスにRRDToolのファイルが配置されているか確認します。また、表示されたコマンドを実行し、エラーが発生しないことを確認します。
Pollerを定期実行するための設定をします。
タスクスケジューラーを利用して、5分ごとに
のコマンドを実行します。一見問題なさそうですが、この方法ではタスクが停止し、うまく実行できない場合がありました。
1分間隔でPollerを実行する下記のプログラムを作成します。
C#でコンソールアプリケーションを作成し、下記のコードを記述します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace CactiPollerExec
{
class Program
{
static void Main(string[] args)
{
while (true) {
FileStream fs = new FileStream("log.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
try {
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
sw.WriteLine("{0} - Exec Cacti Poller", dt);
Process.Start("c:\\php\\php.exe", @"C:\inetpub\wwwroot\cacti\poller.php");
sw.Flush();
}
finally {
sw.Close();
fs.Close();
}
System.Threading.Thread.Sleep(1000 * 60);
}
}
}
}
上記のプログラムをタスクスケジューラーでWindowsの開始時に実行する設定にします。
以上でインストールは完了です。