Icinga 2 特点
Icinga 2 的一些核心功能:
- 监控网络服务(http、smtp、pop3. ping 等)
- 监控主机系统资源(CPU 负载、内存使用情况、磁盘使用情况等)
- 监控服务器组件(交换机、路由器、湿度和温度传感器等)
- 简单的插件设计
- 并行服务检查
在 CentOS 8 上安装 EPEL yum 存储库
使用 ssh 工具以 root 用户身份连接 icinga-2.recipes.com 服务器。
Icinga 2 需要 Nagios 插件,这些插件在 EPEL(企业 Linux 的另外包)yum 存储库中可用,因此我们正在安装 EPEL yum 存储库。
[root@icinga-2 ~]# dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
在 CentOS 8 上安装 Icinga 2
我们已经安装了 Icinga 2 yum 存储库。
因此,我们现在可以使用 dnf 命令安装 Icinga 2.
[root@icinga-2 ~]# dnf install -y icinga2 icinga2-selinux icinga2-ido-mysql vim-icinga2
检查 Icinga 2 安装的功能。
[root@icinga-2 ~]# icinga2 feature list Disabled features: api command compatlog debuglog elasticsearch gelf graphite ido-mysql influxdb livestatus opentsdb perfdata statusdata syslog Enabled features: checker mainlog notification
Icinga 2 是一款开源计算机和网络监控软件。
Icinga 2 最初是在 2009 年从 Nagios 网络监控应用程序fork出来的。
Icinga 2 在 GNU GPL v2 下分发。
作为 Nagios 的一个分支,Icinga 拥有 Nagios Core 的所有功能,它还具有一些添加功能,例如现代 Web 2.0 风格的用户界面、数据库连接器(用于 MySQL、Oracle 和 PostgreSQL)和一个 REST API,它让系统管理员无需复杂的修改。
Icinga 开发人员还寻求通过更快地集成补丁来更密切地反映社区需求。
在本文中,我们正在编写有关如何在 CentOS 8 上安装 Icinga 2 的教程,并且我们还通过 IDO(Icinga 数据输出)模块将 MariaDB 配置为 Icinga 2 的后端数据存储。
在 CentOS 8 上安装 MariaDB 服务器
安装 MariaDB 服务器以用作 Icinga 2 的数据存储。
[root@icinga-2 ~]# dnf install -y @mariadb/server
启动并启用 MariaDB 服务。
[root@icinga-2 ~]# systemctl enable --now mariadb.service Created symlink /etc/systemd/system/mysql.service -> /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/mysqld.service -> /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service -> /usr/lib/systemd/system/mariadb.service.
配置 MariaDB 服务器并设置 root 用户密码。
[root@icinga-2 ~]# 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!
在 CentOS 8 上安装 Nagios 插件
为了收集不同的指标,我们需要各个 Nagios 插件工具提供的命令。
Nagios 插件在 EPEL yum 存储库中可用。
因为,我们已经安装了 EPEL,因此,我们现在可以使用 dnf 命令轻松安装 Nagios 插件。
[root@icinga-2 ~]# dnf install -y nagios-plugins-{http,ping,disk,users,swap,procs,ssh,load}
在 CentOS 8 上安装 Icinga 2 Yum 软件库
Icinga 2 rpms 提供在它自己的yum 存储库中,因此如果我们想使用dnf 命令安装Icinga 2,则需要安装Icinga 2 yum 存储库。
[root@icinga-2 ~]# dnf install -y https://packages.icinga.com/epel/icinga-rpm-release-8-latest.noarch.rpm
配置 Icinga 2 IDO 以使用 MariaDB 数据存储
以 root 用户身份连接 MariaDB 服务器。
[root@icinga-2 ~]# mysql -u root -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.3.11-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)]>
为 Icinga 2 创建一个 MariaDB 数据库,如下所示。
MariaDB [(none)]> CREATE DATABASE icinga; Query OK, 1 row affected (0.073 sec)
为 Icinga 2 创建一个用户并授予对 icinga 数据库的完整权限。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'JackLi@1234'; Query OK, 0 rows affected (0.176 sec)
重新加载权限表并退出 MySQL 提示符。
MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.066 sec) MariaDB [(none)]> EXIT; Bye
从随 Icinga 2 软件提供的脚本导入数据库。
[root@icinga-2 ~]# mysql -u root -p123 icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql
根据我们的环境配置 IDO 配置。
[root@icinga-2 ~]# vi /etc/icinga2/features-available/ido-mysql.conf
取消注释并设置指令如下。
/** * The IdoMysqlConnection type implements MySQL support * for DB IDO. */ object IdoMysqlConnection "ido-mysql" { user = "icinga" password = "JackLi@1234" host = "localhost" database = "icinga" }
启用 IDO 和其他必需的功能。
[root@icinga-2 ~]# icinga2 feature enable command ido-mysql syslog Enabling feature command. Make sure to restart Icinga 2 for these changes to take effect. Enabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect. Enabling feature syslog. Make sure to restart Icinga 2 for these changes to take effect.
启用并启动 Icinga 2 服务。
[root@icinga-2 ~]# systemctl enable --now icinga2.service Created symlink /etc/systemd/system/multi-user.target.wants/icinga2.service -> /usr/lib/systemd/system/icinga2.service.
验证 Icinga 2 服务的状态。
[root@icinga-2 ~]# systemctl status icinga2.service Jan 11 12:34:00 icinga-2.recipes.com icinga2[14857]: [2020-01-11 12:34:00 +0500> Jan 11 12:34:00 icinga-2.recipes.com icinga2[14857]: [2020-01-11 12:34:00 +0500> Jan 11 12:34:00 icinga-2.recipes.com icinga2[14857]: [2020-01-11 12:34:00 +0500> Jan 11 12:34:00 icinga-2.recipes.com icinga2[14857]: [2020-01-11 12:34:00 +0500> Jan 11 12:34:00 icinga-2.recipes.com icinga2[14857]: [2020-01-11 12:34:00 +0500> Jan 11 12:34:00 icinga-2.recipes.com systemd[1]: Started Icinga host/service/ne>
我们已经在 CentOS 8 上成功安装了 Icinga 2.