NagiosQL安装


    NagiosQL和Nconf是比较好用的Nagios配置工具。

一、安装NagiosQL
1、在服务器终端运行以下命令:
##YUM安装PHP模块
yum -y install --disablerepo=* --enablerepo=remi php-pecl-ssh2


##下载解压NagiosQL
cd /usr/local/src
wget -nc http://softlayer-dal.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
tar -zxvf nagiosql_[0-9]*.tar.gz
mv -f nagiosql32 nagiosql

cp -nr nagiosql /var/www/html/nagiosql
chown -R apache:www /var/www/html/nagiosql
chmod -R g+w /var/www/html/nagiosql


##修正PHP程序错误
#You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`value' at line 4
#http://www.nagiosql.org/forum8/general-questions/3251-add-host-you-have-an-error-in-your-sql-syntax.html
sed -i 's/AND `access_group` IN ($strAccess) ORDER BY `value";/AND `access_group` IN ($strAccess) ORDER BY `value`";/'
/var/www/html/nagiosql/functions/nag_class.php


##创建NagiosQL导出Nagios/Icinga配置文件目录
mkdir -p /etc/nagiosql/{hosts,services,backup,import}
mkdir -p /etc/nagiosql/backup/{hosts,services}
chown -R apache:www /etc/nagiosql/
chmod -R g+w /etc/nagiosql/


##修改Icinga配置文件权限
chown -R icinga:www /usr/local/icinga/etc/
chmod -R g+w /usr/local/icinga/etc/

chown -R icinga:www /usr/local/icinga/var/rw/
chmod -R g+w /usr/local/icinga/var/rw/


chown -R icinga:www /usr/local/icinga/var/spool/checkresults
chmod -R g+w /usr/local/icinga/var/spool/checkresults


##生成Apache配置文件
cat <<EOF > /etc/httpd/conf.d/nagiosql.conf
Alias /nagiosql "/var/www/html/nagiosql"

<Directory "/var/www/html/nagiosql">
    AllowOverride None
    Order allow,deny
    Allow from all
    #
    # Use the same value as defined in nagios.conf
    #
    AuthName "Icinga Access"
    AuthType Basic
    AuthUserFile /usr/local/icinga/etc/htpasswd.users
    Require valid-user
</Directory>

EOF

##重载Apache
service httpd reload


##网站安装NagiosQL
#访问http://服务器IP/nagiosql


2、选择语言。如果这里选了英文,以后也不能改为拥吻

3、检查前置条件


4、指定数据库环境参数和Nagios配置文件目录


5、完成安装


二、NagiosQL基本环境配置
1、登陆NagiosQL
这里是2层安全认证:apache的基本认证和NagiosQL程序认证
2、禁用在线版本检查,这个功能有可能会造成程序假死


3、修改Configuration target中localhost的配置

根据实际的Icinga/Nagios文件位置填写相关路径
/usr/local/icinga/var/rw/icinga.cmd
/usr/local/icinga/bin/icinga
/usr/local/icinga/var/icinga.lock
/usr/local/icinga/etc/icinga.cfg

设置完成后检查Support中的Config domain checks是否全部OK



三、迁移导入现有Icinga/Nagios配置文件
1、在服务器终端运行以下命令:
##备份现有Icinga配置文件,准备导入
cp -R `grep "^cfg_dir" /usr/local/icinga/etc/icinga.cfg | grep -v "modules" | awk -F= '{print $2}' | xargs` /etc/nagiosql/import


cp `grep "^cfg_file" /usr/local/icinga/etc/icinga.cfg | awk -F= '{print $2}' | xargs` /etc/nagiosql/import

#在http://服务器IP/nagiosql/admin/import.php,导入/etc/nagiosql/import中所有的cfg文件
#在http://服务器IP/nagiosql/admin/verify.php中写入检测数据和其他数据

2、在导入配置中选择导入/etc/nagiosql/import中所有的cfg文件



3、在Nagios控制中执行2个写入


4、在服务器终端运行以下命令:
##修改配置文件icinga.cfg
#注释现有的cfg_file和非模块cfg_dir,使用4个井号#
sed -i -e 's/^(cfg_file=.*)$/####1/'
-e 's/^cfg_dir=(.*modules)$/@@@1/;s/^(cfg_dir=.*)$/####1/;s/^@@@(.*)$/cfg_dir=1/'
/usr/local/icinga/etc/icinga.cfg

#增加NagiosQL配置文件
grep -q "NagiosQL Configuration Files" /usr/local/icinga/etc/icinga.cfg ||
cat <<EOF >> /usr/local/icinga/etc/icinga.cfg

# NagiosQL Configuration Files
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
EOF


##检查配置文件icinga.cfg 
icinga -v /usr/local/icinga/etc/icinga.cfg


##重载Icinga
service icinga reload

5、查看Support中查看配置文件是否都OK。
忽略“cfg_dir=/usr/local/icinga/etc/modules”,idoutils或NDOUtils的配置文件在在这个目录下

参考文档:
1、安装nagios的WEB管理工具nagiosQL http://cshbk.blog.51cto.com/5685776/1288846




原文地址:https://www.cnblogs.com/han1988/p/3399233.html