Icinga web 2 是一个基于 PHP 的 web 应用程序,它为 Icinga 2 网络监控服务器提供了一个 web 界面。
在本文中,我们将学习如何在 CentOS 8 服务器上安装 Icinga web 2.
为 Icinga Web 2 创建 MySQL 数据库
之前我们已经在同一台 Linux 服务器上安装了 MariaDB。
因此,我们现在可以在同一 MySQL 服务器上创建 Icinga Web 2 后端数据库。
以 root 用户身份登录 MySQL 服务器。
[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 Web 2 创建一个 MySQL 数据库,如下所示。
MariaDB [(none)]> CREATE DATABASE icingaweb; Query OK, 1 row affected (0.028 sec)
为 Icinga Web 2 创建一个数据库用户并授予对 icinga 数据库的完整权限。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON icingaweb.* TO 'icinga'@'localhost' IDENTIFIED BY 'JackLi@1234'; Query OK, 0 rows affected (0.143 sec)
重新加载权限表并退出 MySQL shell。
MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.066 sec) MariaDB [(none)]> EXIT; Bye
在 CentOS 8 上安装 Icinga Web 2:
我们已经在 Linux 包管理器中添加了 Icinga 2 yum 存储库。
因此,我们可以使用 dnf 命令轻松安装 Icinga Web 2 和 Icinga CLI。
[root@icinga-2 ~]# dnf install -y icingacli icingaweb2 icingaweb2-selinux
Icinga Web 2 Web 应用程序以apache 用户身份运行,因此,我们需要调整SELinux 文件上下文,以便apache 用户可以编辑/etc/icingaweb2 目录中的Icinga Web 2 配置文件。
[root@icinga-2 ~]# semanage fcontext -a -t httpd_sys_rw_content_t /etc/icingaweb2 [root@icinga-2 ~]# restorecon -Rv /etc/icingaweb2 Relabeled /etc/icingaweb2 from system_u:object_r:etc_t:s0 to system_u:object_r:httpd_sys_rw_content_t:s0
为 Apache Web 服务器生成 Icinga Web 2 配置。
[root@icinga-2 ~]# icingacli setup config webserver apache Alias /icingaweb2 "/usr/share/icingaweb2/public" # Remove comments if you want to use PHP FPM and your Apache version is older than 2.4 #<IfVersion < 2.4> # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION= # <LocationMatch "^/icingaweb2/(.*\.php)$"> # ProxyPassMatch "fcgi://127.0.0.1:9000//usr/share/icingaweb2/public/" # </LocationMatch> #</IfVersion> <Directory "/usr/share/icingaweb2/public"> Options SymLinksIfOwnerMatch AllowOverride None DirectoryIndex index.php <IfModule mod_authz_core.c> # Apache 2.4 <RequireAll> Require all granted </RequireAll> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order allow,deny Allow from all </IfModule> SetEnv ICINGAWEB_CONFIGDIR "/etc/icingaweb2" EnableSendfile Off <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /icingaweb2/ RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] </IfModule> <IfModule !mod_rewrite.c> DirectoryIndex error_norewrite.html ErrorDocument 404 /icingaweb2/error_norewrite.html </IfModule> # Remove comments if you want to use PHP FPM and your Apache version # is greater than or equal to 2.4 # <IfVersion >= 2.4> # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION= # <FilesMatch "\.php$"> # SetHandler "proxy:fcgi://127.0.0.1:9000" # ErrorDocument 503 /icingaweb2/error_unavailable.html # </FilesMatch> # </IfVersion> </Directory>
重新启动 Apache 服务以应用新配置。
[root@icinga-2 ~]# systemctl restart httpd.service
在 CentOS 8 上运行 Web 设置以配置 Icinga Web 2
生成用于 Icinga web 2 设置的令牌。
[root@icinga-2 ~]# icingacli setup token create The newly generated setup token is: da04f0b87929cec8
在 Web 浏览器中打开 URL http://icinga-2.onitroad.com/icingaweb2/setup。
我们现在开始 Icinga Web 2 的网络设置。
在此处输入令牌,然后单击下一步。
选择要启用的模块,然后单击下一步。
检查并纠正是否有任何遗漏的要求。
选择我们喜欢的身份验证类型。
我们正在使用“数据库”身份验证类型。
定义参数以访问我们的 MySQL 数据存储并单击验证配置。
完成后,单击下一步。
为 Icinga Web 2 创建一个管理员用户,然后单击下一步。
根据要求自定义设置,然后单击下一步。
查看我们到目前为止所做的配置,然后单击下一步。
单击下一步。
定义参数以访问我们的 MySQL 数据存储并单击验证配置。
选择“本地命令文件”作为传输类型。
单击下一步。
单击下一步。
单击完成。
点击登录
以管理员用户身份登录。
在 CentOS 8 上安装 支持PHP 的 Apache Web 服务器
Icinga Web 2 是用于 Icinga 2 的基于 PHP 的 Web 界面。
因此,我们需要一个 PHP 应用服务器来部署它。
使用以下 dnf 命令安装 Apache Web 服务器和 PHP。
[root@icinga-2 ~]# dnf install -y httpd php-fpm php-ldap php-json
为 Apache Web 服务器添加一个默认页面。
这是强制性的,否则 Icinga 的 HTTP 服务将引发 403 禁止错误。
[root@icinga-2 ~]# echo "HomePage" > /var/www/html/index.html [root@icinga-2 ~]# chmod 755 /var/www/html/index.html
启动并启用 Apache 和 PHP 服务。
[root@icinga-2 ~]# systemctl enable --now httpd.service php-fpm.service Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service /lib/systemd/system/httpd.service. Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.servic sr/lib/systemd/system/php-fpm.service.
在 CentOS 8 防火墙中允许 Apache 服务。
[root@icinga-2 ~]# firewall-cmd --permanent --add-service=http success [root@icinga-2 ~]# firewall-cmd --reload success