www. On IT Road .com

在 CentOS 7 上安装 NagiosQL

NagiosQL 在 Nagios Exchange 和 SourceForge 上可用。

我们也可以从 SourceForge 网站下载 NagiosQL 文档。

下载 NagiosQL 最新版本并将其复制到 root 用户的主目录中。

[root@nagios-01 ~]# tar xvjf nagiosql-3.4.0.tar.bz2 -C /var/www/html/
 
[root@nagios-01 ~]# mv /var/www/html/nagiosql-3.4.0/ /var/www/html/nagiosql

为 /var/www/html/nagiosql/ 目录重新应用 SELinux 安全上下文。

[root@nagios-01 ~]# restorecon -Rv /var/www/html/nagiosql/

为 NagiosQL 创建一个目录来放置 Nagios Core 配置文件。

[root@nagios-01 ~]# mkdir /usr/local/nagios/etc/nagiosql
[root@nagios-01 ~]# chown apache:apache /usr/local/nagios/etc/nagiosql/

为 config 目录中的所有用户授予写权限以创建配置文件。

[root@nagios-01 config]# chmod o+w /var/www/html/nagiosql/config

浏览 URL http://nagios-01.onitroad.com/nagiosql/ 以运行 NagiosQL 安装向导。

由于我们是第一次运行 NagiosQL 安装向导,并且 config 文件夹中不存在任何 settings.php 文件,因此向导给了我们以下警告

“设置文件未找到或者不可读(config/settings.php)。
升级不可用!”

可以忽略它。

单击开始安装。

NagiosQL 安装向导正在检查要求,如果缺少准备工作,将给出警告。

如果我们正确地遵循了上述步骤,那么它不会给我们任何警告。

单击下一步。

根据上面的屏幕截图定义设置。

单击下一步。

单击下一步。

如果一切顺利,我们将到达 NagiosQL 登录页面。

以管理员用户身份登录。

在 CentOS 7 上安装或者升级 PHP

因为,我们安装在同一台服务器上,我们已经在该服务器上配置了 Nagios Core。
因此,我们在 Nagios Core 配置期间已经在其上安装了 PHP 5.4.
但是 NagiosQL 需要 PHP 5.5 或者更高版本,因此我们必须将 PHP 从 5.4 升级到 5.5.

PHP 5.5 可通过各种第三方 yum 存储库获得。
因此,我们正在安装 webtatic yum 存储库。

但首先,安装 EPEL(企业 Linux 的另外包)作为 webtatic yum 存储库的准备工作。

[root@nagios-01 ~]# yum install -y epel-release

根据 Linux 版本从 Webtatic 网站下载并安装 webtatic yum 存储库 RPM。

[root@nagios-01 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

为新添加的 yum 存储库构建 yum 缓存。

[root@nagios-01 ~]# yum makecache fast

删除当前版本的 PHP。

[root@nagios-01 ~]# yum remove -y php-common php php-gd php-cli

从 webtatic yum 存储库安装 PHP 5.5.

[root@nagios-01 ~]# yum install -y php55w-common php55w php55w-gd php55w-cli php55w-mysql php55w-devel php55w-pear

安装 PHP 所需的 libssh2-devel 包。

[root@nagios-01 ~]# yum install -y libssh2-devel

从 PECL(PHP 扩展社区库)为 PHP 安装 ssh2 扩展。

[root@nagios-01 ~]# pecl channel-update pecl.php.net
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
[root@nagios-01 ~]# pecl install ssh2

在 /etc/php.ini 中添加以下指令。

[root@nagios-01 ~]# echo "date.timezone='Asia/Karachi'" >> /etc/php.ini
[root@nagios-01 ~]# echo "extension=ssh2.so" >> /etc/php.ini

重启 Apache 服务。

[root@nagios-01 ~]# systemctl restart httpd

我们已经在 CentOS 7 服务器上安装了所有 NagiosQL 必备软件包。

在 CentOS 7 上安装 Apache HTTP 服务器

因为,我们安装在运行 Nagios Core 的同一台服务器上,所以不需要安装 Apache HTTP 服务器,因为它已经在 Nagios Core 配置期间安装了。

NagiosQL 安装后配置

NagiosQL 已经安装完毕,我们现在可以删除安装目录以防止任何人再次运行安装向导。

[root@nagios-01 config]# rm -rf /var/www/html/nagiosql/nagiosql-3.4.0/install/

我们已经成功生成了 settings.php 文件。
因此,为了安全起见,撤销其他用户的写权限。

[root@nagios-01 config]# chmod o-w /var/www/html/nagiosql/config
在 CentOS 7 上安装Nagios 配置器 NagiosQL

Nagios Core 是一个免费的开源网络、服务器和应用程序监控软件。

Nagios Core 的一个缺点是它缺少配置工具,因此我们必须使用文本编辑器来编辑配置文件。
手动编辑配置文件总是很头疼,而且很容易出现排版错误。

NagiosQL 是一个基于 Web 的 Nagios Core 配置器。
它与 Nagios Core 完全集成,使配置管理更加容易。
我们在上一篇文章中配置了另一个 Nagios 配置器:Lilac Reloaded。

在本文中,我们将在基于 CentOS 7 的 Nagios Core 服务器上安装 NagiosQL Nagios 配置器。

在 NagiosQL 中导入 Nagios Core 配置

NagiosQL 是零配置安装的,因此,我们必须导入我们现有的 Nagios Core 配置。

转至管理 > 配置目标。

单击功能列下的修改。

根据环境调整目录路径,然后单击保存。

转至工具 > 数据导入。

选择所有导入文件并单击导入。

转到监督选项卡,我们可能会观察到现在已经导入了一些活动组。

文件状态丢失,因为我们还没有保存我们的文件。
因此,单击写入所有配置文件。

我们可能会观察到文件状态现在是最新的。

对其他目标/配置(如主机、命令、模板等)重复此过程,将它们保存在 NagiosQL 配置目录中。

最后,我们必须编辑 nagios.cfg 文件以删除当前的 cfg_dir 指令并添加由 NagiosQL 主动管理的新配置目录。
这可以通过以下两个命令来实现。

[root@nagios-01 ~]# sed -i 's/^cfg/#cfg/' /usr/local/nagios/etc/nagios.cfg
[root@nagios-01 ~]# echo "cfg_dir=/usr/local/nagios/etc/nagiosql/" >> /usr/local/nagios/etc/nagios.cfg

重新启动 nagios.service 以检查是否有任何配置错误。

[root@nagios-01 hosts]# systemctl restart nagios.service

如果我们正确执行了上述步骤,则应该没有错误。

现在,Nagios Core 正在使用 NagiosQL 配置目录中的配置。

我们已经在 CentOS 7 服务器上成功安装了 NagiosQL Nagios Configurator。

在 CentOS 7 上安装 MariaDB 数据库

NagiosQL 需要 MariaDB 或者 MySQL 数据库来创建其存储库。
因此,我们正在从 CentOS 7 yum 存储库安装可用的 MariaDB 服务器。

[root@nagios-01 ~]# yum install -y mariadb-server

启动并启用 MariaDB 服务。

[root@nagios-01 ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nagios-01 ~]# systemctl start mariadb.service

配置 MariaDB 数据库实例。

[root@nagios-01 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
日期:2020-09-17 00:16:44 来源:oir作者:oir