2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Zabbix7.0 LTS をインストールしてみた 【AlmaLinux9.5 + MySQL8.0】

Posted at

はじめに

こんにちは、登山大好き 7mountains です!
そろそろ山が恋しくなってきたこの頃、今年はどの山に登ろうかと今からワクワクしています。

今回は社内で Zabbix の検証機を構築するべく、インストールを行っていきます。
公式の手順に沿って進めていきましょう!

環境

検証環境なので1台にすべてインストールします
エージェント は Zabbix Agent2 をインストールします
作業はすべて root で行っています

項目 環境
ホスト名 AlmaLinux001
OS AlmaLinux 9.5
Zabbix Server 7.0 LTS
DB MySQL 8.0.41
Web Apache 2.4.62

事前準備

EPEL リポジトリの編集

EPEL で提供されている Zabbix パッケージがインストールされないように、
/etc/yum.repos.d/epel.repo ファイルを編集して、excludepkgs=zabbix* を追記します
※EPEL リポジトリをインストールしていない場合は次の MySQL と Apache のインストールへ進んでください

/etc/yum.repos.d/epel.repo
[root@AlmaLinux001 ~]# vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 9 - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/9/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-9&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
excludepkgs=zabbix*   ←--ここに追記

[epel-debuginfo]
..... 省略 .....

MySQL と Apache のインストール

公式の手順には MySQL と Apache がインストールされていることが前提として記載されているので、最初にインストールします

MySQL と Apache をインストール
[root@AlmaLinux001 ~]# dnf install -y mysql-server httpd

MySQL の起動

MySQL の起動と、自動起動の設定を行います

MySQL の起動
[root@AlmaLinux001 ~]# systemctl enable --now mysqld.service   ←-- 自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl status mysqld.service         ←-- 状態確認
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-04-16 14:57:15 JST; 41min ago
    Process: 816 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 916 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 1198 (mysqld)
..... 省略 .....

mysql_secure_installation の実行

MySQL の初期状態だと、root ユーザのパスワードが設定されていません
セキュリティ的によろしくないので、パスワードを設定します

root ユーザのパスワード変更の他、不要なユーザやデータベースを削除するコマンドです
パスワードは、8文字以上で英数大文字小文字と記号が含まれていないとポリシー違反で弾かれますので、ご注意ください
パスワードポリシーを無視したい場合は --use-default オプションなしで実行してくださいね

mysql_secure_installation の実行
[root@AlmaLinux001 ~]# mysql_secure_installation --use-default
..... 省略 .....
Please set the password for root here.

New password:               ←-- 新しいパスワードを入力

Re-enter new password:      ←-- 新しいパスワードを再入力

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
..... 省略(不要なデータベースやユーザを削除) .....
All done!

インストールしていく

Zabbix リポジトリのインストール

Zabbix リポジトリのインストールを行います

