在CentOS 7上使用Icinga 2和Icingaweb 2进行服务器监控

Icinga 2是可扩展的OpenSource监控软件。 本教程将介绍在CentOS 7服务器上安装Icinga 2和Icingaweb。

要求

要安装此类系统,您将需要以下信息:

  • Centos 7最小服务器系统。 这可以是Centos 7.1最小服务器教程中所述的从头开始安装的服务器,也可以是安装了Centos 7安装程序的托管公司的虚拟服务器或根服务器。
  • 快速的互联网连接。

初步笔记

  • 在本教程中,我使用IP地址为192.168.250.100/24的主机名icinga2.domain.tld和网关192.168.250.254。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。
  • 这里显示的输出只是一个示例,可能会因系统而异,具体取决于您的基本系统和已安装的软件包。
  • 数据库服务器将是maria db并将安装在同一台主机上。
  • 存在用户管理员,位于sudoers列表中。
  • 我们将禁用本教程的SELinux。

准备

以管理员身份登录

login as: administrator
administrator@192.168.250.100's password:
[administrator@icinga2 ~]$

检查网络连接

我们将测试我们的互联网连接是否建立,名称解析是否正常工作:

ping www.google.de -c3

输出将如下:

[administrator@icinga2 ~]$ 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
[administrator@icinga2 ~]$

改为root

现在我们将自己成长为根。 要这样做:

sudo su

输出将如下:

[administrator@icinga2 ~]$ 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:
[root@icinga2 administrator]#

安装初步软件

我们现在将安装一些初步软件:

  • 通过检查是否只有一个差分文件,而不是整个包,deltarpm将降低要下载的数量
  • nano是一个文本编辑器
  • 需要wget从URL下载文件
  • 对网络进程进行某些检查需要使用网络工具
  • 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) <security@centos.org>"
 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
[root@icinga2 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
[root@icinga2 tmp]# netstat -nlp | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      10360/httpd

安装和配置mariadb

yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb

输出:

[root@icinga2 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

输出:

[root@icinga2 tmp]# netstat -nlp | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      11623/mysqld

设置用户'root'的密码

mysql -u root

输出:

[root@icinga2 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创建和填充数据库

使用密码登录到MySQL。

mysql -u root -p

输出:

[root@icinga2 tmp]# [root@icinga2 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

输出:

[root@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

为了检查一切是否正常工作,我们将做尾巴-f /var/log/icinga2/icinga2.log。 您可以通过点击CTRL-C来停止输出。

tail -f /var/log/icinga2/icinga2.log

输出应该是这样的

[root@icinga2 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

输出:

[root@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

输出:

[root@icinga2 tmp]# icinga2 feature enable command
Enabling feature command. Make sure to restart Icinga 2 for these changes to take effect.

重新启动icinga2

systemctl restart icinga2
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