CentOS 7の環境にCactiをインストールします。
下記コマンドを実行し、httpdをインストールします。
下記コマンドを実行し、PHPをインストールします。
下記コマンドを実行して net-snmpをインストールします。
SELinuxを無効にします。設定手順はこちらの記事を参照してください。
MariaDBをインストールします。インストール方法はこちらの記事を参照してください。
SELinuxが導入されている場合、MariaDBが起動できないことがあります。下記のコマンドを実行した後でMariaDBを起動します。
上記コマンドを実行後
コマンドを実行します。
データベースの起動後、mysql_secure_installation コマンドを利用してMariaDBの初期設定をします。手順の詳細はこちらの記事を参照してください。
下記コマンドを実行してRRDToolをインストールします。
下記のコマンドを実行します。
バージョン番号はバージョンアップとともに変化するので、http://dl.fedoraproject.org/pub/epel/7/x86_64/eから最新のバージョン番号を確認します。
Cactiをインストールします。EPELリポジトリを有効にすることで、yumコマンドでcactiがインストールできるようになります。
インストールができていれば、/etc/httpd/conf.d/cacti.conf ファイルが設置されています。このファイルを編集します。
コマンドを実行しエディタを起動します。
#
# Cacti: An rrd based graphing tool
#
# For security reasons, the Cacti web interface is accessible only to
# localhost in the default configuration. If you want to allow other clients
# to access your Cacti installation, change the httpd ACLs below.
# For example:
# On httpd 2.4, change "Require host localhost" to "Require all granted".
# On httpd 2.2, change "Allow from localhost" to "Allow from all".
Alias /cacti /usr/share/cacti
<Directory /usr/share/cacti/>
<IfModule mod_authz_core.c>
# httpd 2.4
Require host localhost
</IfModule>
<IfModule !mod_authz_core.c>
# httpd 2.2
Order deny,allow
Deny from all
Allow from localhost
</IfModule>
</Directory>
<Directory /usr/share/cacti/install>
# mod_security overrides.
# Uncomment these if you use mod_security.
# allow POST of application/x-www-form-urlencoded during install
#SecRuleRemoveById 960010
# permit the specification of the rrdtool paths during install
#SecRuleRemoveById 900011
</Directory>
# These sections marked "Require all denied" (or "Deny from all")
# should not be modified.
# These are in place in order to harden Cacti.
<Directory /usr/share/cacti/log>
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Directory>
<Directory /usr/share/cacti/rra>
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Directory>
今回Apache (Httpd)のバージョンは2.4のため、"# httpd 2.4"のセクションを変更します。httpd 2.2までの書式と異なるので注意してください。
#
# Cacti: An rrd based graphing tool
#
# For security reasons, the Cacti web interface is accessible only to
# localhost in the default configuration. If you want to allow other clients
# to access your Cacti installation, change the httpd ACLs below.
# For example:
# On httpd 2.4, change "Require host localhost" to "Require all granted".
# On httpd 2.2, change "Allow from localhost" to "Allow from all".
Alias /cacti /usr/share/cacti
<Directory /usr/share/cacti/>
<IfModule mod_authz_core.c>
# httpd 2.4
#Require host localhost
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# httpd 2.2
Order deny,allow
Deny from all
Allow from localhost
</IfModule>
</Directory>
<Directory /usr/share/cacti/install>
# mod_security overrides.
# Uncomment these if you use mod_security.
# allow POST of application/x-www-form-urlencoded during install
#SecRuleRemoveById 960010
# permit the specification of the rrdtool paths during install
#SecRuleRemoveById 900011
</Directory>
# These sections marked "Require all denied" (or "Deny from all")
# should not be modified.
# These are in place in order to harden Cacti.
<Directory /usr/share/cacti/log>
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Directory>
<Directory /usr/share/cacti/rra>
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Directory>
MariaDBのタイムゾーンの設定をします。手順の詳細はこちらの記事を確認してください。
下記のコマンドを実行します。
/etc/my.cnf ファイル、または、 /etc/my.cnf.d/ ディレクトリ内のcnfファイルを編集します。
cnfファイル内の mysqld セクションに "default-time-zone" を記述します。MariaDBのバージョン10.2の場合は、/etc/my.cnf.d/server.cnf ファイルの[mysqld]セクションに記述するのが良いかもしれません。
[mysqld]
default-time-zone = 'Asia/Tokyo'
続いて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です。
cactiuser のアカウントが TimeZoneテーブルにアクセスできるよう下記のコマンドを実行します。
grant select on mysql.time_zone_name to 'cactiuser'@'localhost' identified by '(cactiuser のパスワード)';
/etc/my.cnf ファイルか /etc/my.cnf.d/ ディレクトリ内の設定ファイルの [mysqld]セクションに下記のオプションパラメータをついkします。今回は、/etc/my.cnf.d/server.cnf ファイルの[mysqld]セクションに記述します。
[mysqld]
default-time-zone = 'Asia/Tokyo'
collation-server = utf8mb4_unicode_ci
character-set-client = utf8mb4
character-set-server = utf8mb4
max_heap_table_size = 300M
tmp_table_size = 128M
join_buffer_size = 128M
innodb_buffer_pool_size = 960M
innodb_doublewrite = OFF
innodb_flush_log_at_timeout = 5
innodb_read_io_threads = 48
innodb_write_io_threads = 32
default-time-zone は先のタイムゾーン設定の手順で追記した部分になります。
下記コマンドを実行してSQLコマンドプロンプトを表示します。
mysql -u root -p
下記コマンドを実行してmariadbにデータベースを作成します。
create database cacti;
下記SQLコマンドを実行してcactiuserユーザーを作成します。
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY '(cactiユーザーのパスワード)';
FLUSH privileges;
以下のコマンドを実行します。identified by の後の '(cactiユーザーのパスワード)' はパスワードになりますので、変更のうえコマンドを実行します。
GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY '(cactiユーザーのパスワード)';
FLUSH privileges;
コマンドを実行した後、
quit;
でSQLプロンプトを終了します。
mysqladmin -u root -p create cactiuser
mysqladmin -u root -p create cacti
コマンドでもユーザーの作成はできます。
下記のコマンドを実行し、テーブルなどを作成します。
mysql -u cactiuser -p cacti < /usr/share/doc/cacti-0.8.8g/cacti.sql
データベース名とデータベースのユーザーが同じ名前のためわかりにくいです。
mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8g/cacti.sql
コマンドの書式は下記となります。
mysql -u (データベースのユーザー名) -p (データベース名) < /usr/share/doc/cacti-0.8.8g/cacti.sql
データベースのユーザー名やパスワードをデフォルトのものから変更した場合は、/etc/cacti/db.php を編集します。
/usr/share/cacti/include/config.php のシンボリックリンクがあるため、/usr/share/cacti/include/config.php を編集しても同様の処理となります。
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2016 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 refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser"; /* 必要に応じて変更 */
$database_password = "(cactiユーザーのパスワード)"; /* 必要に応じて変更 */
$database_port = "3306";
$database_ssl = false;
/*
Edit this 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";
?>
plugins, log, rra ディレクトリに書き込み権限を付与します。下記コマンドを実行します。
またh
または
/etc/cron.d/cacti ファイルを編集し、crondで5分に1回pollerが実行されるようにします。
#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
コメント記号を外します。
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
ファイアウォールの設定を変更して、httpで外部からアクセス可能な状態に変更します。