[root@AlmaLinux001 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/7.0/alma/9/x86_64/zabbix-release-latest-7.0.el9.noarch.rpm
[root@AlmaLinux001 ~]# dnf clean all

Zabbix Server のインストール

Zabbix server, frontend, agent2 をインストールします
公式手順に記載はありませんが、後の動作検証用にZabbix-Get もインストールします

Zabbix Server のインストール
[root@AlmaLinux001 ~]# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2 zabbix-get

プラグインのインストール

Zabbix Agent2 はプラグインのインストールが必要なので、お忘れなく!

Zabbix Agnet2 プラグインのインストール
[root@AlmaLinux001 ~]# dnf install zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-mssql zabbix-agent2-plugin-postgresql

データベースとユーザの作成

初期データベースを作成します
MySQL に Zabbix 用のデータベース zabbix と、ユーザ zabbix を作成します
公式の手順ではユーザ zabbix のパスワードは、 password となっていますので、適宜変更してください

初期データベースの作成
[root@AlmaLinux001 ~]# cat /var/log/mysql/mysqld.log | grep passwordmysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; ←-- データベースの作成
Query OK, 1 row affected (0.01 sec)

mysql> create user zabbix@localhost identified by '<パスワード>';         ←-- ユーザの作成(パスワードの指定箇所)
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;             ←-- 権限設定
Query OK, 0 rows affected (0.00 sec)

mysql> set global log_bin_trust_function_creators = 1;                   ←-- SUPER権限が無くても関数を作成できるように log_bin_trust_function_creators = 1 を設定(後で元に戻します)
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit;
Bye

データベース用スキーマとデータのインポート

データベース用のスキーマと、データをインポートします(時間がかかります)

スキーマとデータのインポート
[root@AlmaLinux001 ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
Enter password:        ←-- MySQLのユーザ zabbix のパスワードを入力

log_bin_trust_function_creators オプションを無効化

スキーマとデータのインポートが完了したら、log_bin_trust_function_creators オプションを無効化します

log_bin_trust_function_creators を無効化
[root@AlmaLinux001 ~]# mysql -uroot -p
Enter password:        ←-- MySQLのユーザ root のパスワードを入力
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set global log_bin_trust_function_creators = 0;   ←-- log_bin_trust_function_creators を元に戻す
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit;
Bye

SELinux の設定

SELinux のポリシーを追加します
※SELinux を無効にしている場合は不要です

SELinux ポリシー追加
[root@AlmaLinux001 ~]# setsebool -P httpd_can_connect_zabbix on
[root@AlmaLinux001 ~]# setsebool -P httpd_can_network_connect_db on

設定していく

zabbix_server.conf の設定

Zabbix Server の設定ファイルに、MySQLのユーザ zabbix のパスワードを登録します

/etc/zabbix/zabbix_server.conf
[root@AlmaLinux001 ~]# vi /etc/zabbix/zabbix_server.conf
..... 省略 .....
### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=<パスワード>     ←-- MySQLのユーザ zabbix のパスワードを入力
..... 省略 .....

Zabbix Server の起動

Zabbix Serverの起動と、自動起動の設定を行います

Zabbix Serverの起動
[root@AlmaLinux001 ~]# systemctl enable --now zabbix-server.service   ←-- 自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl status zabbix-server.service         ←-- 状態確認
● zabbix-server.service - Zabbix Server
     Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; preset: disabled)
     Active: active (running) since Tue 2025-04-15 16:18:30 JST; 37min ago
    Process: 1861 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
   Main PID: 1863 (zabbix_server)
..... 省略 .....

Apache の起動と SSLの設定

公式ドキュメントのベストプラクティスでも、Zabbixの管理画面(フロントエンド)のSSL設定が推奨されています

httpd の設定

コンフィグファイルをバックアップして、下記に置き換えます

/etc/httpd/conf/httpd.conf
[root@AlmaLinux001 ~]# mv -i /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
[root@AlmaLinux001 ~]# vi /etc/httpd/conf/httpd.conf
-------------------- 下の行から --------------------
ServerTokens Prod
ServerSignature Off
TraceEnable Off
AddDefaultCharset UTF-8
Header set X-XSS-Protection "1; mode=block"
Header always append X-Content-Type-Options nosniff
#Header always set X-Frame-Options "SAMEORIGIN"

EnableSendfile on
HostnameLookups Off

ServerRoot "/etc/httpd"

Timeout 60
ProxyTimeout 60

KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 5

ServerLimit 256

ThreadsPerChild 25
ThreadLimit 25

StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
MaxRequestWorkers 400
MaxConnectionsPerChild 10000

Listen 80
# LoadModule foo_module modules/mod_foo.so
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
ServerName localhost:80

<Directory />
    AllowOverride none
    Require all denied
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

IncludeOptional conf.d/*.conf

<VirtualHost *:80>
    ServerName zabbix.example.com
    Redirect permanent / https://zabbix.example.com/
</VirtualHost>
-------------------- 上の行まで --------------------

自己証明書を作成

社内の検証機なので自己証明書を使いますが、本番機は公的証明書の利用をご検討ください

秘密鍵の作成
[root@AlmaLinux001 ~]# openssl ecparam -name prime256v1 -genkey -out server.key
SSLサーバー証明書の作成(有効期限 5 年)
[root@AlmaLinux001 ~]# openssl req -new -x509 -days 1825 -key server.key -subj '/C=JP/CN=zabbix.example.com' -out server.crt
秘密鍵とSSL証明書を移動
[root@AlmaLinux001 ~]# mv -i server.key /etc/pki/tls/private/
[root@AlmaLinux001 ~]# mv -i server.crt /etc/pki/tls/certs/
パーミッションを変更
[root@AlmaLinux001 ~]# chmod 600 /etc/pki/tls/private/server.key
[root@AlmaLinux001 ~]# chmod 600 /etc/pki/tls/certs/server.crt
[root@AlmaLinux001 ~]# chown root:root /etc/pki/tls/private/server.key
[root@AlmaLinux001 ~]# chown root:root /etc/pki/tls/certs/server.crt

SELinux を有効にしている場合は、秘密鍵とSSL証明書に正しいセキュリティコンテキストをつけておきましょう

SELinux を有効にしている場合
[root@AlmaLinux001 ~]# restorecon /etc/pki/tls/private/server.key
[root@AlmaLinux001 ~]# restorecon /etc/pki/tls/certs/server.crt

SSL の設定

SSL モジュールをインストールします

SSL モジュール
[root@AlmaLinux001 ~]# dnf -y install mod_ssl
Last metadata expiration check: 0:51:00 ago on Tue 15 Apr 2025 09:41:33 AM JST.
Dependencies resolved.
=====================================================================================================================
 Package                 Architecture           Version                              Repository                 Size
=====================================================================================================================
Installing:
 mod_ssl                 x86_64                 1:2.4.62-1.el9_5.2                   appstream                 109 k
..... 省略 .....
Complete!

続いてコンフィグファイルをバックアップして、下記に置き換えます

/etc/httpd/conf.d/ssl.conf
[root@AlmaLinux001 ~]# mv -i /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.org
[root@AlmaLinux001 ~]# vi /etc/httpd/conf.d/ssl.conf
-------------------- 下の行から --------------------
Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(1024000)
SSLSessionCacheTimeout 3600
SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
SSLStrictSNIVHostCheck off

SSLProtocol -all +TLSv1.2 +TLSv1.3

SSLCipherSuite "\
ECDHE-ECDSA-AES128-GCM-SHA256 \
ECDHE-ECDSA-CHACHA20-POLY1305 \
ECDHE-ECDSA-AES256-GCM-SHA384 \
ECDHE-ECDSA-AES128-SHA \
ECDHE-ECDSA-AES256-SHA \
ECDHE-ECDSA-AES128-SHA256 \
ECDHE-ECDSA-AES256-SHA384 \
ECDHE-RSA-AES128-GCM-SHA256 \
ECDHE-RSA-CHACHA20-POLY1305 \
ECDHE-RSA-AES256-GCM-SHA384 \
ECDHE-RSA-AES128-SHA \
ECDHE-RSA-AES256-SHA \
ECDHE-RSA-AES128-SHA256 \
ECDHE-RSA-AES256-SHA384 \
DHE-RSA-AES128-GCM-SHA256 \
DHE-RSA-CHACHA20-POLY1305 \
DHE-RSA-AES256-GCM-SHA384 \
DHE-RSA-AES128-SHA \
DHE-RSA-AES256-SHA \
DHE-RSA-AES128-SHA256 \
DHE-RSA-AES256-SHA256"

SSLHonorCipherOrder on
SSLCompression off

SSLUseStapling On
SSLStaplingReturnResponderErrors off
SSLStaplingCache shmcb:/run/httpd/stapling_cache(128000)

<VirtualHost *:443>
    ServerName zabbix.example.com
    DocumentRoot "/var/www/html"
    
    Protocols h2 http/1.1

    <Directory "/var/www/html">
        Options FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

   SSLEngine on
   Header always set Strict-Transport-Security "max-age=31536000"
   SSLCertificateFile /etc/pki/tls/certs/server.crt
   SSLCertificateKeyFile /etc/pki/tls/private/server.key
   # SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt

    Header set Content-Security-Policy: "default-src 'self' *.openstreetmap.org; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; img-src 'self' data: *.openstreetmap.org; style-src 'self' 'unsafe-inline'; base-uri 'self'; form-action 'self';"

    SetEnvIf Request_URI "\.(gif|jpg|png|svg|css|js)$" nolog
    ErrorLog logs/error_log
    CustomLog logs/access_log combined env=!nolog
</VirtualHost>
-------------------- 上の行まで --------------------

Apache httpd の自動起動を設定して起動します

Apache httpd の起動
[root@AlmaLinux001 ~]# systemctl enable --now httpd   ←-- 自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl status httpd         ←-- 状態確認
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/httpd.service.d
             mqphp-fpm.conf
     Active: active (running) since Wed 2025-04-16 09:03:07 JST; 1h 3min ago
       Docs: man:httpd.service(8)
..... 省略 .....
[root@AlmaLinux001 ~]#

インデックスファイルの配置

こちらも公式ドキュメントにはありませんが、ドキュメントルート直下にインデックスファイルが配置されていないため、ブラウザからホスト名やIPアドレスでアクセスするとテストページが表示されてしまいます
必須ではありませんが、インデックスファイルを配置することをオススメします

インデックスファイル
[root@AlmaLinux001 ~]# vi /var/www/html/index.php
-------------------- 下の行から --------------------
<?php
header('Location: /zabbix/');
-------------------- 上の行まで --------------------

PHP の設定と起動

PHP の設定を行います

PHP の設定
[root@AlmaLinux001 ~]# vi /etc/php.ini
..... 省略 .....
;;;;;;;;;;;;;;;;;
; Miscellaneous ;
;;;;;;;;;;;;;;;;;

; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header).  It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
; http://php.net/expose-php
; expose_php = On
expose_php = Off               ←-- expose_php を On から Off に変更
..... 省略 .....
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[CLI Server]
; Whether the CLI web server uses ANSI color coding in its terminal output.
cli_server.color = On

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = 'Asia/Tokyo'   ←-- タイムゾーンを指定
..... 省略 .....

PHP の自動起動の設定と起動を行います

PHP の自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl enable --now php-fpm.service   ←-- 自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl status php-fpm.service         ←-- 状態確認
● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-04-16 09:03:07 JST; 1h 19min ago
   Main PID: 816 (php-fpm)
..... 省略 .....

Zabbix Agent2 の起動

Zabbix Agent2 の自動起動の設定と、起動後の動作確認を行います

Zabbix Agent2 起動と動作確認
[root@AlmaLinux001 ~]# systemctl enable --now zabbix-agent2.service   ←-- 自動起動の設定と起動
[root@AlmaLinux001 ~]# systemctl status zabbix-agent2.service         ←-- 状態確認
● zabbix-agent2.service - Zabbix Agent 2
     Loaded: loaded (/usr/lib/systemd/system/zabbix-agent2.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-04-16 09:03:07 JST; 1h 26min ago
   Main PID: 819 (zabbix_agent2)
..... 省略 .....
[root@AlmaLinux001 ~]# cd /bin/
[root@AlmaLinux001 bin]# zabbix_get -s 127.0.0.1 -k agent.version    ←-- zabbix_getコマンドでAgentのバージョンを確認するコマンド
7.0.11

Firewall の設定

HTTP(80/tcp) と HTTPS(443/tcp) を開放します
※Firewall を無効化している場合は不要です

Firewall の設定
[root@AlmaLinux001 ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@AlmaLinux001 ~]# firewall-cmd --add-port=443/tcp --permanent
success
[root@AlmaLinux001 ~]# firewall-cmd --reload
success
[root@AlmaLinux001 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: cockpit dhcpv6-client ssh
  ports: 80/tcp 443/tcp              ←-- この表示があれば正しく設定されています
  ..... 省略 .....

Zabbix の初期設定

ブラウザでZabbixサーバへアクセスして初期設定を行います
https://AlmaLinux001.local/zabbix/

日本語で設定していきますので、デフォルトの言語を 日本語 (ja_JP) を選択して、次のステップ ボタンをクリックします
WS000001-1.JPG

前提条件のチェックがすべて OK であることを確認します
WS000002-1.JPG

データベースのパスワードを入力し、次のステップ ボタンをクリックします
WS000003-1.JPG

Zabbixサーバー名 に適当なホスト名を入力、デフォルトのタイムゾーンは (UTC+9:00) Asia/Tokyo を選択し、デフォルトのテーマ はお好きなテーマを選択してください
WS000004-1.JPG

設定パラメータの確認画面が表示されますので、問題なければ 次のステップ ボタンをクリックします
WS000005-1.JPG

終了 ボタンをクリックすれば、初期設定は完了です
WS000006-1.JPG

初回ログインとパスワード変更

初期設定が完了するとログイン画面になりますので、初期ユーザとパスワードでログインします
ユーザ名:Admin
パスワード:password
WS000007-1.JPG

左下の ユーザ設定 をクリックし、続いて プロファイル をクリックします
WS000010-1.JPG

パスワード変更 ボタンをクリックし、新しいパスワードを設定します
WS000015-1.JPG
WS000013-2.JPG

パスワード変更するとログアウトするよと警告画面が表示されるので、OK ボタンをクリックします
WS000014-1.JPG

ログイン画面に戻るので、新しいパスワードでログインできることを確認します
WS000016-1.JPG
WS000017.JPG

Zabbix Server のデータ取得確認

初期状態で Zabbix Server が登録されているので、データが取得できているか確認します
左側の 最新データ - ホスト の順にクリックし、中央の 最新データ をクリックします
WS000019-1.JPG

取得したデータの一覧が表示されれば OK です
お疲れさまでした!
WS000018-1.JPG

さいごに

公式の手順を参考に、zabbix-get や SSL の設定を補足しました
SSL の設定を忘れがちなのは私だけでしょうか?

参考文献

Download and Install Zabbix 7.0 LTS
Zabbix 7.0 インストールと管理画面のSSL設定メモ

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?