温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

发布时间:2020-08-10 22:16:20 来源:网络 阅读:1024 作者:乜波 栏目:移动开发

按照网上一篇文档实践搭建了nagios监控系统, 学习交流,原文地址:http://zhumeng8337797.blog.163.com/blog/static/1007689142011101551756386/

一、安装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
   四、用户和组的准备
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
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

没有错误,表示通过。
现在可以通过http://IP/nagios访问控制台
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

六.安装nrpe插件
nrpe_plugins指标采集程序主要是用来分析nrpe客户端的plugin脚本采集性能指 标数据。目前实现的有cpumemorydiskbuffersingleprocessoraclesybase等方面的性能指标的分析这个插件需要分别安装在主控端和被控端上,这个插件需要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
完成以后没有出错就可以看到以下生成的文件了
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

接下来按如下操作
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是一个基于phpperl,用rrdtoolnagios采集的数据绘制图表的工具,所以安装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 
报错:
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

执行:yum install perl-Time-HiRes
继续编译
make all
make install
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

根据提示
make install-webconf
make install-config
make install-init
然后把相关后缀带sample文件变更成无sample后缀
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

[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
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

pnp4nagios有很多种工作模式,这里我们选用同步模式,想选其它模式可以看说明都有详细配置教程(不同模式配置不同
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

这里我们按说明的设定方法来做
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

[这里先把pnp4nagios执行数据收集的文件拷贝到nagioslibexec下,方便统一命令的执行路径.]
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 
        }
#process-service-perfdata' command definition 
define command{ 
        command_name    process-service-perfdata 
        command_line    $USER1$/process_perfdata.pl 
        } 
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

然后添加小太阳模版,镶嵌在nagios页面上
[这里有两种查看图的方法,第一种方法是你当太阳的图标的时候会在新窗口中打开图形查看,第二种方法是你只需要把鼠标移动到太阳图标上面就会自动弹出图形出来,以下两种方法你可以根据自己喜好选其中一种即可]
第一种方法在templates.cfg里面加入如下
vi templates.cfg
添加内容:
define host { 
   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 
为目标主机图标旁边添加一个小太阳标记
vi localhost.cfg
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

为相关服务添加一个小太阳标记
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

访问http://IP/pnp3nagios,有一项出错
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

yum install php* -y
重启后解决

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

 
按要求重命名install.php
cd /usr/local/pnp4nagios/share/
mv install.php install.php.bak
刷新网页:
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

重启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
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
设定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
apache添加nagiosQL虚拟目录
vi /etc/httpd/conf.d/nagios.conf 
#add virture directory for nagiossql
Alias /nagiosQL "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
重新加载httpd服务和启动mysqld服务
service httpd reload
service mysqld restart 
建立nagiosql安装文件
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
访问http://ip/nagiosQL进行安装
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

开始安装,测试环境通过,下一步
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

输入mysql 密码,设置nagiosQL默认登录密码
删除安装目录,这里使用改权限:chmod 000 /usr/local/nagios/nagiosql/install
完成安装
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

管理-域-localhost---修改
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

按如图修改
 
 
CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版
工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

工具-nagios控制-写入检测数据-写入其他数据
CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版
检查配置文件成功

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

重新启动nagios
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

写入之后就可以看到相应的cfg文件了,查看写入是否成功,由下面的输出可以看出写入是成功滴.
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

修改nagios的配置文件,将原有以cfg_file开头项全部注释掉,加入上面新写入的配置文件
vi /usr/local/nagios/etc/nagios.cfg 
注释掉
 

CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版

加入新的配置文件路径
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服务,至此整个搭建过程终于完成了
 
后面续上添加监控主机。
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI