웹사이트 검색

CentOS 8에 Icinga 2 모니터링 도구를 설치하는 방법


이 페이지에서

  1. 전제 조건
  2. 저장소 설정
  3. LAMP 스택 설치 및 구성
  4. Icinga2 설치 및 구성
  5. Icingaweb2 설치 및 구성
  6. 웹 인터페이스를 통해 Icinga Web 2 구성\n
  7. Icinga 2 및 Icinga Web 2 설치 확인\n
  8. 결론

모니터링은 서버 인프라 및 데이터 센터의 가장 중요한 구성 요소 중 하나입니다. 서버에서 발생할 문제와 문제를 감지하여 해당 문제를 더 빨리 해결할 수 있도록 도와줍니다. 사용할 수 있는 몇 가지 오픈 소스 모니터링 도구가 있으며 가장 인기 있는 도구 중 하나는 Icinga 2입니다.

Icinga는 인기 있는 Nagios 모니터링 도구의 포크로 만들어졌으며 이제 처음부터 C++로 재작성되었습니다. Nagios 프로젝트의 포크로서 Icinga는 icinga director, icinga 모듈 및 icinga 플러그인을 포함한 추가 도구 및 기능과 함께 제공됩니다. 또한 하나의 대시보드에서 여러 Icinga 인스턴스를 관리할 수 있는 분산 모니터링을 지원합니다.

이 튜토리얼에서는 CentOS 8 서버에서 Apache2 및 MariaDB와 함께 Icinga2를 설치하고 구성하는 방법을 단계별로 보여줍니다.

전제 조건

  • CentOS 8 서버. 최신 버전으로 업데이트되었는지 확인하십시오.\n
  • 최소 2GB RAM 및 2코어. 더 있으면 더 좋을 것입니다.
  • Sudo 권한이 있는 사용자.\n

리포지토리 설정

먼저 epel, remi 및 icinga 리포지토리를 centos 8 시스템에 추가해야 합니다. 그런 다음 dnf "config-manager" 도구를 설치하고 해당 도구를 사용하여 "PowerTools" 저장소를 활성화해야 합니다.

1. 다음 명령을 실행하여 centos 8 서버용 epel 및 remi 리포지토리를 추가합니다.

sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

2. 이제 아래 명령을 실행하여 centos 8 시스템용 Icinga 리포지토리를 다운로드하고 추가합니다.

sudo dnf install -y https://packages.icinga.com/epel/icinga-rpm-release-8-latest.noarch.rpm

3. 그런 다음 다음 명령을 실행하여 dnf config-manager 도구를 설치하고 PowerTools 리포지토리를 활성화합니다.

sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager --set-enabled powertools

4. 모든 프로세스가 완료되면 아래 명령을 사용하여 시스템에서 활성화된 모든 리포지토리를 확인합니다.

sudo dnf repolist

아래와 유사한 출력이 표시되고 epel, remi, icinga-* 및 powertools 리포지토리가 목록에 있는지 확인합니다.

repo id                                                                                              repo name
appstream                                                                                            CentOS Linux 8 - AppStream
baseos                                                                                               CentOS Linux 8 - BaseOS
epel                                                                                                 Extra Packages for Enterprise Linux 8 - x86_64
epel-modular                                                                                         Extra Packages for Enterprise Linux Modular 8 - x86_64
extras                                                                                               CentOS Linux 8 - Extras
icinga-stable-release                                                                                ICINGA (stable release for epel)
powertools                                                                                           CentOS Linux 8 - PowerTools
remi-modular                                                                                         Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                                                                                            Safe Remi's RPM repository for Enterprise Linux 8 - x86_64

LAMP 스택 설치 및 구성

Icinga 모니터링 도구에는 모든 모니터링 작업을 처리하는 "icinga2"와 Icinga 스택을 관리할 수 있는 PHP 기반의 강력하고 깨끗하며 빠른 웹 애플리케이션인 "icingaweb2"의 두 가지 주요 구성 요소가 있습니다. 웹 브라우저. 이제 centos 8 시스템에 기본 LAMP 스택을 설치 및 구성합니다.

1. 아래 명령을 사용하여 PHP 7.4용 remi 모듈을 활성화합니다.

sudo dnf module enable -y php:remi-7.4

다음으로 다음 명령을 실행하여 기본 LAMP 스택 패키지를 설치합니다.

sudo dnf install -y httpd mariadb-server mariadb php php-cli php-devel php-pear make php-mysqlnd php-pecl-imagick php-pecl-imagick-devel

이제 apache(centos의 httpd)와 mariadb 서비스를 모두 시작하고 둘 다 시스템 부팅 시 시작되도록 활성화합니다.

sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb

다음과 유사한 출력이 표시되고 apache 및 mariadb 서비스가 시작되고 활성화됩니다.

# Apache started and enabled
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

# MariaDB started and enabled
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.

2. 그런 다음 아래 명령을 실행하여 mariadb 루트 암호를 설정하고 보안상의 이유로 기본 데이터베이스 test 및 익명 사용자를 제거하고 루트 사용자에 대한 원격 로그인도 비활성화합니다.

sudo mysql_secure_installation

다음은 유사한 출력 결과입니다. mariadb 루트 사용자에 대한 강력한 새 암호를 입력하고 Y를 입력하여 모든 작업을 확인하십시오.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

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): PRESS ENTER
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: TYPE STRONG PASSWORD
Re-enter new password: TYPE STRONG 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!

Icinga2 설치 및 구성

이제 Icinga 자체의 주요 구성 요소를 설치 및 구성하게 됩니다. 이 단계에서는 icinga2 패키지 설치, 새 데이터베이스 및 사용자 생성, 데이터베이스 스키마 가져오기 및 Icinga REST API 설정을 다룹니다.

1. 다음 명령을 실행하여 Icinga 모니터링 도구 패키지를 설치합니다.

sudo dnf install -y icinga2 nagios-plugins-all

그런 다음 icinga2 서비스를 시작하고 활성화한 다음 Icinga 서비스 상태를 확인합니다.

sudo systemctl enable --now icinga2
sudo systemctl status icinga2

다음과 유사한 출력이 표시되면 Icinga 서비스가 실행 중입니다.

# Icinga2 started and enabled
Created symlink /etc/systemd/system/multi-user.target.wants/icinga2.service → /usr/lib/systemd/system/icinga2.service.

# Icinga2 status running
? icinga2.service - Icinga host/service/network monitoring system
   Loaded: loaded (/usr/lib/systemd/system/icinga2.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-07-18 02:38:19 UTC; 6s ago
  Process: 31290 ExecStartPre=/usr/lib/icinga2/prepare-dirs /etc/sysconfig/icinga2 (code=exited, status=0/SUCCESS)
 Main PID: 31298 (icinga2)
    Tasks: 13 (limit: 4964)
   Memory: 20.9M
   CGroup: /system.slice/icinga2.service
           ??31298 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
           ??31319 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
           ??31324 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log

2. 다음으로, centos 8 시스템에서 SELinux를 실행 중이면 icinga2-selinux 패키지를 설치해야 합니다. 그러나 SELinux가 비활성화된 경우 이 부분을 건너뜁니다.

아래 명령어를 실행하여 SELinux 상태를 확인합니다.

sudo sestatus

다음과 유사한 출력이 표시되면 SELinux가 활성화된 것입니다. 그렇지 않으면 출력이 비활성화되어 SELinux 부분을 건너뛸 수 있습니다.

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      32

이제 아래 명령을 사용하여 icinga2-selinux 패키지를 설치합니다.

sudo dnf install -y icinga2-selinux

그런 다음 icinga2 서비스를 다시 시작하여 새 구성을 적용하고 SELinux 컨텍스트에서 Icinga가 실행 중인지 확인합니다.

sudo systemctl restart icinga2
ps -eZ | grep icinga2

아래는 비슷한 출력입니다.

system_u:system_r:icinga2_t:s0    33479 ?        00:00:00 icinga2
system_u:system_r:icinga2_t:s0    33499 ?        00:00:00 icinga2
system_u:system_r:icinga2_t:s0    33504 ?        00:00:00 icinga2

3. 다음으로 다음 명령을 사용하여 icinga2용 IDO MySQL 백엔드를 설치합니다.

sudo dnf install -y icinga2-ido-mysql

이제 아래 명령을 실행하여 MySQL 셸에 로그인하고 루트 암호를 입력합니다.

sudo mysql -u root -p

아래의 mysql 쿼리를 사용하여 icinga2 서비스에 대한 새 데이터베이스 및 사용자를 생성합니다.

MariaDB [(none)]> CREATE DATABASE icinga;
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icingapassdb';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

이제 아래의 mysql 명령을 실행하여 icinga2-ido-mysql 데이터베이스 스키마를 icinga 데이터베이스로 가져오고 mariadb 루트 암호의 암호를 입력합니다.

sudo mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql

그런 다음 아래 명령을 사용하여 icinga2-ido-mysql 기능을 활성화하고 icinga2 서비스를 다시 시작하여 새 구성을 적용합니다.

sudo icinga2 feature enable ido-mysql
sudo systemctl restart icinga2

그러면 아래 그림과 유사한 출력이 표시됩니다.

4. 다음으로 icinga2 REST API 구성 및 인증서를 생성해야 합니다. icingaweb2는 확인 일정 변경, 개체 세부 정보 쿼리 등과 같은 모니터링 작업과 관련된 작업을 보내려면 REST API가 필요합니다.

아래의 icinga2 명령을 실행하여 새 API 사용자, 구성 및 TLS 인증서를 생성합니다.

sudo icinga2 api setup

다음과 유사한 출력이 표시됩니다. 암호가 있는 새 사용자 루트는 /etc/icinga2/conf.d/api-users.conf 구성 파일에서 사용할 수 있고 TLS 인증서는 /var/lib/icinga2에서 사용할 수 있습니다. /certs/ 디렉터리.

information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca//ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca//ca.crt'.
information/cli: Generating new CSR in '/var/lib/icinga2/certs//centos8.csr'.
information/base: Writing private key to '/var/lib/icinga2/certs//centos8.key'.
information/base: Writing certificate signing request to '/var/lib/icinga2/certs//centos8.csr'.
information/cli: Signing CSR with CA and writing certificate to '/var/lib/icinga2/certs//centos8.crt'.
information/pki: Writing certificate to file '/var/lib/icinga2/certs//centos8.crt'.
information/cli: Copying CA certificate to '/var/lib/icinga2/certs//ca.crt'.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Reading '/etc/icinga2/icinga2.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Updating 'NodeName' constant in '/etc/icinga2/constants.conf'.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating 'ZoneName' constant in '/etc/icinga2/constants.conf'.
information/cli: Backup file '/etc/icinga2/constants.conf.orig' already exists. Skipping backup.
Done.

Now restart your Icinga 2 daemon to finish the installation!

선택적으로 새 API 사용자를 수동으로 추가하려면 아래와 같이 nano 편집기 명령을 사용하여 구성 /etc/icinga2/conf.d/api-users.conf를 편집합니다.

sudo nano /etc/icinga2/conf.d/api-users.conf

다음 샘플 구성을 아래와 같이 붙여넣고 API 사용자, 비밀번호, 정의 권한을 필요에 맞게 정의했는지 확인합니다.

object ApiUser "icingaweb2" {
  password = "Wijsn8Z9eRs5E25d"
  permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}

마지막으로 다음 명령으로 icinga2 서비스를 다시 시작하여 새 구성을 적용합니다.

sudo systemctl restart icinga2

Icingaweb2 설치 및 구성

이 단계에서는 데이터베이스 설정 및 설치 토큰 생성을 포함하여 icingaweb2 웹 애플리케이션을 설치 및 구성합니다.

1. 다음 명령을 실행하여 icingaweb2 패키지를 설치합니다.

sudo dnf install -y icingaweb2 icingacli

설치하는 동안 icingaweb2에 대한 새로운 Apache 구성이 생성됩니다. 다음 명령을 사용하여 새 구성을 확인합니다.

cat /etc/httpd/conf.d/icingaweb2.conf

아래는 보게 될 구성입니다.

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=$1
#    <LocationMatch "^{urlPath}/(.*\.php)$">
#        ProxyPassMatch "fcgi://127.0.0.1:9000/{documentRoot}/$1"
#    </LocationMatch>
#</IfVersion>

<Directory "/usr/share/icingaweb2/public">
    Options SymLinksIfOwnerMatch
    AllowOverride None
.......

새 구성을 적용하려면 아래 명령을 사용하여 apache/httpd 서비스를 다시 시작하십시오.

sudo systemctl restart httpd

2. 그런 다음 다음 명령을 입력하여 mysql 셸에 로그인합니다.

sudo mysql -u root -p

아래의 일부 mysql 쿼리를 실행하여 icingaweb2에 대한 새 데이터베이스 및 사용자를 생성합니다.

MariaDB [(none)]> CREATE DATABASE icingaweb2;
MariaDB [(none)]> GRANT ALL ON icingaweb2.* TO IDENTIFIED BY 'icingaweb2passdb';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

3. 그런 다음 다음 명령을 사용하여 다음 단계에서 설치를 위한 icingaweb2 설치 토큰을 생성합니다.

sudo icingacli setup token create
sudo icingacli setup token show

다음 출력으로 표시됩니다. icinga2 설치 토큰을 메모에 복사하십시오.

# Generated setup token
The newly generated setup token is: 41e33db4cf0c5617

# Show generated token
The current setup token is: 41e33db4cf0c5617

웹 인터페이스를 통한 Icinga Web 2 구성

이제 웹 브라우저와 URL http://SERVER-IP/icingaweb2/setup을 열면 icinga2 설치 페이지가 나타납니다.

1. 상자에 icingaweb2 설정 토큰을 붙여넣고 다음을 클릭합니다.

2. 여기에서 Icinga 모듈을 기본값으로 두고 다음을 클릭합니다.

3. 이제 모든 icingaweb2 시스템 요구 사항이 "녹색" 색상인지 확인한 후 다음 버튼을 클릭합니다.

4. 백엔드 인증을 기본 데이터베이스로 두고 다음을 클릭합니다.

5. icingaweb2의 데이터베이스 이름, 사용자 이름 및 암호를 입력하고 다음을 다시 클릭합니다.

6. 인증 백엔드 이름을 기본 icingaweb2로 두고 다음을 클릭합니다.

7. 이제 새 사용자 및 암호 관리를 입력하고 다음을 클릭합니다.

8. 애플리케이션 및 로그 구성을 기본값으로 두고 다음을 클릭합니다.

9. 모든 구성을 다시 확인한 후 다음을 클릭하여 계속합니다.

10. 이제 다음을 클릭하여 icinga2 모니터링 모듈을 구성합니다.

11. icinga2-ido-mysql의 데이터베이스 이름, 사용자 이름 및 암호를 입력한 다음 구성 확인 버튼을 클릭합니다.

There is current no icinga instance write to the IDO와 같은 오류가 있는 경우. icinga 인스턴스가 구성되어 있고 IDO에 쓸 수 있는지 확인하고 터미널로 돌아가 구성을 수동으로 편집하십시오.

다음 명령을 실행하여 IDO 구성을 편집합니다.

sudo nano /etc/icinga2/features-available/ido-mysql.conf

아래와 같이 ido mysql 구성을 복사하여 붙여넣습니다.

object IdoMysqlConnection "ido-mysql" {
user = "icinga", password = "icingapassdb", host = "localhost", database = "icinga" }

이제 Ctrl+x를 누른 다음 y를 누른 다음 Enter를 눌러 파일을 저장합니다.

그런 다음 다음 명령을 사용하여 Icinga2 서비스를 다시 시작하십시오.

sudo systemctl restart icinga2

이제 웹 브라우저로 돌아가 유효성 검사 건너뛰기 옵션을 활성화한 후 다시 다음을 클릭합니다.

12. 이제 로컬 명령 파일 전송 유형을 선택하고 다음을 클릭합니다.

13. 모니터링 보안 구성을 기본값으로 두고 다음을 클릭합니다.

14. Icinga 설치 구성을 다시 확인하고 마침을 클릭하여 계속합니다.

15. 설치에 성공하면 아래 그림과 같은 출력이 나타납니다. 그런 다음 Icinga Web 2에 로그인 버튼을 클릭합니다.

Icinga 2 및 Icinga Web 2 설치 확인

1. Icinga 관리자 사용자 및 암호를 입력한 다음 로그인 버튼을 클릭합니다.

2. 이제 아래와 비슷한 페이지가 나타납니다.

대시보드에서 볼 수 있듯이 icinga2 모니터링 도구에 의해 자동으로 감지되는 일부 서비스가 있습니다. 녹색이 있는 서비스는 건강 상태를 의미하고 노란색이 있는 서비스는 확인이 필요한 경고를 의미합니다. 오류 서비스는 빨간색으로 표시됩니다.

결론

튜토리얼을 완료하면서 LAMP Stack이 있는 최신 CentOS 8 서버에서 icinga2 모니터링 도구의 설치 및 구성에 대해 배웠습니다. icinga2 설치는 각 단계에 집중해야 하며 가장 중요한 것은 맹목적으로 명령을 실행하는 것이 아니라 자신이 무엇을 하고 있는지 알고 있다는 것입니다.