facebook twitter hatena line email

Cacti/cactiインストールメモ

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

サーバ負荷監視ツールcactiインストールメモ

必須環境

php
mysql
apache
php-mysql

net-snmpインストール

# yum install net-snmp
# yum install net-snmp-utils
# yum install net-snmp-devel
# yum install php-snmp
# /etc/rc.d/init.d/snmpd start
# /sbin/chkconfig snmpd on
# /sbin/chkconfig --list snmpd

yum install php-snmpが以下エラーになる場合

--> Processing Dependency: php-common(x86-64) = 5.3.29-1.el6_15.wing for package: php-snmp-5.3.29-1.el6_15.wing.x86_64

phpバージョンが違うためと思われるので以下のような感じで対応

# yum install php-snmp.x86_64  --enablerepo=remi --enablerepo=remi-php55

snmp設定

# vi /etc/snmp/snmpd.conf
#       sec.name  source          community
#com2sec notConfigUser  default       public # del
#       groupName      securityModel securityName
#group   notConfigGroup v1c           notConfigUser # del
#group   notConfigGroup v2c           notConfigUser # del
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
#view    systemview    included   .1.3.6.1.2.1.1 # del
#view    systemview    included   .1.3.6.1.2.1.25.1.1 # del
# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none # del
# Check the / partition and make sure it contains at least 10 megs.
#disk / 10000

com2sec local localhost private # add
com2sec mynetwork 192.168.0.0/24 public # 追加(192.168.0.は環境に合わせる)
group MyROGroup v1 local # add
group MyROGroup v2c local # add
group MyROGroup v1 mynetwork # add
group MyROGroup v2c mynetwork # add
view all included .1 80 # add
access MyROGroup "" any noauth exact all none none # add
access MyRWGroup "" any noauth exact all all none # add
disk / 10000 # add

RRDToolインストール準備

# export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/share/pkgconfig
#
# yum install libart_lgpl-devel
# yum -y install gcc
#
# cd /usr/local/src
# wget http://www.infodrom.org/projects/cgilib/download/cgilib-0.5.tar.gz
# tar xvzf cgilib-0.5.tar.gz
# cd cgilib-0.5
# make
# cp libcgi.a /usr/local/lib/
# cp cgi.h /usr/local/include/
# /sbin/ldconfig
# 
# yum install zlib-devel
# 
# cd /usr/local/src
# wget -P /usr/local/src http://jaist.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.12.tar.gz
# tar xzf libpng-1.2.12.tar.gz
# cd libpng-1.2.12
# ./configure --prefix=/usr/local
# make
# make install
# 
# cd /usr/local/src/
# wget http://download.savannah.gnu.org/releases/freetype/freetype-old/freetype-2.3.2.tar.gz
# tar zxf freetype-2.3.2.tar.gz
# cd freetype-2.3.2
# ./configure
# make
# make install

ファイルやディレクトリはありませんエラーが出るとき

rmdir: /usr/local/include/freetype2/freetype/internal: そのようなファイルやディレクトリはありません

が出るときは

mkdir /usr/local/include/freetype2/freetype/internal

makeでエラーが出るとき

make: *** [cgi.o] エラー 127
$ yum -y install gcc

RRDToolインストール準備2

# yum install gd gd-devel
# yum install cairo-devel
# yum install pango-devel
# yum install libxslt-devel
# yum install glib2-devel

RRDToolインストール

# cd /usr/local/src
# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.5.3.tar.gz
# tar xvzf rrdtool-1.5.3.tar.gz
# cd rrdtool-1.5.3
# ./configure
# make
# make install
# ln -s /usr/local/src/rrdtool-1.5.3 /usr/local/rrdtool

RRDToolインストールでエラーが出た時

Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
# yum install perl-ExtUtils-MakeMaker

日付確認

$ date
$ date -s "07/06 14:11 2016" # 日付を入れる

cactiインストール準備

# yum install patch

cactiインストール

# cd /usr/local/src
# wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
# tar zxvf cacti-0.8.8h.tar.gz
# mv cacti-0.8.8h /var/www/cacti
# cd /var/www/cacti
mysql > CREATE DATABASE cacti DEFAULT CHARACTER SET utf8;
# /usr/bin/mysql -u root -p < cacti.sql cacti
# /usr/bin/mysqladmin -u root -p reload
mysql> grant all on cacti.* to cactiuser@localhost identified by 'cactiuser';

以下エラーが出たら

ERROR 1064 (42000) at line 5: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 6

cacti.sqlのTYPE=をENGINE=に変更する

以下エラーが出たら

ERROR 1067 (42000) at line 1847: Invalid default value for 'status_fail_date'
$ vim cacti.sql cacti
:%s/0000-00-00/0000-01-01/g

上記のように置換する

cacti_mysqlユーザ設定

# vi /var/www/cacti/include/config.php // userとpassを変更時は以下を編集
#$database_username = "cactiuser";
#$database_password = "cactiuser";
#上記を変更する

ERROR: Your MySQL TimeZone database is not populatedエラーが出た場合

mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql

