nagios+cacti整合
系统:CentOS -6.5-x86_64软件环境:apr-1.5.0.tar.gz apr-util-1.5.3.tar.gz httpd-2.4.7.tar.gz pcre-8.33.tar.gz mysql-5.6.10.tar.gz mhash-0.9.9.9.tar.gz libmcrypt-2.5.6.tar.gz zlib-1.2.5.1.tar.gz libpng-1.2.47.tar.xz jpeg-6b.tar.gz freetype-2.3.11.tar.bz2 gd-2.1.0.tar.gz php-5.5.13.tar.gz nagios-3.4.3.tar.gznagios-plugins-1.4.16.gznrpe-2.14.tar.gz sendEmail-v1.56.tar.gz rrdtool* net-snmp* cacti-0.8.8b.tar.gz cacti-spine-0.8.8b.tar.gz settings-v0.7-1.tgz monitor-v1.3-1.tgz thold-v0.5.0.tgz ntop-4.0.1.tar.gz ntop-v0.2-1.tgz npc-2.0.4.tar.gz json-1.2.1.tgz ndoutils-1.5.2.tar.gz GeoIP.tar.gz
Yum安装的软件
perl-GD perl-DBI perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utilsperl-Socket6 perl-IO-Socket-INET6 net-snmp-devel dmidecode net-snmp-perlperl-Crypt-DES fping perl-Config-IniFiles graphviz
监控主机ip:192.168.1.124
被监控机ip:192.168.1.43 192.168.1.212
一、搭建lamp环境
1.安装apache。
安装前准备:# yum install -y gcc gcc-c++ gcc-devel cmake
安装apr
# tar xvf apr-1.5.0.tar.gz
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make &&make install
安装apr-util
# tar xvf apr-util-1.5.3.tar.gz
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make &&make install
安装pcre
# tar xvf pcre-8.33.tar.gz
# cd pcre-8.33
# ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
# make && make install
安装apache
# tar xvf httpd-2.4.7.tar.gz
# ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite
# make && make install
启动apache
# cd /usr/local/httpd/bin/
# ./apachectl start
查看端口监听
# netstat -antl|grep 80
2.安装mysql
解压,编译安装mysql
# tar xf mysql-5.6.10.tar.gz
# cd mysql-5.6.10
# cmake-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql-DMYSQL_DATADIR:PATH=/database -DWITH_DEBUG:BOOL=on -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_INNOBASE_STORAGE_ENGINE:BOOL=on -DWITH_PARTITION_STORAGE_ENGINE:BOOL=on
出错1:
# yuminstall -yncurses-devel
# rm CMakeCache.txt
然后重新编译
# make && make install
新建mysql用户及相关目录,并更改属组和属主创建
# mkdir /database
# mkdir /usr/local/mysql/var/log -p
# mkdir /usr/local/mysql/var/run
# mkdir /usr/local/mysql/etc
# mkdir /usr/local/mysql/binlog
# useradd mysql
# chown -R mysql:mysql /database /usr/local/mysql/
修改配置文件
# cp support-files/my-default.cnf /usr/local/mysql/etc/my.cnf
# vim /usr/local/mysql/etc/my.cnf
添加如下内容:
basedir=/usr/local/mysql
datadir=/database
socket=/usr/local/mysql/var/run/mysql.sock
pid-file=/usr/local/mysql/var/run/mysql.pid
log-bin=/usr/local/mysql/binlog/mysqlbin-log
port=3306
user=mysql
log-error=/usr/local/mysql/var/log/mysql.log
socket=/usr/local/mysql/var/run/mysql.sock
初始化mysql数据库
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/database --user=mysql
添加mysql自启动
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql5.6d
# chkconfig --add mysql5.6d
# chkconfig mysql5.6d on
# service mysql5.6d start
Starting MySQL...
[root@localhost mysql-5.6
修改root密码:
# /usr/local/mysql/bin/mysql –uroot
mysql> use mysql
mysql> update user set password=password('123654') where user='root';
# /usr/local/mysql/bin/mysql -uroot -p123654
3.安装php
安装mhash
# tar jxvf mhash-0.9.9.9.tar.bz2
# cd mhash-0.9.9.9
# ./configure
# make &&make install
安装libmcrypt
# tar xf libmcrypt-2.5.6.tar.gz
# cd libmcrypt-2.5.6
# ./configure
#make
#make install
安装zlib,装两次,一次指定路径,一次不指定,64位系统安装库编译的时候要在前面加上CFLAGS="-O3 -fPIC"
# tar xf zlib-1.2.5.1.tar.gz
# cd zlib-1.2.5.1
# CFLAGS="-O3 -fPIC"./configure
# make && make install
#CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/zlib
# make && make install
安装libpng
# tar xf libpng-1.2.47.tar.xz
# cd libpng-1.2.47
# CFLAGS="-O3 -fPIC"./configure --prefix=/usr/local/libpng
安装jpeg
# tar xf jpeg-6b.tar.gz
# cd jpeg/src/
# cp /usr/share/libtool/config/config.guess config.guess
cp: overwrite `config.guess'? y
# cp /usr/share/libtool/config/config.sub config.sub
cp: overwrite `config.sub'? y
# CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
# make && make install
错误2:
# mkdir -p /usr/local/jpeg/bin
# mkdir -p /usr/local/jpeg/lib
# mkdir -p /usr/local/jpeg/include
# mkdir -p /usr/local/jpeg/man
# mkdir -p /usr/local/jpeg/man/man1
安装freetype
# tar jxvf freetype-2.3.11.tar.bz2
# cd freetype-2.3.11
# ./configure --prefix=/usr/local/freetype --enable-shared
# make && make install
安装gd
# tar xf gd-2.0.35.tar.gz
# cd gd/2.0.35/
# ./configure --prefix=/usr/local/gd--with-jpeg=/usrl/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
# make && make install
出现错误3:
# sed -i 's#png.h#/usr/local/libpng/include/png.h#' gd_png.c
安装php
# yum install libxml2* -y
# tar xf php-5.5.13.tar.gz
# cd php-5.5.13
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=mysqlnd --with-apxs2=/usr/local/httpd/bin/apxs --with-libxml-dir=/usr/include/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-gd=/usr/local/gd --with-zlib-dir=/usr/local/zlib --with-mysqli=mysqlnd --with-mcrypt=/usr/local/lib/libmcrypt--enable-soap --enable-mbstring=all --enable-sockets --enable-bcmath
错误4:
版本太低,换了最高版本的libgd-2.1.0.tar.gz
#cd /soft/gd/2.0.35
#make clean
#rm –rf /usr/local/gd
下载libgd-2.1.0.tar.gz
#tar xf libgd-2.1.0.tar.gz
# cd libgd-2.1.0
# ./configure --prefix=/usr/local/gd--with-jpeg=/usrl/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
# make && make install
再重新编译php,已经没错误了
# make
错误5:
# yum install libXpm-devel –y
# make
# make test
# make install
安装pdo_mysql模块
# cd ext/pdo_mysql/
# /usr/local/php/bin/phpize
# mkdir ext/pdo/tests -p
# ./configure --with-php-config=/usr/local/php/bin/php-config--with-pdo-mysql=/usr/local/mysql
# make
# make test
# make install
# cp php.ini-development /usr/local/php/etc/php.ini
# echo 'extension_dir=”/usr/local/php/lib/php/extensions/no-debug-zts-20121212/”' >>/usr/local/php/etc/php.ini
# echo 'extension=”pdo_mysql.so”' >>/usr/local/php/etc/php.ini
查看模块是否被加载
# /usr/local/php/bin/php-m |grep pdo_mysql
pdo_mysql
让apache支持php
# vim /usr/local/httpd/conf/httpd.conf
增加
AddType application/x-httpd-php .php
找到这一段,加入index.php
DirectoryIndex index.html index.php
重启apache
在htdocs下面写一个test.php做测试看是否支持php
# vim ../htdocs/test.php
测试php能否连接数据库
# vim ../htdocs/con.php
二、监控机安装nagios和nagios-plugins以及nrpe
#yum install perl-GD perl-DBI perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utilsperl-Socket6 perl-IO-Socket-INET6 net-snmp-devel dmidecode net-snmp-perlperl-Crypt-DES fping perl-Config-IniFiles graphviz –y
Nagios监控原理:
Nagios 通过NRPE 来远端管理服务
1. Nagios 执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。
2. 通过SSL,check_nrpe 连接远端机子上的NRPE daemon
3. NRPE 运行本地的各种插件去检测本地的服务和状态(check_disk,..etc)
4. 最后,NRPE 把检测的结果传给主机端的check_nrpe,check_nrpe 再把结果送到Nagios状态队列中。
5. Nagios 依次读取队列中的信息,再把结果显示出来。
参考:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html
创建nagios用户
# useradd -s /sbin/nologin nagios
# mkdir -p /usr/local/nagios
# chown -R nagios:nagios /usr/local/nagios
解压,编译安装
# tar xvf nagios-3.4.3.tar.gz
# cd nagios
# ./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/gd/lib--with-gd-inc=/usr/local/gd/include
# make all
# make install
#make install-init
#make install-commandmode
#make install-config
编译安装nagios插件
# tar xvf nagios-plugins-1.4.16.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios/
# make && make install
编译安装nrpe
# tar xf nrpe-2.14.tar.gz
# cd nrpe-2.14
# ./configure
# make all
# make install-plugin
配置apache和nagios
# vim /usr/local/httpd/conf/httpd.conf添加
#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
Alias /nagios /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
保存,创建admin用户,用于登陆nagios,此文档中设置的密码是123654
# /usr/local/httpd/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin
New password:
Re-type new password:
Adding password for user admin
修改cgi配置文件
修改nagios的cgi配置文件,给admin用户权限
# sed -i 's/nagiosadmin/admin/g' /usr/local/nagios/etc/cgi.cfg---》这是我直接改用户的方法。也可以使用下面这种方法:
# vim /usr/local/nagios/etc/cgi.cfg
authorized_for_system_information=admin
authorized_for_configuration_information=admin
authorized_for_system_commands=admin
authorized_for_all_services=admin
authorized_for_all_hosts=admin
authorized_for_all_service_commands=admin
authorized_for_all_host_commands=admin
确保以上参数值为:admin
重启apache
# cd /usr/local/httpd/bin/
# ./apachectl restart
访问nagios:http://192.168.1.124/nagios,输入刚才设置的用户名:admin密码:123654,出现nagios的主页面。
到这里会出现在ie浏览器点击service或者hosts会出现乱码,原因是Apache没开启cgi模块。修改apache配置文件
# vim ../conf/httpd.conf将以下两句注释去掉,重启apache
LoadModule cgid_module modules/mod_cgid.so
LoadModule actions_module modules/mod_actions.so
三、linux被监控机安装nagios插件、nrpe
被监控主机需要安装nagios插件,以及nrpe
装nagios插件
# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios
# tar xf nagios-plugins-1.4.16.gz
# cd nagios-plugins-1.4.16
# ./configure--prefix=/usr/local/nagios/
#make && make install
安装nrpe
# ./configure
# make all
# make instlal-plugin
# make install-daemon
#make install-daemon-config
# chown-Rnagios.nagios/usr/local/nagios
# vim /usr/local/nagios/etc/nrpe.cfg
找到这句加上监控机的ip
allowed_hosts=127.0.0.1,192.168.1.124
启动nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
查看监听端口:
# netstat -antl|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:*
确保防火墙跟selinux都是关闭的
检测自己的nrpe是否成功
# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.15
到监控机去检测npre能否正常通信:
# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.43
NRPE v2.14
③配置snmp
com2sec notConfigUser192.168.1.124(监控主机的ip) public
view all included.1 80
accessnotConfigGroup "" any noauth exactall none none
重启snmp服务
# service snmpd restart
四、配置nagios
先看看etc下面有哪些文件
其中nagios.cfg是主配置文件,这下面有个objects的目录,这个目录下面的配置文件是定义监控的
其中templates.cfg里面有很多模板,我们在自定义监控的时候可以引用此文件中的模板。现在我们来定义监控。
在objects的目录下我们可以看到localhost.cfg这个配置文件,打开可以看到里面已经定义了对本机的监控,所以不用对本机做定义,打开nagios网页http://192.168.1.124/nagios然后点击services可以看到如下图的监控信息。
在监控主机定义监控
# cd /usr/local/nagios/etc/objects/,创建hosts.cfg自定义监控配置文件此文件用来定义被监控主机的名字和ip
# vim hosts.cfg
define host{
use linux-server
host_namelinux-43
alias test
address192.168.1.43
}
解释这段的意思
use linux-server 这句是引用template里面的linux-server,指被监控的是linux主机
host_name linux-43 这句是给被监控主机的机器名,随便取
aliastest 被监控主机别名,也随便取
address192.168.1.43 被监控主机的ip
定义了主机之后,现在来定义主机组,在当前路径下又新建hostgroups.cfg
# vim hostgroups.cfg
define hostgroup{
hostgroup_name zj-servers
alias zj-servers
members linux-43
}
解释这段的意思
hostgooup_name zj-server意思是主机组的名字
alias zj-server 意思是主机组的别名
members linux-43 意思是这组的成员,多个成员用逗号隔开,这些成员必须是在hosts.cfg定义的。
接下来定义服务,在当前路径新建services.cfg
# vim services.cfg
define service{
use local-service
host_name linux-43
service_description check-host-alive
check_command check-host-alive
}
解释这段的意思:
use local-service 这句也是引用template.cfg中的local-service意思是监控的服务
host_name linux-43 这句的意思是监控的是linux-43这个主机的服务
service_description check-host-alive这句的意思服务的描述,即检查主机的存活
check_command check-host-alive这句的意思是使用什么命令去检查,这里是使用check-host-alive,这个命令必须在commands.cfg有定义,打开comands.cfg可以看到定义此命令的这一段。
修改nagios主配置文件
# vim ../nagios.cfg
增加三行,刚才自定义的文件,都要在主配置文件指定他们的路径
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
重启nagios,到网页上去看http://192.168.1.124/nagios
先检测配置文件有无错误
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启
# service nagios restart
打开网站,点击hosts可以看到linux-43,刚才我们自定义的主机已经监控起来了
我们可以对同一个主机监控多个服务,下面来利用nrpe插件对远程主机监控
check_nrpe的用法:
check_nrpe –H 被监控的主机 -c 要执行的监控命令
注意:-c 后面接的监控命令必须是nrpe.cfg 文件中定义的。也就是NRPE daemon只运行nrpe.cfg中所定义的命令。而且在nrpe.cfg定义的命令在这个路径(/usr/local/nagios/libexec/)下面必须有这个命令才能定义。这个nrpe.cfg是在被监控机定义,从nagios的监控原理可以知道,是在被监控端执行检测命令,得到结果再发送给监控主机的nrpe插件。
举例,现在我们要监控远程主机的负载,是用check_load这个命令去检测的。所以首先查看被监控机(192.168.1.43)的nrpe.cfg文件是否有定义这个命令,有则不定义。
查看修改nrpe.cfg
从上图中,可看到check_load已经被定义了,再看看在监控主机这边是怎么远程使用这个命令的。
修改dont_blame_nrpe=0为dont_blame_nrpe=1,意思是允许带参数,然后重启nrpe。
先找出nrpe进程,然后kill掉,然后再启动。
# ps -ef |grep nrpe
nagios 19527 10 13:26 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
# kill -9 19527
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg-d
Check_nrpe的解释
在使用check_nrpe之前首先要检查commands.cfg文件有没有定义这个命令,没有则需要自定义。经查找是没有定义check_nrpe的,所以在此我们要先定义check_nrpe,如下图定义。
-c 后面带的$ARG1$ 参数是传给nrpe daemon 执行的检测命令,之前说过了它必须是nrpe.cfg 中所定义的那些命令中的其中一条。在services.cfg 中使用check_nrpe 的时候要用 “!” 带上这个参数。
现在我们可以在services.cfg去定义这个命令去检查了。
# vim services.cfg
增加这一段
define service{
use local-service
host_name linux-43
service_description current load
check_command check_nrpe!check_load
}
最后一行check_nrpe就是commands.cfg里定义的命令,!check_load是用!把check_load这个参数带到被监控机上去执行。
修改了配置文件之后,检查配置文件,并重启,从网页上看是否检查到此信息。
已经添加了,但是还未开始检测状态,要等一会。
看到ok说明监控好了。
五、添加windows监控
在Nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的。其功能类似于check_nrpe。不过还需要搭配另外一个软件NSClient++,它则类似于NRPE。
NSClient与nrpe最大的区别:
· 被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的。当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控。
· NSClient++则不同,被监控机上只安装NSClient,没有任何的插件。当监控主机将监控请求发给NSClient++后,NSClient直接完成监控,所有的监控是由NSClient完成的。
下载NSClient++-0.2.7.zip
下载地址:http://www.nsclient.org/nscp/downloads
解压,打开cmd,进入解压后的目录
安装nsclient并安装系统托盘
打开服务
找到nsclientpp,双击,然后弹出的窗口,点击登录,大上允许服务与桌面的勾,然后点确定。
修改NSClient++-0.2.7下的NSC.ini文件。
将 部分的所有模块前面的注释都去掉,除了CheckWMI.dll 和 RemoteConfiguration.dll 这两个。
在部分设置'password'选项来设置密码,作用是在nagios连接过来时要求提供密码。这一步是可选的,我这里设置为'123654'。
将部分'allowed_hosts'选项的注释去掉,并且加上运行nagios的监控主机的IP。各IP之间以逗号相隔。这个地方是支持子网的,如果写成192.168.1.0/24则表示该子网内的所有机器都可以访问。如果这个地方是空白则表示所有的主机都可以连接上来。
将的'port'选项的注释去掉,这是nsclient的默认端口
启动nsclient服务,并查看监听端口
监控主机开启对windows的监控
修改nagios的主配置文件
# vim ../nagios.cfg
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg找到这行,去掉注释。
修改commands.cfg,找到check_nt那一段,nagios使用check_nt这个去检查windows服务的。将check_nt这一段修改
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123654 -v $ARG1$ $ARG2$
}
修改widows.cfg,找到host这段,将ip修改为要监控的windows主机的ip
define host{
use windows-server; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.1.212 ; IP address of the host
}
重启nagios,去网页上查看windows有没有被监控。
错误六:
出现这个错误是由于操作系统语言的问题
修改counters.defs文件
Description = "chinese"—》这句是修改为chinese
在最后面增加下面一段
Description = "Chinese"
NT4_SystemTotalProcessorTime = "\System\% Total Processor Time"
NT4_SystemSystemUpTime = "\System\System Up Time"
NT4_MemoryCommitLimit = "\Memory\Commit Limit"
NT4_MemoryCommitByte = "\Memory\Committed Bytes"
W2K_SystemTotalProcessorTime = "\Processor(_total)\% Processor Time"
W2K_SystemSystemUpTime = "\System\System Up Time"
W2K_MemoryCommitLimit = "\Memory\Commit Limit"
W2K_MemoryCommitByte = "\Memory\Committed Bytes"
然后重启nsclient
六、nagios添加邮件报警
安装sendEmail
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz下载sendEmail
# tar xf sendEmail-v1.56.tar.gz
# cd sendEmail-v1.56
# ls
CHANGELOGREADMEREADME-BR.txtsendEmailsendEmail.plTODO
# cp sendEmail /usr/local/bin/
此命令的解释:
-f 表示发送者的邮箱
-t 表示接收者的邮箱
(接收邮件和发送邮件,尽量不要用同一个邮箱帐号,容易出错)
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容
用法:
/usr/local/bin/sendEmail -f发件人邮件-t收件人邮件-s smtp.163.com -u "邮件主题" -xu 用户名 -xp 密码 -m 邮件内容
首先在命令行测试一下:
# /usr/local/bin/sendEmail -f 13873356730@163.com-t 603461655@qq.com13873356730@163.com -s smtp.163.com -u "hello" -xu 13873356730@163.com-xp password -m test
看到下面这行信息,说明邮件发送成功。
Aug 06 16:28:05 localhost sendEmail: Email was sent successfully!
① 对nagios添加邮件报警了。
修改配置文件contacts.cfg,修改邮箱,此处为接受报警邮件的邮箱
# vim contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email 603461655@qq.com ;grant all privileges on cacti.* to "cactier"@'localhost' identified by '123654';
mysql> flush privileges;
修改snmp配置文件
# sec.namesource community
com2sec notConfigUserdefault public
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
# group context sec.model sec.level prefix read writenotif
accessnotConfigGroup "" any noauth exactallnonenone
## incl/excl subtree mask
view all included.1 80
开始安装cacti
# tar xf cacti-0.8.8b.tar.gz
# cd cacti-0.8.8b
# mv cacti-0.8.8b /usr/local/httpd/htdocs/cacti
# cd /usr/local/httpd/htdocs/cacti/
# mysql -ucactier-p123654 cacti /dev/null
在网页上访问cacti:http://192.168.1.124/cacti
出现这个错误是默认用了unix-socket去连接。我们把config.php中的host改为127.0.0.1
之后下一步,就到修改密码了
设置好密码123654然后就能进入cacti了
安装spine
# tar xf cacti-spine-0.8.8b.tar.gz
# cd cacti-spine-0.8.8b
# ./configure --prefix=/usr/local/spine --with-mysql=/usr/local/mysql/
# make && make install
# mv /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
# vim /usr/local/spine/etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cactier
DB_Pass 123654
DB_Port 3306
DB_PreG 0
更改轮询器为spine
Setting->poller->poller type 选择 spine ,记得save哦
安装ntop
# tar xf ntop-4.0.1.tar.gz
# cd ntop-4.0.1
# ./autogen.sh
错误七:
# yum install libpcap libpcap-devel –y
# ./autogen.sh
# ./configure --prefix=/usr/local/ntop
# tar xf GeoIP.tar.gz
# cd GeoIP-1.4.8/
# ./configure
# make && make install
进入到ntop的解压路径,重新编译再安装
# make&&make install
给ntop设置密码:
# /usr/local/ntop/bin/ntop –A
# useradd ntop
# chown -R ntop:ntop /usr/local/ntop/share/ntop/
# chown -R ntop:ntop /usr/local/ntop/var/ntop/
# /usr/local/ntop/bin/ntop -u ntop -c –d –》启动ntop
写入开机自启动
# echo "/usr/local/ntop/bin/top-u ntop-c -d" >>/etc/rc.local
安装ntop插件ntop-v0.2-1.tgz
# tar zxvf ntop-v0.2-1.tgz -C /usr/local/httpd/htdocs/cacti/plugins
# vim /usr/local/httpd/htdocs/cacti/include/config.php
$plugins[] = "ntop";
然后登陆cacti网站:console –》plugin managemaent 点击蓝色的箭头,激活ntop
然后点击User management—》admin—》把view ntop勾上,save,然后点击ntop可以看到如下图
安装setting、monitor,thold等插件
# tar xf settings-v0.7-1.tgz-C /usr/local/httpd/htdocs/cacti/plugins
# vim /usr/local/httpd/htdocs/cacti/include/config.php
$plugins[] = "settings";
在cacti网站上激活settings
Console---》plugin managementà点点点就激活了,激活后如下图
其他插件如settings一样的方法。
# tar xf monitor-v1.3-1.tgz -C /usr/local/httpd/htdocs/cacti/plugins
# vim /usr/local/httpd/htdocs/cacti/include/config.php
$plugins[] = "monitor";
# tar xf thold-v0.5.0.tgz -C /usr/local/httpd/htdocs/cacti/plugins
# vim /usr/local/httpd/htdocs/cacti/include/config.php
$plugins[] = "thold";
八、Cacti和nagios整合
①安装ndoutils
# tar zxvf ndoutils-1.5.2.tar.gz
# cd ndoutils-1.5.2
# ./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql --with-mysql-inc=/usr/local/mysql/include/ --with-mysql-lib=/usr/local/mysql/lib/
# make && make install
# cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin
# cd db/
# mkdir /var/lib/mysql
# ln -s /usr/local/mysql/var/run/mysql.sock/var/lib/mysql/mysql.sock
# ./installdb -ucactier -p123654 -hlocalhost –dcacti
# 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
# chown -R nagios.nagios /usr/local/nagios/etc/ndo*
# chown -R nagios.nagios /usr/local/nagios/bin/*
# vim /usr/local/nagios/etc/nagios.cfg
添加
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg –》这两行必须是放在同一行,中间空格隔开,否则报错
然后确保event_broker_options=-1的参数值是-1,这个值默认就是-1。
安装ndo2db前要先安装mysql-devel
Yum install –y mysql-devel
# vim /usr/local/nagios/etc/ndo2db.cfg
socket_type=unix---》修改为socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cacti
db_prefix=nagios_
db_user=cactier
db_pass=123654
# vim /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
# cp daemon-init /etc/init.d/ndo2db
# vim /etc/init.d/ndo2db
Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x
# chmod +x /etc/init.d/ndo2db
# service ndo2db start
安装npc插件
# tar xf npc-2.0.4.tar.gz -C /usr/local/httpd/htdocs/cacti/plugins
# vim /usr/local/httpd/htdocs/cacti/include/config.php
$plugins[] = "npc";
安装npc支持json
# cd php-5.5.3/ext/json
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make
# make test
# make install
# vim /usr/local/php/etc/php.ini添加
extension="json.so"
# /usr/local/php/bin/php –m查看json是否加载
修改ndo2db.cfg
# vim /usr/local/nagios/etc/ndo2db.cfg
db_prefix=npc_
先激活npc插件,再修改cacti npc插件
Console-->settings-->npc修改如下图
修改数据库表结构:
# mysql -ucactier -p123654
Msyql>usecacti
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_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`;
Mysql>exit
重启ndo2db和nagios
#servicendo2dbrestart
#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
页:
[1]