在CentOs linux 6.0 x86_64 server上安装实现cacti+nagios+ntop整合+nagiosql图形界面管理nagios配置文件
一、软件环境
OS:CentOS6.0 x86_64
cacti-0.8.8b
nagios-3.5.0
nagios-plugins-2.0
ndoutils-1.4b9
settings-v0.71-1
thold-v0.4.9-3
npc-2.4
ntop-5.0-5
sendEmail-v1.55
二、软件下载及安装
1、下载源码
cd /usr/local/src/cacti
wget http://www.nmon.net/packages/rpm/x86_64/ntop/ntop-5.0-5.el6.x86_64.rpmhistory
wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/hiredis-0.10.1-3.el6.x86_64.rpm
pfring-5.5.3-6099.x86_64.rpm
wget http://cznic.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
wget http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.1.1/nagiosql_311.tar.gz/download
wget http://www.cactifans.org/plugins/npc.tar.gz
wget wget http://docs.cacti.net/_media/plugin:ntop-v0.2-1.tgz
wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz
wget http://docs.cacti.net/_media/userplugin:timeshift-0.1.1.zip
wget http://docs.cacti.net/_media/plugin:clog-v1.7-1.tgz
wget http://docs.cacti.net/_media/plugin:thold-v0.4.9-3.tgz
wget http://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz
wget http://www.cpan.org/authors/id/J/JV/JV/Getopt-Long-2.40.tar.gz
wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
wget http://cznic.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
2、yum安装必要的软件包:
yum -y install httpd php php-mysql mysql mysql-server mysql-devel php-snmp net-snmp-utils rrdtool rrdtool-devel rrdtool-php
service mysqld start
chkconfig mysqld on
service httpd start
chkconfig httpd on
修改mysql root密码:
mysqladmin -uroot password '123456'
3、安装cacti:
由于一些包在官方的库中没有,因此我们要建立dag.repo,定义非官方库
vi /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
导入非官方库的GPG:rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
安装cacti需要的环境包
yum -y install php-devel php-common net-snmp net-snmp-utils \
zlib libpng freetype libjpeg fontconfig gd libxml2 patch wget rrdtool xinetd \
gd gd-devel openssl-devel
cd /usr/local/src/cacti
tar zxvf cacti-0.8.8b.tar.gz
cp cacti-0.8.8b/* /var/www/html -R
chown -R apache:apache /var/www/html/
启动mysql为cacti创建数据库和用户
service mysqld start
mysql -uroot -p
Enter password:
#密码为空
mysql> create database cacti;
mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti123';
mysql> flush privileges;
导入cacti的数据库:
mysql -ucacti -pcacti123 cacti < /var/www/html/cacti.sql
修改cacti的配置文件并保存
vi /var/www/html/include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti123";
$database_port = "3306";
vi /var/www/html/include/global.php
/* Default database settings*/
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti123";
$database_port = "3306";
$database_ssl = false;
设置crontab定时任务:
chkconfig snmpd on
chkconfig httpd on
chkconfig mysqld on
chkconfig crond on
service httpd restart
service snmpd restart
service mysqld restart
service crond restart
web页完成安装
http://xxx.xxx.xxx.xxx
Next >> Next >> Finish
用户名和密码为:admin/admin,之后输入新的密码,就完成了最基本的安装。
开启插件管理:在cacti 页面点console�C>User Management->admin->在Plugin Management上打钩->Save
sed -i 's/^;date.timezone =/date.timezone =PRC/g' /etc/php.ini
service httpd restart
crontab -e #增加如下计划任务
*/5 * * * * php /var/www/html/poller.php > /dev/null 2>&1
4、安装nagios
useradd nagios
groupadd nagcmd
tar zxvf nagios-3.5.0.tar.gz
cd nagios
./configure --with-command-group=nagcmd --with-gd-lib=/usr/lib
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
service httpd restart
chkconfig nagios on
usermod -G nagcmd apache
tar zxvf nagios-plugins-2.0.tar.gz
cd nagios-plugins-2.0
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
tar zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
########################################################################
make install-daemon
make install-daemon-config
make install-xinetd
sed -i 's/127.0.0.1/127.0.0.1 192.168.1.13/g' /etc/xinetd.d/nrpe
echo "nrpe 5666/tcp # nrpe" >> /etc/services
service xinetd restart
chkconfig xinetd on
########################################################################
5、安装ndoutils
tar zxvf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9
echo "/usr/lib64/mysql" >>/etc/ld.so.conf
ldconfig
./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql
make
cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin/
cd db
./installdb -ucacti -pcacti123 -hlocalhost -d cacti
cd ..
cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /usr/local/nagios/etc/
mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
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/*
修改nagios.cfg
sed -i 's?^#broker_module=/somewhere/module1.o?broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg?g' /usr/local/nagios/etc/nagios.cfg
修改ndo2db.cfg
sed -i 's/socket_type=unix/socket_type=tcp/g' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's/db_name=nagios/db_name=cacti/g' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's/db_user=ndouser/db_user=cacti/g' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's/db_pass=ndopassword/db_pass=cacti123/g' /usr/local/nagios/etc/ndo2db.cfg
修改ndomod.cfg
sed -i 's/output_type=unixsocket/output_type=tcpsocket/g' /usr/local/nagios/etc/ndomod.cfg
sed -i 's?output=/usr/local/nagios/var/ndo.sock?output=127.0.0.1?g' /usr/local/nagios/etc/ndomod.cfg
为ndo2db添加启动进程:
cp ./daemon-init /etc/init.d/ndo2db
sed -i 's?Ndo2dbBin=/usr/local/nagios/bin/ndo2db?Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x?g' /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
启动守护进程与nagios
service ndo2db start
tail -f /var/log/messages #检查是否有报错信息
service nagios restart
6、安装npc
tar zxvf npc.tar.gz -C /var/www/html/plugins
chown apache.apache /var/www/html/plugins/npc -R
然后进入cacti,点Console�CPlugin Management�C>安装并启用npc插件
接着在右侧栏目中选择settings,点选npc的标签
钩选Remote Commands
Nagios Command File Path: /usr/local/nagios/var/rw/nagios.cmd
Nagios URL:]http://yourserver/nagios/
保存就可以了。
mysql -ucacti -pcacti123
use cacti;
ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
7、安装ntop
rpm -ivh hiredis-0.10.1-3.el6.x86_64.rpm
yum -y install kernel-uname-r
信息:
Installing:
kernel x86_64 2.6.32-358.2.1.el6 updates 26 M
Updating:
bfa-firmware noarch 3.0.3.1-1.el6 base 723 k
Updating for dependencies:
kernel-firmware
rpm -ivh pfring-5.5.3-6099.x86_64.rpm
yum -y install geoip geoip-devel
rpm -ivh ntop-5.0.2-2.el6.x86_64.rpm
ntop -A --set-admin-password=123456
echo 'ntop -i eth0 -d -L -u ntop &> /dev/null' >> /etc/rc.d/rc.local
启动ntop
ntop -i eth0 -d -L -u ntop &> /dev/null
整合ntop到cacti
tar zxvf ntop-v0.2-1.tgz -C /var/www/html/plugins
chown apache.apache /var/www/html/plugins/ntop -R
然后进入cacti,点Console�CPlugin Management�C>安装并启用ntop插件
在cacti 页面点console�C>User Management->admin->在View NTop上打钩->Save
8、安装nagiosql
cd /usr/local/src/cacti
tar zxvf nagiosql_311.tar.gz -C /usr/local
chown apache.nagios -R /usr/local/nagiosql
mkdir -p /usr/local/nagios/etc/nagiosql/{hosts,services,backup/{hosts,services},import}
chown -R apache:nagios /usr/local/nagios/etc/nagiosql/
chmod -R 755 /usr/local/nagios/etc/nagiosql
cat >>/etc/httpd/conf.d/nagiosql.conf <<eof
Alias /nagiosql "/usr/local/nagiosql"
<Directory "/usr/local/nagiosql">
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
eof
重启apache
service httpd restart
访问http://ip/nagiosql进行安装
右上角选择语言为中文简体,点开始安装-->如果环境测试成功通过,可点下一步继续-->下一步-->登录服务器命令行执行删除
/usr/local/nagiosql/install目录后,点完成-->出现NagiosQL欢迎界面,安装成功-->用刚才设置的密码登录nagiosql可以
看到nagiosql管理界面进行管理。
cd /usr/local/nagios/etc
chown nagios.nagcmd nagios.cfg
chown nagios.nagcmd cgi.cfg
chown nagios.nagcmd resource.cfg
chown nagios.nagcmd /usr/local/nagios/var -R
在 /usr/local/nagios/etc/nagios.cfg中添加:
cat >>/usr/local/nagios/etc/nagios.cfg<<eof
cfg_dir=/usr/local/nagios/etc/nagiosql/services
cfg_dir=/usr/local/nagios/etc/nagiosql/hosts
eof
修改cfg_file到自己定义的目录
sed -i 's/^cfg_file/#cfg_file/g' /usr/local/nagios/etc/nagios.cfg
cat >>/usr/local/nagios/etc/nagios.cfg<<eof
cfg_file=/usr/local/nagios/etc/nagiosql/commands.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contacts.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/contacttemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/hosttemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/servicegroups.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/servicetemplates.cfg
cfg_file=/usr/local/nagios/etc/nagiosql/timeperiods.cfg
eof
导入配置文件:
(1)通过手工编辑的配置文件导入方法:
拷贝老的备份文件到 /usr/local/nagios/etc/nagiosql/import/ 目录
登录http://ip/nagiosql -->管理-->域-->localhost点修改-->修改为自己的目录后点保存,应该显示数据成功写入数据库。-->
工具-->导入数据,选择要导入的配置文件,点导入按钮-->nagios控制-->写入检测数据-->写入其他数据-->检查配置文件-->检查通过后,重新启动Nagios-->结束
(2)通过nagiosql生成的配置文件导入方法:
如果是导入以前的nagiosql管理的配置文件,可以备份以前的nagiosql的数据库(默认数据库名是db_nagiosql_v3),然后覆盖新nagiosql的数据,在登录web管理页面
执行工具-->导入数据,选择要导入的配置文件,点导入按钮-->nagios控制-->写入检测数据-->写入其他数据-->检查配置文件-->检查通过后,重新启动Nagios-->结束
9、安装完成的效果图:
(1)cacti绘出的图像:
(2)nagios图像:
3、nagios绘出的拓扑图:
4、ntop图:
5、nagiosql图: