在 CentOS 7 上使用 Icinga 2 和 Icingaweb 2 进行服务器监控
在此页
- 1。要求
- 2。初步说明
- 3。准备
- 检查网络连接
- 更改为root
- 安装初步软件
- 禁用 SELinux
- 更新系统并重启
- 安装额外的存储库
- 安装 Apache、php 并准备 php.ini
- 安装和配置 mariadb
- 为 icinga2 创建和填充数据库
- 修改ido-mysql.conf
- 在启动时启用并启动 icinga2
Icinga 2 是一款可扩展的开源监控软件。本教程描述了在 CentOS 7 服务器上安装 Icinga 2 和 Icingaweb。
一、要求
要安装这样的系统,您需要具备以下条件:
- Centos 7 最小服务器系统。这可以是按照 Centos 7.1 最小服务器教程中所述从头开始安装的服务器,也可以是安装了最小 Centos 7 安装程序的托管公司的虚拟服务器或根服务器。
- 快速的互联网连接。
2.初步说明
- 在本教程中,我使用主机名 icinga2.domain.tld,IP 地址为 192.168.250.100/24,网关为 192.168.250.254。这些设置可能因您而异,因此您必须在适当的地方替换它们。
- 此处显示的输出只是一个示例,可能会因您的系统而异,具体取决于您的基本系统和已安装的软件包。
- 数据库服务器将是 maria db,并将安装在同一台主机上。
- 用户管理员存在并且在 sudoers 列表中。
- 我们将在本教程中禁用 SELinux。
三、准备工作
以管理员身份登录
login as: administrator 's password: [ ~]$
检查网络连接
我们将测试我们的互联网连接是否建立以及名称解析是否正常工作:
ping www.google.de -c3
输出将类似于:
[ ~]$ ping www.google.de -c3 PING www.google.de (172.217.20.67) 56(84) bytes of data. 64 bytes from fra02s27-in-f3.1e100.net (172.217.20.67): icmp_seq=1 ttl=57 time=19.2 ms 64 bytes from fra02s27-in-f3.1e100.net (172.217.20.67): icmp_seq=2 ttl=57 time=19.3 ms 64 bytes from fra02s27-in-f3.1e100.net (172.217.20.67): icmp_seq=3 ttl=57 time=19.6 ms --- www.google.de ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 19.276/19.430/19.649/0.195 ms [ ~]$
更改为根
现在我们要扎根。为此,请输入:
sudo su
输出将类似于:
[ ~]$ sudo su We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for administrator: [ administrator]#
安装预备软件
我们现在将安装一些初步软件:
- deltarpm 将通过检查是否只有一个差异文件而不是整个包来降低下载量
- nano 是一个文本编辑器
- 需要 wget 从 URL 下载文件
- net-tools 需要对网络进程进行某些检查
- gcc 是 GNU 编译器
yum -y install deltarpm
输出将类似于:
Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): extras/7/x86_64/primary_db ... ... Total download size: 82 k Installed size: 209 k Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/deltarpm-3.6-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for deltarpm-3.6-3.el7.x86_64.rpm is not installed deltarpm-3.6-3.el7.x86_64.rpm | 82 kB 00:00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : deltarpm-3.6-3.el7.x86_64 1/1 Verifying : deltarpm-3.6-3.el7.x86_64 1/1 Installed: deltarpm.x86_64 0:3.6-3.el7 Complete!
yum -y install nano wget net-tools gcc
输出将类似于:
Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): extras/7/x86_64/primary_db ... ... Installed: gcc.x86_64 0:4.8.5-4.el7 nano.x86_64 0:2.3.1-10.el7 net-tools.x86_64 0:2.0-0.17.20131004git.el7 wget.x86_64 0:1.14-10.el7_0.1 Dependency Installed: cpp.x86_64 0:4.8.5-4.el7 glibc-devel.x86_64 0:2.17-106.el7_2.4 glibc-headers.x86_64 0:2.17-106.el7_2.4 kernel-headers.x86_64 0:3.10.0-327.13.1.el7 libmpc.x86_64 0:1.0.1-3.el7 mpfr.x86_64 0:3.1.1-4.el7 Dependency Updated: glibc.x86_64 0:2.17-106.el7_2.4 glibc-common.x86_64 0:2.17-106.el7_2.4 Complete!
禁用 SELinux
编辑 /etc/selinux/config
nano /etc/selinux/config
寻找
SELINUX=enforcing
改成
SELINUX=disabled
保存文件
更新系统并重启
现在我们将更新系统。
yum -y update && yum -y upgrade
这可能要花点时间。重启后。
reboot
4.安装icinga2和附加软件
安装额外的存储库
系统重新启动后,以管理员身份登录并再次成为 root 用户。
将目录更改为 /tmp
cd /tmp
安装 epel 仓库
yum install -y epel-release
安装 icinga 存储库
rpm --import http://packages.icinga.org/icinga.key
wget http://packages.icinga.org/epel/ICINGA-release.repo -O /etc/yum.repos.d/ICINGA-release.repo重建 yum 缓存(可能需要一些时间)
yum makecache
安装icinga2、icinga2 mysql连接器和nagios插件
yum install -y nagios-plugins-all icinga2 icinga2-ido-mysql icinga-idoutils-libdbi-mysql
安装 Apache、php 并准备 php.ini
yum install -y httpd
yum install -y php-cli php-pear php-xmlrpc php-xsl php-pdo php-soap php-gd php-ldap
编辑 php.ini
寻找
; Defines the default timezone used by the date functions ; http://php.net/date.timezone ;date.timezone =
改成
; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = "Europe/Berlin"
保存文件
在启动时启用 Apache
systemctl enable httpd
[ tmp]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
systemctl start httpd
检查 Apache 是否正在运行
netstat -nlp | grep 80
[ tmp]# netstat -nlp | grep 80 tcp6 0 0 :::80 :::* LISTEN 10360/httpd
安装和配置 mariadb
yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb
输出:
[ tmp]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
检查 mariadb 是否正在运行
netstat -nlp | grep 3306
输出:
[ tmp]# netstat -nlp | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11623/mysqld
为root用户设置密码
mysql -u root
输出:
[ tmp]# mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.47-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
[MariaDB [(none)]> use mysql
输出:
[MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mysql]>
[MariaDB [(mysql)]> update user set password=PASSWORD("root_password") where User='root';
输出:
update user set password=PASSWORD("root_password") where User='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
[MariaDB [(mysql)]> flush privileges;
输出:
MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec0
[MariaDB [(mysql)]> exit;
输出:
MariaDB [mysql]> exit; Bye
重新启动 MariaDB
systemctl restart mariadb
为 icinga2 创建和填充数据库
使用 root 密码登录 MySQL。
mysql -u root -p
输出:
[ tmp]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.47-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
[MariaDB [(none)]>CREATE DATABASE icinga2;
输出:
MariaDB [(none)]> CREATE DATABASE icinga2; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]>
[MariaDB [(none)]>GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga2.* TO 'icinga2'@'localhost' IDENTIFIED BY 'icinga2_password';
输出:
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga2.* TO 'icinga2'@'localhost' IDENTIFIED BY 'icinga2_password'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]>
[MariaDB [(none)]>flush privileges;;
输出:
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]>
[MariaDB [(none)]> exit;
输出:
MariaDB [none]> exit; Bye
填充数据库
mysql -u root -p icinga2 < /usr/share/icinga2-ido-mysql/schema/mysql.sql
修改 ido-mysql.conf
为了使 icinga2 连接到我们的 mariadb 数据库,我们必须修改 /etc/icinga2/ido-mysql.conf
nano /etc/icinga2/features-available/ido-mysql.conf
寻找
/** * The db_ido_mysql library implements IDO functionality * for MySQL. */ library "db_ido_mysql" object IdoMysqlConnection "ido-mysql" { //user = "icinga" //password = "icinga" //host = "localhost" //database = "icinga" }
改成
/** * The db_ido_mysql library implements IDO functionality * for MySQL. */ library "db_ido_mysql" object IdoMysqlConnection "ido-mysql" { user = "icinga2" password = "icinga2_password" host = "localhost" database = "icinga2" }
在启动时启用并启动 icinga2
在启动时启用 icinga2
systemctl enable icinga2
输出:
[ tmp]# systemctl enable icinga2 Created symlink from /etc/systemd/system/multi-user.target.wants/icinga2.service to /usr/lib/systemd/system/icinga2.service.
启动 icinga2
systemctl start icinga2
为了检查是否一切正常,我们将执行 tail -f /var/log/icinga2/icinga2.log。您可以通过按 CTRL-C 来停止输出。
tail -f /var/log/icinga2/icinga2.log
输出应该是这样的
[ tmp]# tail -f /var/log/icinga2/icinga2.log [2016-05-10 23:21:50 +0200] information/DbConnection: Resuming IDO connection: ido-mysql [2016-05-10 23:21:50 +0200] information/ConfigItem: Activated all objects. [2016-05-10 23:21:50 +0200] information/ConfigCompiler: Compiling config file: /var/lib/icinga2/modified-attributes.conf [2016-05-10 23:21:50 +0200] information/IdoMysqlConnection: MySQL IDO instance id: 1 (schema version: '1.14.0') [2016-05-10 23:21:50 +0200] information/IdoMysqlConnection: Finished reconnecting to MySQL IDO database in 0.201981 second(s).
使 icinga2 在开机时启动:
systemctl enable icinga2
输出:
[ tmp]# systemctl enable icinga2 Created symlink from /etc/systemd/system/multi-user.target.wants/icinga2.service to /usr/lib/systemd/system/icinga2.service.
启用 icinga2 命令模块:
icinga2 feature enable command
输出:
[ tmp]# icinga2 feature enable command Enabling feature command. Make sure to restart Icinga 2 for these changes to take effect.
重启icinga2
systemctl restart icinga2