#yum -y install *gcc*
#yum -y install httpd httpd-manual mysql mysql-devel mysql-server php php-devel php-mysql php-common php-pdo php-gd lm_sensors net-snmp php-snmp net-snmp-utils
# chkconfig mysqld on
# chkconfig httpd on
# chkconfig snmpd on
# service mysqld start
# service httpd start
# service snmpd start
# mysqladmin -u root password 'redhat321'
# mysql -u root -p
:输入密码
mysql>create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql>grant all on cacti.* to cactiadmin@localhost identified by 'cacti321';
Query OK, 0 rows affected (0.01 sec)
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
# tar xf rrdtool-1.4.4.tar.gz
# cd rrdtool-1.4.4
# ./configure --prefix=/usr/local/rrdtool && make && make install
# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
# tar xf cacti-0.8.7e.tar.gz -C /var/www/html/
# cd /var/www/html/
# mv cacti-0.8.7e/ cacti
# chown -R root.root /var/www/html/cacti/
# mysql -u root -p cacti <cacti/cacti.sql
Enter password:
# vim /var/www/html/cacti/include/config.php
$database_username = "cactiadmin";
$database_password = "cacti321";
# vim /var/www/html/cacti/include/global.php
$database_username = "cactiadmin";
$database_password = "cacti321";
# wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip
# unzip cacti-plugin-0.8.7e-PA-v2.6.zip
# cd cacti-plugin-arch/
# cp cacti-plugin-arch/{cacti-plugin-0.8.7e-PA-v2.6.diff,pa.sql} /var/www/html/cacti/
# cd /var/www/html/cacti/
# patch -p1 -N <cacti-plugin-0.8.7e-PA-v2.6.diff
# mysql -uroot -p cacti<pa.sql
# vim include/global.php
$config['url_path'] = '/cacti/';
# crontab -e
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php
# service crond restart
# vim /etc/snmp/snmpd.conf
com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact mib2 none none
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
# useradd -s /sbin/nologins nagios
# mkdir -p /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/
# tar xf nagios-3.4.1.tar.gz
# cd nagios
# ./configure --prefix=/usr/local/nagios/
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# chkconfig --add nagios
# chkconfig nagios on
# service nagios start
# tar xf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios/ && make && make install
# vim /etc/httpd/conf/httpd.conf
最后添加如下内容,设置成需要输入密码才能登陆
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagions Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
(1)hosts.cfg定义主机的文件
define host{
use linux-server
host_name 192.168.163.143
alias 192.168.163.143
address 192.168.163.143
}
(2)services.cfg 定义主机服务的文件
define service{
use local-service //引用local-service的属性信息,在template.cfg中定义
host_name 192.168.163.143 //监控那个主机,host-142在hosts.cfg中定义
service_description ssh //对监控内容的描述
check_command check_ssh //指定监控的命令,check_ping在commands.cfg中定义
}
define service{
use local-service
host_name 192.168.163.143
service_description Ping
check_command check_ping
}
# chown nagios.nagios /usr/local/nagios/etc/objects/{hosts.cfg,services.cfg}
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# tar xf php-json-ext-1.2.1.tar.gz
# cd php-json-ext-1.2.1
# phpize
如果没有命令的话安装下面的软件包
# rpm -ihv /media/CentOS/php-devel-5.1.6-27.el5.i386.rpm
# sh configure && make && make install
# vim /etc/php.d/json.ini
extension=json.so
# tar xf ndoutils-1.4b9.tar.gz
# cd ndoutils-1.4b9
# ./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --with-ndo2db-user=nagios--with-ndo2db-group=nagios
# make(不用make install)
# cp src/{ndomod-3x.o,ndo2db-3x,log2ndo,file2sock} /usr/bin/
# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# chmod 644 /var/www/html/nagios/etc/ndo*
# vim /usr/local/nagios/etc/ndo2db.cfg
socket_type=tcp
db_host=127.0.0.1
db_port=3306
db_name=cacti
db_prefix=npc_
db_user=cactiadmin
db_pass=cacti321
debug_level=1
# vim /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
# cp /download/ndoutils-1.4b9/daemon-init /etc/init.d/ndo2db
# vim /etc/init.d/ndo2db
Ndo2dbBin=/usr/bin/ndo2db-3x
# chmod +x /etc/init.d/ndo2db
# service ndo2db start
# tar xf npc-2.0.4.tar.gz
# mv npc /var/www/html/cacti/plugins/
修改配置文件,添加如下信息
# vim /var/www/html/cacti/include/global.php
$plugins = array();
$plugins[]='npc';
# vim /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
event_broker_options=-1
# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
# tar zxvf PDO_MYSQL-1.0.2.tgz
# cd PDO_MYSQL-1.0.2
# /usr/local/php/bin/phpize
#./configure --with-php-config=/usr/bin/php-config
#make
#make install
修改php.ini,添加如下信息,之后重启httpd即可
extension = "pdo_mysql.so"
# mysql -u root -p
mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;