配置 Nagios Core 以使用 NDOUtils 代理模块

编辑 nagios.cfg 文件,以便 Nagios Core 可以使用 NDOUtils 代理模块。

[root@nagios-01 ndoutils-2.1.3]# cat >> /usr/local/nagios/etc/nagios.cfg << EOF
> #NDOUtils Broker Module
> broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
> EOF

重新启动 nagios.service 以重新加载更改。

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

在 CentOS 7 上安装 MariaDB 数据库

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

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

启动并启用 MariaDB 服务。

[root@nagios-01 ~]# systemctl start mariadb.service
[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.

配置 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!
更多: zhilu jiaocheng

在 CentOS 7 上为 Nagios Core 安装 NDOUtils

从 SourceForge 网站下载 NDOUtils 源代码。

[root@nagios-01 tmp]# wget -O ndoutils.tar.gz https://sourceforge.net/projects/nagios/files/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz/download

提取下载的文件。

[root@nagios-01 tmp]# tar xvf ndoutils.tar.gz

从源代码编译 NDOUtils 二进制文件。

[root@nagios-01 tmp]# cd ndoutils-2.1.3
[root@nagios-01 ndoutils-2.1.3]# ./configure

安装 NDOUtils 二进制文件。

[root@nagios-01 ndoutils-2.1.3]# make install

创建数据库表来存储 Nagios 数据。

[root@nagios-01 ndoutils-2.1.3]# cd db
[root@nagios-01 db]# ./installdb -u 'ndoutils' -p 'jackli123' -h 'localhost' -d nagios
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 52.
** Creating tables for version 2.0.1
     Using mysql.sql for installation...
** Updating table nagios_dbversion
Done!

忽略失败警告,这里检查数据库是否已经初始化。

安装 NDOUtils 配置文件。

[root@nagios-01 ndoutils-2.1.3]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 644 -o nagios -g nagios config/ndo2db.cfg-sample /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios config/ndomod.cfg-sample /usr/local/nagios/etc
*** Config files installed ***
Remember, these are *SAMPLE* config files.  You'll need to rename
the files in order to use them.
Please read the documentation to know what they are doing.

根据环境编辑这些配置文件。

我们在这里只定义 MariaDB 用户凭据,将所有其他设置保留为默认值。

[root@nagios-01 ndoutils-2.1.3]# cd /usr/local/nagios/etc/
[root@nagios-01 etc]# mv ndo2db.cfg-sample ndo2db.cfg
[root@nagios-01 etc]# mv ndomod.cfg-sample ndomod.cfg
[root@nagios-01 etc]# sed -i 's/^db_user=.*/db_user=ndoutils/g' ndo2db.cfg
[root@nagios-01 etc]# sed -i 's/^db_pass=.*/db_pass=jackli123/g' ndo2db.cfg

安装 NDOUtils 服务。

[root@nagios-01 etc]# cd /tmp/ndoutils-2.1.3/
[root@nagios-01 ndoutils-2.1.3]# make install-init
/usr/bin/install -c -m 644 startup/default-service /usr/lib/systemd/system/ndo2db.service

启动并启用 ndo2db.service。

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

调整 NDOUtils 的内核参数

需要为 NDOUtils 设置一些内核参数。

从 /etc/sysctl.conf 中删除以下内核参数的任何先前设置。

[root@nagios-01 ~]# sed -i '/msgmnb/d' /etc/sysctl.conf
[root@nagios-01 ~]# sed -i '/msgmax/d' /etc/sysctl.conf
[root@nagios-01 ~]# sed -i '/shmmax/d' /etc/sysctl.conf
[root@nagios-01 ~]# sed -i '/shmall/d' /etc/sysctl.conf

现在,为这些参数添加所需的值,如下所示。

[root@nagios-01 ~]# cat >> /etc/sysctl.conf << EOF
> kernel.msgmnb = 131072000
> kernel.msgmax = 131072000
> kernel.shmmax = 4294967295
> kernel.shmall = 268435456
> EOF

从配置文件重新加载内核参数。

[root@nagios-01 ~]# sysctl -p
kernel.msgmnb = 131072000
kernel.msgmax = 131072000
kernel.shmmax = 4294967295
kernel.shmall = 268435456
在 CentOS 7 上为 Nagios Core 安装 NDOUtils

NDOUtils 是 Nagios Core 的插件。

默认情况下,Nagios Core 将其数据存储在平面文件中。
NDOUtils 允许我们将当前和历史数据从 Nagios Core 实例导出到 MySQL 数据库。
NDOUtils 包含在 Nagios XI(Nagios 的商业版本)中。
许多社区插件也使用 NDOUtils 作为数据源。
NDOUtils 由一个独立的守护进程、一个 Nagios 事件代理和几个帮助实用程序组成。

在本文中,我们将在 CentOS 7 上为 Nagios Core 安装 NDOUtils。

测试 NDOUtils 与 Nagios Core 的集成

通过查询 Nagios 日志来检查 Nagios Core 使用的 NDOUtils 代理模块。

[root@nagios-01 ndoutils-2.1.3]# grep ndo /usr/local/nagios/var/nagios.log
[1557602671] ndomod: NDOMOD 2.1.3 (2017-04-13) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1557602671] ndomod: Successfully connected to data sink.  0 queued items to flush.
[1557602671] ndomod registered for process data
[1557602671] ndomod registered for timed event data
[1557602671] ndomod registered for log data'
[1557602671] ndomod registered for system command data'
[1557602671] ndomod registered for event handler data'
[1557602671] ndomod registered for notification data'
[1557602671] ndomod registered for service check data'
[1557602671] ndomod registered for host check data'
[1557602671] ndomod registered for adaptive contact data'
[1557602671] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.

检查 NDOUtils 是否将条目转发到我们的 MariaDB 数据库。

[root@nagios-01 ndoutils-2.1.3]# echo 'select * from nagios.nagios_logentries;' | mysql -u ndoutils -p'jackli123'
logentry_id     instance_id     logentry_time   entry_time      entry_time_useclogentry_type    logentry_data   realtime_data   inferred_data_extracted
1       1       2019-05-12 00:24:31     2019-05-12 00:24:31     767227  262144 ndomod registered for log data'  1       1 
40      1       2019-05-12 00:24:31     2019-05-12 00:24:31     769082  8      Warning: Service 'W3SVC' on host 'winserver' has no check time period defined!  11
41      1       2019-05-12 00:24:31     2019-05-12 00:24:31     769103  8      Warning: Contact 'nagiosadmin' has no host notification time period defined!    11
42      1       2019-05-12 00:24:31     2019-05-12 00:24:31     821974  262144 Successfully launched command file worker with pid 14112 1       1

我们已经在 CentOS 7 上成功为 Nagios Core安装了 NDOUtils 。

为 NDOUtils 创建一个 MariaDB 数据库

使用 mysql 命令以 root 用户身份连接 MariaDB 实例。

[root@nagios-01 ~]# mysql -u root -p'123'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

使用以下命令为 NDOUtils 创建数据库和用户。

MariaDB [(none)]> CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.04 sec)
MariaDB [(none)]> CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'jackli123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT USAGE ON *.* TO 'ndoutils'@'localhost' IDENTIFIED BY 'jackli123' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

从 mysql 提示符退出。

MariaDB [(none)]> QUIT
Bye
日期:2020-09-17 00:16:44 来源:oir作者:oir