CentOS6.0+Nagios中文版+PNP+NagiosWeb管理工具nagiosQL中文版
按照网上一篇文档实践搭建了nagios监控系统, 学习交流,原文地址:http://zhumeng8337797.blog.163.com/blog/static/1007689142011101551756386/
金昌网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联自2013年创立以来到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
一、安装CentOS6.0 64位系统
二、执行
1.yum -y install httpd gettext MySQL mysql-server mysql-devel php php-mysql php-pear
2.yum install php-mysql mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel php
三、下载安装包
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz (现在最新版本的插件)
wget http://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2/download
wget http://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2/download
四、用户和组的准备
useradd nagios
passwd nagios
usermod -s /sbin/nologin nagios
uroupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
五、开始安装程序
解压:tar -jxvf nagios-cn-3.2.3.tar.bz2
编译安装:cd nagios-cn-3.2.3
yum -y install gcc automake autoconf libtool make
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
安装插件:
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make insall
添加访问页面用户nagiosadmin及密码,这里要记住此密码不要忘记了.(nagios 123456)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
设置相关服务开机启动
[root@localhost nagios-cn-3.2.3]#service nagios start
[root@localhost nagios-cn-3.2.3]#chkconfig --add nagios
[root@localhost nagios-cn-3.2.3]# chkconfig nagios on
[root@localhost nagios-cn-3.2.3]# chkconfig httpd on
[root@localhost nagios-cn-3.2.3]# chkconfig mysqld on
检查配置文件是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
没有错误,表示通过。
现在可以通过http://IP/nagios访问控制台
六.安装nrpe插件
[nrpe_plugins指标采集程序主要是用来分析nrpe客户端的plugin脚本采集性能指 标数据。目前实现的有cpu、memory、disk、buffer、singleprocess、oracle、sybase等方面的性能指标的分析, 这个插件需要分别安装在主控端和被控端上,这个插件需要openssl的支持,没有就直接在线安装一下(yum install openssl-devel)所以还需在nagios主机和被控端安装,感觉挺麻烦,没办法它需要咱们就跟着做哈.]
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
yum install openssl-devel (提示已经安装)
./configure
make && make install
完成以后没有出错就可以看到以下生成的文件了
接下来按如下操作
mkdir /usr/local/nagios/etc
cp sample-config/nrpe.cfg /usr/local/nagios/etc/
cp init-script /etc/init.d/nrpe
chmod +x /etc/init.d/nrpe
启动nrpe :service nrpe start
七、配置PNP
[PNP是一个基于php和perl,用rrdtool将nagios采集的数据绘制图表的工具,所以安装pnp之前必须先安装php perl and rrdtool这里用yum直接来安装rrdtool,单独下载安装有很多依存关系,挺麻烦.]
yum install rrdtool
wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.15.tar.gz/download
tar zxvf pnp4nagios-0.6.15.tar.gz
cd pnp4nagios-0.6.15
./configure
报错:
执行:yum install perl-Time-HiRes
继续编译
make all
make install
根据提示
make install-webconf
make install-config
make install-init
然后把相关后缀带sample文件变更成无sample后缀
[root@localhost pnp4nagios-0.6.15]# cd /usr/local/pnp4nagios/etc/
[root@localhost etc]# mv misccommands.cfg-sample misccommands.cfg
[root@localhost etc]# mv nagios.cfg-sample nagios.cfg
[root@localhost etc]# mv rra.cfg-sample rra.cfg
[root@localhost etc]# cd pages/
[root@localhost pages]# mv web_traffic.cfg-sample web_traffic.cfg
[root@localhost pages]# cd ../check_commands/
[root@localhost check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@localhost check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg
[root@localhost check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
配置Nagios来启用PNP
cd /usr/local/nagios/etc
vi nagios.cfg
pnp4nagios有很多种工作模式,这里我们选用同步模式,想选其它模式可以看说明都有详细配置教程(不同模式配置不同)
这里我们按说明的设定方法来做
[这里先把pnp4nagios执行数据收集的文件拷贝到nagios的libexec下,方便统一命令的执行路径.]
cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
然后在commands.cfg里面加入如下(这里是同步模式设定方法)
cd /usr/local/nagios/etc/objects
vi commands.cfg
添加内容并注释掉原来的
#process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line $USER1$/process_perfdata.pl -d HOSTPERFDATA
}
define command{
command_name process-host-perfdata
command_line $USER1$/process_perfdata.pl -d HOSTPERFDATA
}
#process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line $USER1$/process_perfdata.pl
}
define command{
command_name process-service-perfdata
command_line $USER1$/process_perfdata.pl
}
然后添加小太阳模版,镶嵌在nagios页面上
[这里有两种查看图的方法,第一种方法是你当太阳的图标的时候会在新窗口中打开图形查看,第二种方法是你只需要把鼠标移动到太阳图标上面就会自动弹出图形出来,以下两种方法你可以根据自己喜好选其中一种即可]
第一种方法在templates.cfg里面加入如下
[这里有两种查看图的方法,第一种方法是你当太阳的图标的时候会在新窗口中打开图形查看,第二种方法是你只需要把鼠标移动到太阳图标上面就会自动弹出图形出来,以下两种方法你可以根据自己喜好选其中一种即可]
第一种方法在templates.cfg里面加入如下
vi templates.cfg
添加内容:
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
为目标主机图标旁边添加一个小太阳标记
vi localhost.cfg
为相关服务添加一个小太阳标记
访问http://IP/pnp3nagios,有一项出错
yum install php* -y
重启后解决
按要求重命名install.php
cd /usr/local/pnp4nagios/share/
mv install.php install.php.bak
刷新网页:
重启nagios:service nagios restart
ok,到此总算配置好了PNP
八.Nagios WEB管理工具叫NagiosQL(注:还有同样一个Nagios WEB管理工具叫Nconf)
下载安装包:wget http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.1.1/nagiosql_311.tar.gz/download
NagiosQL是一个WEB管理工具,只要把其放到下Apache即可。因为这里它要和Nagios整合到一起,为了方便管理,把其放在Nagios目录下
tar zxvf nagiosql_311.tar.gz
mv nagiosql /usr/local/nagios/
建立nagiosQL导出nagios配置文件的目录,并修改权限
建目录和改权限
mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
chown -R apache:nagios /etc/nagiosql/
chmod -R 755 /etc/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config
mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
chown -R apache:nagios /etc/nagiosql/
chmod -R 755 /etc/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config
Nagios相关文件权限的设定
chown nagios:apache /usr/local/nagios/etc
chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chown nagios:apache /usr/local/nagios/etc/*
chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chmod 775 /usr/local/nagios/etc
chown nagios:apache /usr/local/nagios/etc
chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chown nagios:apache /usr/local/nagios/etc/*
chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chmod 775 /usr/local/nagios/etc
设定nagios二进制文件的权限,以便其能够通过Web程序执行
chown nagios:apache /usr/local/nagios/bin/nagios
chmod 750 /usr/local/nagios/bin/nagios
chown -R apache.nagios /usr/local/nagios/var/spool/
chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd
chmod 660 /usr/local/nagios/var/rw/nagios.cmd
chown nagios:apache /usr/local/nagios/bin/nagios
chmod 750 /usr/local/nagios/bin/nagios
chown -R apache.nagios /usr/local/nagios/var/spool/
chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd
chmod 660 /usr/local/nagios/var/rw/nagios.cmd
为apache添加nagiosQL虚拟目录
vi /etc/httpd/conf.d/nagios.conf
#add virture directory for nagiossql
Alias /nagiosQL "/usr/local/nagios/nagiosql"
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
重新加载httpd服务和启动mysqld服务
service httpd reload
service mysqld restart
建立nagiosql安装文件
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
访问http://ip/nagiosQL进行安装
开始安装,测试环境通过,下一步
输入mysql 密码,设置nagiosQL默认登录密码
删除安装目录,这里使用改权限:chmod 000 /usr/local/nagios/nagiosql/install
完成安装
管理-域-localhost---点“修改”
按如图修改
工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
工具-nagios控制-写入检测数据-写入其他数据
检查配置文件成功
重新启动nagios
写入之后就可以看到相应的cfg文件了,查看写入是否成功,由下面的输出可以看出写入是成功滴.
修改nagios的配置文件,将原有以cfg_file开头项全部注释掉,加入上面新写入的配置文件
vi /usr/local/nagios/etc/nagios.cfg
注释掉
加入新的配置文件路径
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
检查nagios的配置文件是否有问题,然后生重启nagios服务,至此整个搭建过程终于完成了
后面续上添加监控主机。
当前题目:CentOS6.0+Nagios中文版+PNP+NagiosWeb管理工具nagiosQL中文版
网页地址:http://azwzsj.com/article/picjge.html