NagiosQL 是专为 nagios 设计的 web 图形化管理应用,主要作用就是操作数据库和配置文件,其中包括将配置文件的信息写到数据库中,在数据库中修改 Nagios的监控配置信息,并将数据库中存放的配置更新到文件中。用户可以通过 NagiosQL提供的Web页面直观的修改配置。实现架构很简单,功能很实用。<?xml:namespace prefix = o />
功能介绍:
1、 具有基本的nagios的配置管理能力,导入,导出配置文件的功能。
2、 具有nagios配置文件检查、排错的能力。
3、 Nagiosql可对文件结构进行定制,可延续之前的配置结构,按 IP生成配置。
4、 Nagiosql将每一次配置的变更做一次配置备份,以时间戳为后缀保存,理论上可以回滚到任意一个历史配置。
环境配置
既然是web 管理端,那么当然需要httpd之类的web工具的支持了,这里我搭的是LAMP的环境,Nagios 已经搭建好的。
注意:在编译安装php的时候要注意一下,如果是参考我前面的博客Nagios(一) 搭建LAMP环境的话,在编译php的时候还需要添加2个参数。否则会报错,如下所示:
![](https://i-blog.csdnimg.cn/blog_migrate/028cd7bed9353d4e66754466d8b488b9.png)
编译安装php 参数:
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/etc \
--with-freetype-dir --with-jpeg-dir \
--with-png-dir --enable-zip \
--with-zlib --enable-xml \
--with-gd --with-mhash \
--with-libxml-dir=/usr --enable-mbstring \
--enable-fpm --with-fpm-user=fpmuser \
--with-fpm-group=fpmuser --disable-ipv6 \
--enable-sockets --with-openssl \
--with-bz2 --with-curl --enable-dba=shared \
--with-pcre-dir --with-gd --with-jpeg-dir --with-png-dir \
--with-zlib-dir --enable-mbstring \
--with-mysql=/usr/local/mysql/ \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-gettext --enable-ftp
开始解压安装nagiosql
[root@server ~]# tar zxvf nagiosql_311.tar.gz
[root@server ~]# mv nagiosql /usr/local/nagios/
[root@server ~]# cd /usr/local/nagios/nagiosql/
创建配置文件目录
[root@server nagiosql]# mkdir -p etc/{hosts,services,backup/{hosts,services},import}
修改相关目录的权限
[root@server nagiosql]# chown -R nagios.nagios .
[root@server nagiosql]# chmod -R 755 .
[root@server nagiosql]# chmod 777 config/
[root@server nagiosql]# chown nagios:nagios /usr/local/nagios/etc
[root@server nagiosql]# chown nagios:nagios /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
[root@server nagiosql]# chown nagios:nagios /usr/local/nagios/etc/*
[root@server nagiosql]# chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
[root@server nagiosql]# chmod 775 /usr/local/nagios/etc
[root@server nagiosql]# chown nagios:nagios /usr/local/nagios/bin/nagios
[root@server nagiosql]# chmod 750 /usr/local/nagios/bin/nagios
[root@server nagiosql]# chown -R nagios.nagios /usr/local/nagios/var/spool/
[root@server nagiosql]# chown nagios:nagios /usr/local/nagios/var/rw/nagios.cmd
[root@server nagiosql]# chmod 660 /usr/local/nagios/var/rw/nagios.cmd
创建安装文件
[root@server nagiosql]# touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
编辑httpd.conf 添加虚拟目录
[root@server nagiosql]#vim /usr/local/apache/conf/httpd.conf
Alias /nagiosql "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改完后,重启apache和mysql
[root@server nagiosql]# /usr/local/apache/bin/apachectl restart
[root@server nagiosql]# service mysql start
Starting MySQL SUCCESS!
环境测试通过!
![](https://i-blog.csdnimg.cn/blog_migrate/522dbe5f585973f4abbd90998430c8aa.png)
[root@server ~]# /usr/local/mysql/bin/mysqladmin -uroot password 123123
“请删除安装目录以继续”
[root@server ~]# chmod 000 /usr/local/nagios/nagiosql/install
输入账号密码后登陆:
![](https://i-blog.csdnimg.cn/blog_migrate/5b1297640e11a5e7355158d473b3f619.png)
管理-域-localhost---点“修改”
![](https://i-blog.csdnimg.cn/blog_migrate/22ecafb5db795d9cf5e9cc5957b10c43.png)
按如图所示更改相应的路径即可
![](https://i-blog.csdnimg.cn/blog_migrate/164333c4efd4960695738bc13ccb328c.png)
工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
导入成功后可以看到
![](https://i-blog.csdnimg.cn/blog_migrate/60fca4731eb5caa232cac250f44bb2d3.png)
工具-nagios控制-写入检测数据-写入其他数据
![](https://i-blog.csdnimg.cn/blog_migrate/d2374bb3532400eab0d7703397210872.png)
检查配置文件成功
![](https://i-blog.csdnimg.cn/blog_migrate/ed9f4476ea596605c173fd305935bacd.png)
重启nagios
![](https://i-blog.csdnimg.cn/blog_migrate/95ae68ddbc408ab3389d92f73b9ab517.png)
写入之后就可以看到相应的cfg文件了,查看写入是否成功,由下面的输出可以看出写入已经成功
![](https://i-blog.csdnimg.cn/blog_migrate/2c0898fd9d88477091867045709bd070.png)
修改nagios的配置文件,将原有以cfg_file开头项全部注释掉,加入上面新写入的配置文件
[root@server ~]# vim /usr/local/nagios/etc/nagios.cfg
# You can specify individual object config files as shown below:
#cfg_file=/usr/local/nagios/etc/objects/commands.cfg
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
#cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios/etc/objects/templates.cfg
#cfg_file=/usr/local/nagios/etc/hosts.cfg
#cfg_file=/usr/local/nagios/etc/services.cfg
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
加入新的配置文件路径
cfg_dir=/usr/local/nagios/nagiosql/etc/hosts/
cfg_dir=/usr/local/nagios/nagiosql/etc/services/
cfg_file=/usr/local/nagios/nagiosql/commands.cfg
cfg_file=/usr/local/nagios/nagiosql/contactgroups.cfg
cfg_file=/usr/local/nagios/nagiosql/contacts.cfg
cfg_file=/usr/local/nagios/nagiosql/contacttemplates.cfg
cfg_file=/usr/local/nagios/nagiosql/hostdependencies.cfg
cfg_file=/usr/local/nagios/nagiosql/hostextinfo.cfg
cfg_file=/usr/local/nagios/nagiosql/hostgroups.cfg
cfg_file=/usr/local/nagios/nagiosql/hosttemplates.cfg
cfg_file=/usr/local/nagios/nagiosql/servicedependencies.cfg
cfg_file=/usr/local/nagios/nagiosql/serviceescalations.cfg
cfg_file=/usr/local/nagios/nagiosql/serviceextinfo.cfg
cfg_file=/usr/local/nagios/nagiosql/servicegroups.cfg
cfg_file=/usr/local/nagios/nagiosql/servicetemplates.cfg
cfg_file=/usr/local/nagios/nagiosql/timeperiods.cfg
cfg_file=/usr/local/nagios/nagiosql/hostescalations.cfg
检查nagios的配置文件是否有问题,然后生重启nagios服务,至此整个搭建过程终于完成
[root@server ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0