cactiとは

サーバや通信機器のグラフレポーティングツール。
基本的な機能はSNMPにより情報を取得しグラフ化する。
データの収集はrrdtoolによる。
自作スクリプトを利用すればあらゆる数値情報をグラフ化できる。

導入方法

cacti(0.8.8)をCentOS(6.2)へインストールした際の備忘録

CentOSの導入と基本設定

CentOSのインストール

最小構成でインストールする。

ユーザアカウント作成

[root@myhost ~]# useradd myaccount
[root@myhost ~]# passwd myaccount
Changing password for user myaccount.
New UNIX password: <- パスワード入力
Retype new UNIX password: <- パスワード入力
passwd: all authentication tokens updated successfully.
[root@myhost ~]# 

sshdの設定

[root@myhost ~]# vi /etc/ssh/sshd_config
-----snip-----
#PermitRootLogin yes  <-  コメントアウト
PermitRootLogin no    <-  追加
-----snip-----
[root@myhost ~]# /etc/init.d/sshd restart
sshd を停止中:                                             [  OK  ]
sshd を起動中:                                             [  OK  ]
[root@myhost ~]# chkconfig sshd on
[root@myhost ~]# chkconfig --list sshd
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@myhost ~]# 

あとはリモートでログインして作業する。

SELINUXとiptablesによるアクセス制御の設定

SELinuxを無効にする

[root@myhost tmp]# vi /etc/selinux/config
-----snip-----
#SELINUX=enforcing       <-  コメントアウト
SELINUX=disabled         <-  追加
-----snip-----

iptablesの設定

[root@myhost tmp]# vi /etc/sysconfig/iptables
-----snip-----
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT                   <- 追加(http)
-A INPUT -p tcp --dport 443 -j ACCEPT                  <- 追加(https)
-A INPUT -p udp --dport 161 -j ACCEPT                  <- 追加(snmp)
-A INPUT -p udp --dport 162 -j ACCEPT                  <- 追加(snmptrap)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
-----snip-----

(SELinuxの設定がシステム再起動で反映されるため、再起動する。)

[root@myhost tmp]# shutdown -r now

RPMforgeのインストール

cactiは標準のリポジトリに含まれていないため、RPMforgeのリポジトリを利用する。

標準リポジトリのパッケージをRPMforgeパッケージでアップデートしなくする。

[root@myhost ~]# yum -y install yum-plugin-priorities
[root@myhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
各セクション[]で囲まれた部分の最後に
priority=1
を追加する。

RPMforgeのリポジトリ追加

[root@myhost ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
[root@myhost ~]# rpm -ihv rpmforge-release-0.5.2-2.el6.rf.i686.rpm

cactiセットアップ

cacti本体のインストール

cacti0.8.8はプラグインアーキテクチャ同梱のため、yumでそのままインストールする。mysqlは依存関係でインストールされないため、同時に指定する。

[root@myhost ~]# yum install cacti-spine mysql-server

cacti用のapache設定

[root@myhost ~]# vi /etc/httpd/conf.d/cacti.conf
Alias /cacti/ /var/www/cacti/
<Directory /var/www/cacti/>
   DirectoryIndex index.php
   Options -Indexes
   AllowOverride all
   order deny,allow
   deny from all
   allow from 127.0.0.1
   allow from xxx.xxx.xxx.xxx/yy  <- 追加
   AddType application/x-httpd-php .php
   php_flag magic_quotes_gpc on
   php_flag track_vars on
</Directory>

グラフに日本語を利用するための設定

[root@myhost ~]# vi /etc/sysconfig/httpd
----- snip -----
#HTTPD_LANG=C              <- コメントアウト
HTTPD_LANG=ja_JP.UTF-8     <- 追加
----- snip -----

サービスの起動設定

[root@myhost ~]# /etc/init.d/httpd start
[root@myhost ~]# chkconfig httpd on
[root@myhost ~]# chkconfig --list httpd 
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@myhost ~]# vi /etc/my.cnf
----- snip -----
[mysqld]
default-character-set=utf8              <- 追加
skip-character-set-client-handshake     <- 追加

[mysql]
default-character-set=utf8              <- 追加
----- snip -----

[root@myhost ~]# /etc/init.d/mysqld start
[root@myhost ~]# chkconfig mysqld on
[root@myhost ~]# chkconfig --list mysqld
mysqld           0:off   1:off   2:on    3:on    4:on    5:on    6:off

MySQL設定

[root@myhost ~]# mysqladmin -u root password XXXXX
[root@myhost ~]# mysql -u root -p
mysql> use mysql;
mysql> select user,host,password from user;
+------+------------------------+------------------+
| user | host                   | password         |
+------+------------------------+------------------+
| root | localhost              | XXXXXXXXXXXXXXXX | 
| root | XXXXXX.XXXX.XXX.XX     |                  | 
| root | 127.0.0.1              |                  | 
|      | localhost              |                  | 
|      | XXXXXX.XXXX.XXX.XX     |                  | 
+------+------------------------+------------------+
5 rows in set (0.00 sec)

mysql> delete from user where password = "";
Query OK, 4 rows affected (0.00 sec)

mysql> select user,host,password from user;
+------+-----------+------------------+
| user | host      | password         |
+------+-----------+------------------+
| root | localhost | XXXXXXXXXXXXXXXX | 
+------+-----------+------------------+
1 row in set (0.01 sec)

mysql>exit;

MySQLのcacti用アカウント設定

[root@myhost ~]# mysqladmin -u root -p create cacti
[root@myhost ~]# mysql -u root -p cacti < /var/www/cacti/cacti.sql 
[root@myhost ~]# mysql -u root -p 
mysql> grant all on cacti.* to cactiuser@localhost identified by 'cactiuser';
mysql> flush privileges;
mysql> 

config.phpの編集

[root@myhost ~]# vi /var/www/cacti/include/config.php 
-----snip----- 
/*
   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 = "/";
$url_path = "/cacti/"; ←修正
-----snip-----

cacti動作確認

webでアクセス。
http://サーバのIPアドレス/cacti/
最後にスラッシュがないとアクセスできないので注意。

初回ログイン時は強制的にパスワード変更ダイアログが出る。
セットアップした直後の初期アカウントは admin/admin となっている。

その他の設定

spineを利用する際はConsole -> Cacti Settinfs -> Paths の spineパス設定と Console -> Cacti Settinfs -> Poller の Poller Type設定をする。

sslへの対応

[root@myhost plugins]# yum install mod_ssl
[root@myhost plugins]# cd /etc/httpd
[root@myhost plugins]# mkdir ssl
[root@myhost plugins]# cd ssl
[root@myhost ssl]# openssl genrsa -des3 1024 > ./server.key
[root@myhost ssl]# openssl rsa -in ./server.key -out ./server.key
[root@myhost ssl]# chmod 400 ./server.key
[root@myhost ssl]# openssl req -new -key ./server.key -out ./server.csr
[root@myhost ssl]# openssl x509 -in ./server.csr -out ./server.crt -req -signkey ./server.key -days 3650
[root@myhost ssl]# vi ../conf.d/ssl.conf
-----snip-----
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt  <-  コメントアウト
SSLCertificateFile /etc/httpd/ssl/server.crt          <-  追加
-----snip-----
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key   <-  コメントアウト
SSLCertificateKeyFile /etc/httpd/ssl/server.key             <-  追加
-----snip-----
[root@myhost ssl]# /etc/init.d/httpd restart

で、完了!

なにかおかしい。。。

うまくポーリングが動作しない。タイムゾーンの設定が適切でないことと、phpのセッション保存ディレクトリのパーミッションがおかしいようだ。

[root@myhost ~]# vi /etc/php.ini
---- snip ----
;date.timezone = 
date.timezone = Asia/Tokyo    <-- 追加
---- snip ----
[root@myhost ~]# /etc/init.d/httpd restart
[root@myhost ~]# chmod 777 /var/lib/php/session/



Counter: 2048, today: 1, yesterday: 0

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS