CentOS版本: centos-x64 2.6.32-279.el6.x86_64
nagios版本:Nagios Core 3.4.2
Cacti版本: cacti-0.8.8a
Ntop:ntop-5.0.1
pnp:pnp4nagios-0.6.19
一、配置yum, 更换为163的源
1. 首先备份/etc/yum.repos.d/CentOS-Base.repo
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
#http://mirrors.163.com/.help/CentOS6-Base-163.repo
3. 修改repo文件名称
#mv /etc/yum.repos.d/CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
4. 运行yum makecache生成缓存
5. 安装rpmforge
#rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
二、安装包及相关软件
1. 每个人机器的环境不一样,我是用最小安装模式安装的centos,需要安装以上的包,如果还安装过程中提示缺少依赖包,请自行安装吧。
yum install httpd -y
yum install php php-mysql php-snmp php-gd -y
yum install mysql mysql-server mysql-devel -y
yum install net-snmp-utils -y
yum install rrdtool* -y
yum install gcc* -y
yum install gd gd-devel -y
yum install glibc* -y
yum install make.x86_64 automake -y
yum install openssl* -y
yum install perl-devel -y
yum install GeoIP GeoIP-devel -y
yum install ettercap -y
yum install libpcap libpcap-devel -y
yum install gdbm gdbm-devel -y
yum install python python-libspython-devel -y
yum install wget -y
yum install automake* -y
yum install libtool -y
yum install subversion -y
yum install libdbi libdbi-devel -y
yum install libdbi-dbd-mysql –y
2. 配置apache
#vi/etc/httpd/conf/httpd.conf,确保有“LoadModule status_module modules/mod_status.so”这行并没有被注释,标示已经支持检测模块,然后启动apache:
#servicehttpd start
#chkconfig --level 35 httpd on 开机启动
3. 配置php
#vi/var/www/html/index.php
<?php
phpinfo();
?>
访问http://localhost,验证php能够正常工作
4. 配置mysql
#servicemysqld start 启动mysql
#chkconfig--level 35 mysqld on 设置mysql开机启动
#mysqladmin-u root password 'password' 设置root账号登陆密码
#mysql-u root -p 使用root账号登陆
mysql>create database cactidb; 创建数据库cactidb,并创建管理账号cactier
mysql>GRANT all Privileges ON cactidb.* TO cactier@localhost IDENTIFIED BY 'password';
mysql>GRANT all Privileges ON cactidb.* TO [email protected] IDENTIFIED BY 'password';
mysql>flush privileges; 更新权限设置
创建mysql.php验证mysql数据库连接
<?php
$link=mysql_connect("localhost","root","password");
if(!$link) echo"FAILD!";
else echo "OK!";
?>
页面显示OK!表示连接正常。
5. 配置SNMP
#vi/etc/snmp/snmpd.conf 编辑SNMP的配置文件,其中修改一下几行
# First, map the community name "public"into a "security name"
# sec.name source community
41 com2sec notConfigUser default public#默认的密码为“public”, 可以改为需要的密码
62 access notConfigGroup "" any noauth exact all none none
85 view all included .1 80
#service snmpd start 启动SNMP服务
#chkconfig--level 35 snmpd on 设置snmp服务开机启动
三、安装nagios
1. 设置nagios用户和组
#/usr/sbin/useradd-m nagios
#passwdnagios
#/usr/sbin/groupaddnagios
#/usr/sbin/usermod-a -G nagios nagios
2. 安装配置nagios
#tarzxf nagios-3.4.2.tar.gz
#cd nagios
#./configure --with-gd-lib=/usr/lib64 --with-gd-inc=/usr/include --with-command-group=nagios--with-httpd-conf=/etc/httpd/conf/
#makeall
#makeinstall
#makeinstall-init
#makeinstall-config
#makeinstall-commandmode
#makeinstall-webconf
#vi/usr/local/nagios/etc/objects/contacts.cfg
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
vi/etc/httpd/conf/httpd.conf
添加:
#nagios default settings
Include /etc/httpd/conf/nagios.conf
#service httpd restart
访问http://IP/nagios
3. 安装nagios-plugins
#tar zxf nagios-plugins-1.4.16.tar.gz
#cd nagios-plugins-1.4.16
#./configure--with-nagios-user=nagios --with-nagios-group=nagios
#make
#makeinstall
4. 安装 nagios-snmp
#tar zxf CPAN-1.9800.tar.gz
#cd CPAN-1.9800
#perl Makefile.PL
#make
#make install
#yuminstall perl-Time-HiRes -y
#perl -MCPAN -e shell (ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN )
cpan>installNet::SNMP
#tar zxf nagios-snmp-plugins.1.1.1.tgz
#cd nagios_plugins
#chkconfig --add nagios
#chkconfig nagios on
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
#chcon -R -t httpd_sys_content_t /usr/local/nagios/share
#servicenagios start
四、安装cacti
1. 安装
#tar zxvf /root/cacti-0.8.8a.tar.gz
#mv /root/cacti-0.8.8a /usr/local/cacti
#mysql -u root -p cactidb < /usr/local/cacti/cacti.sql
#vi/usr/local/cacti/include/config.php
$database_type = "mysql";
$database_default ="cactidb";
$database_hostname ="localhost";
$database_username ="cactier";
$database_password ="password";
$database_port = "3306";
$database_ssl = false;
#adduser -s /sbin/nologin cactier
#cd /usr/local/cacti
#chown -R cactier rra/ log/
#vi/etc/crontab
*/5* * * * cactier php /usr/local/cacti/poller.php > /dev/null &
#vi /etc/httpd/conf/cacti.conf
Alias /cacti "/usr/local/cacti"
<Directory"/usr/local/cacti">
OptionsFollowSymLinks MultiViews
AllowOverrideNone
Orderallow,deny
Allowfrom all
</Directory>
2. 配置
#/usr/bin/php -q /usr/local/cacti/poller.php --force --debug
验证php是否有错误,如有:PHP Warning: strtotime()或PHPWarning: date()的警告信息,则 vi/etc/php.ini,修改“;date.timezone=”为“date.timezone= PRC”,然后重启httpd服务。
打开http://IP/cacti/install 进行cacti的安装
五、安装ntop
#useradd -M -s /sbin/nologin -r ntop
#tarzxvf ntop-5.0.1.tar.gz
#cd ntop-5.0.1
#./autogen.sh
#make
#makeinstall
#chown-R ntop.ntop /usr/local/share/ntop
#chown-R ntop:root /usr/local/share/ntop
#ntop -A
#ntop -i eth0 -d -L -u ntop
#echo 'ntop -i eth0 -d -L -u ntop &> /dev/null' >>/etc/rc.d/rc.local
访问http://IP:3000
六、整合cacti和ntop
#tar zxvf ntop-v0.2-1.tgz
#mv ntop /usr/local/cacti/plugins/
#vi/usr/local/cacti/include/config.php
添加“$plugins[] = 'ntop';”
七、整合cacti和nagios
1. 安装ndoutils
#tar zxf ndoutils-1.5.2.tar.gz
#cd ndoutils-1.5.2
#./configure --with-mysql-lib=/usr/lib64/mysql
#make
#cd /root/ndoutils-1.5.2/db
#./installdb -ucactier -p 123#abc -h localhost -d cactidb
#cd /root/ndoutils-1.5.2/src
cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bin
#cp -v ndomod-3x.o /usr/local/nagios/bin/
#mv/usr/local/nagios/bin/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
#cp -v ndo2db-3x /usr/local/nagios/bin/
#mv/usr/local/nagios/bin/ndo2db-3x /usr/local/nagios/bin/ndo2db
#cp -v file2sock /usr/local/nagios/bin/
#cp -v log2ndo /usr/local/nagios/bin/
#cd /root/ndoutils-1.5.2/config
#cp -v ndo2db.cfg-sample /usr/local/nagios/etc/
#mv/usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
#cp -v ndomod.cfg-sample /usr/local/nagios/etc/
#mv/usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
#chmod 644 /usr/local/nagios/etc/ndo*
#chown nagios:nagios /usr/local/nagios/etc/*
#chown nagios:nagios /usr/local/nagios/bin/*
#vi /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg # 在文件中添加:
event_broker_options=-1# 检查
#vi/usr/local/nagios/etc/ndo2db.cfg
socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cactidb
db_prefix=npc_
db_user=cactier
db_pass=password
#/usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
为ndo2db添加启动进程
#cp ./daemon-init /etc/init.d/ndo2db
#vi /etc/init.d/ndo2db
# 检查里面的路径确保不会出现“//",并将Ndo2dbBin修改成下面的值:
Ndo2dbBin=/usr/local/nagios/bin/ndo2db
#chmod +x /etc/init.d/ndo2db
#servicendo2db start
#tail-20 /var/log/messages ## 查看其中是否有错误出现。如无报错请继续
#/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg 检查nagios配置没有问题
#service nagios restart
2. 安装npc
#tar zxf /root/npc-2.0.4.tar.gz
#mv /root/npc/ /usr/local/cacti/plugins/
#vi /usr/local/cacti/include/config.php
添加 $plugins[] = 'npc';
3. 为apche添加php支持
#vi /etc/httpd/conf/httpd.conf
# 添加一行:
AddType application/x-httpd-php .php .phtml
# 修改原DirectoryIndex内容为:
DirectoryIndex index.html index.html.var index.php
#usermod -G cactier apache
#service httpd restart ## 重启apache以让php生效
#php -m ## 查看是否有json被加载
4. 修改mysql中的表结构:
use cactidb;
alter table npc_eventhandlers addlong_output TEXT NOT NULL default '' after output;
alter table npc_eventhandlers add long_outputTEXT NOT NULL default '' after output;
alter table npc_hostchecks add long_outputTEXT NOT NULL default '' after output;
alter table npc_hoststatus add long_outputTEXT NOT NULL default '' after output;
alter table npc_notifications add long_outputTEXT NOT NULL default '' after output;
alter table npc_servicechecks addlong_output TEXT NOT NULL default '' after output;
alter table npc_servicestatus addlong_output TEXT NOT NULL default '' after output;
alter table npc_statehistory add long_outputTEXT NOT NULL default '' after output;
alter table npc_systemcommands addlong_output TEXT NOT NULL default '' after output;
#service ndo2db restart
#service nagios restart
八、安装pnp4nagios
1. 安装pnp
#tar pnp4nagios-0.6.19.tar.gz
#cdpnp4nagios-0.6.19
# ./configure --with-nagios-user=nagios--with-nagios-group=nagios
#make all
#make install
#make install-webconf
#make install-config
#make install-init
部署配置文件
#chown –R nagios.nagios /usr/local/pnp4nagios
#su - nagios
$cd /usr/local/pnp4nagios/etc
$mv misccommands.cfg-sample misccommands.cfg
$mv nagios.cfg-sample nagios.cfg
$mv process_perfdata.cfg-sample process_perfdata.cfg
$mv rra.cfg-sample rra.cfg
$cd /usr/local/pnp4nagios/etc/pages
$mv web_traffic.cfg-sample web_traffic.cfg
$cd /usr/local/pnp4nagios/etc/check_commands
$mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
$mv check_nrpe.cfg-sample check_nrpe.cfg
$mv check_nwstat.cfg-sample check_nwstat.cfg
设置npcd开机启动
#chkconfig–add /etc/init.d/npcd
启动npcd
#service npcd start
2. 修改nagios配置文件
配置nagios.cfg,修改:
#vi/usr/local/nagios/etc/nagios.cfg
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
配置commands.cfg,修改:
#vi /usr/local/nagios/etc/objects/etc/objects/commands.cfg
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata'command definition
define command{
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
配置templates.cfg,添加:
#vi/usr/local/nagios/etc/objects/etc/objects/templates.cfg
# Pnp4nagios host definition template
define host {
name host-pnp
action_url/pnp4nagios/graph?host=$HOSTNAME$
register 0
}
# Pnp4nagioshost definition template
define service {
name srv-pnp
action_url/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
配置主机监控文件:
#vi/usr/local/nagios/etc/objects/etc/objects/192.168.8.80-NSClient.cfg
define service{
use generic-service,srv-pnp
host_name 192.168.8.80-NSClient
service_description check_ping
check_command check_ping!100.0,20%!500.0,60%
}
3. 重启服务
#/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg 检查nagios配置
#service nagios restart 没有错误重启nagios服务
#service npcd restart 重启npcd服务