ldapインストール

linux/ldapインストール [ショートカット]

cactiパッチ

cactiバージョンによるがパッチが出ていれば当てる

  • 0.8.8cの場合

必要なし

  • 0.8.8bの場合
# wget http://www.cacti.net/downloads/patches/0.8.8b/security.patch
# patch -p1 -N < security.patch
  • 0.8.8aの場合
# wget http://www.cacti.net/downloads/patches/0.8.8a/security.patch
# wget http://www.cacti.net/downloads/patches/0.8.8a/snmpv3_priv_proto_none.patch
# patch -p1 -N < security.patch
# patch -p1 -N < snmpv3_priv_proto_none.patch  
  • 0.8.7gの場合
# cd /var/www/cacti/
# wget http://www.cacti.net/downloads/patches/0.8.7g/data_source_deactivate.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/graph_list_view.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/html_output.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/ldap_group_authenication.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/script_server_command_line_parse.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/ping.patch
# wget http://www.cacti.net/downloads/patches/0.8.7g/poller_interval.patch
# patch -p1 -N < data_source_deactivate.patch
# patch -p1 -N < graph_list_view.patch
# patch -p1 -N < html_output.patch
# patch -p1 -N < ldap_group_authenication.patch
# patch -p1 -N < script_server_command_line_parse.patch
# patch -p1 -N < ping.patch
# patch -p1 -N < poller_interval.patch

apacheバーチャルホスト設定

<VirtualHost *:80>
 ServerName cacti.example.jp
 DocumentRoot "/var/www/cacti"
 HostNameLookups off
 UseCanonicalName on
 <Directory "/var/www/cacti">
   Options Indexes FollowSymLinks Includes ExecCGI
   AllowOverride All
   Allow from All
 </Directory>
</VirtualHost>

cacti.example.jpは適宜変更

nginxバーチャルホスト設定

server {
   listen       80;
   server_name  cacti.localhost;
   location / {
       root   /var/www/cacti;
       index  index.html index.php;
   }
   location ~ \.php$ {
       root   /var/www/cacti;
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
   }
}

cacti初期設定

  1. ブラウザでhttp://cacti.example.jp/install/へアクセス
  2. setting/Paths/RRDTool Binary Pathを"/usr/local/rrdtool/src/rrdtool"へ指定
  3. 初期ユーザ:パスワード admin:adminを入力
  4. 新しいパスワードを入力しなおす

/cacti/へリダイレクトされる場合

$ vi include/config.php  [$ vi include/global.php (0.8.8系の場合)]
- $url_path = "/cacti/";
+ $url_path = "/";

linuxにcactiユーザ作成

# adduser cacti

logとrraディレクトリをcacti権限に変更

# cd /var/www/cacti
# chown -R cacti.apache rra log
# chmod 775 rra log

cactiユーザに自動集計

# sudo su cacti
# crontab -e
*/5 * * * * /usr/bin/php /var/www/cacti/poller.php > /dev/null 2>&1
# 月1自動削除
* * 1 * * echo "dummy" > /var/www/cacti/log/cacti.log

グラフが表示されない場合

  1. Console/Configuration Settings/General/RRDTool Utility Versionに
rrdtool 1.4.xに変更
  1. Console/Configuration Settings/visual/Default RRDtool 1.2 Fontsに
/usr/local/rrdtool/src/DejaVuSansMono-Roman.ttfを設定

なければフォントを探して入れる

$locate .ttf | grep cacti
/var/www/cacti/DejaVuSansMono-Roman.ttf
  1. /etc/php.iniに以下を追加
[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Tokyo
  1. /usr/bin/php /var/www/cacti/poller.phpでError表示されないか確認
  1. selinuxを一旦無効にしてみる(バイナリ画像自体が出ない場合:rraディレクトリにはファイルがある)
# sestatus # 現在のステータス確認
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
# setenforce 0 # 一旦無効
# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
# setenforce 1 # 一旦有効
  1. "bash: /usr/local/src/rrdtool: はディレクトリです"となる場合
locate rrdtool | grep rrdtool$

Console/Configuration Settings/Paths/RRDToolにrrdtoolのパスを入れる

  1. 日付が未来になってないか確認する
$ date

日付を合わせる。(もしかするとcactiを再インストールした方が良いかも)

php5.4でsetting画面が表示されない問題

$ vi lib/functions.php
-410 session_unregister($var_name);

をコメントアウト

cactiスクリプトのdir場所を変更した場合

  1. console/setting/path/Loggingのパスを変更
  2. use cacti;select * from poller_item;のデータ変更

監視サーバを追加

  1. console/management/device画面でadd

snmpエラーになる場合は "Downed Device Detection"のsnmpをpingへ変更

参考

http://kikuz0u.x0.com/memo/hiki.cgi?Cacti+%28RRDTool%A5%D5%A5%ED%A5%F3%A5%C8%A5%A8%A5%F3%A5%C9%29%A1%A1%A1%C1+Linux%CA%D4+%A1%C1

http://fedorasrv.com/rrdtool-cacti.shtml