AlmaLinux9.6にZabbixを構築する
  1. 記事一覧/

AlmaLinux9.6にZabbixを構築する

サーバ 仮想環境 AWS Linux

自宅LANで本番運用させるZabbixをVM上に構築したので、その構築手順を公開していく。

Zabbixとは
#

ZabbixはOSSの統合監視ソフトウェア。
サーバー、ネットワーク、アプリケーションなど、システム全体の状態を一元的に監視し、障害検知や通知を行える。

https://www.zabbix.com/documentation/current/jp/manual

構築環境
#

筆者はProxmoxVE上のVMで構築を行った。
デフォルト(Zabbix本体だけ)で4GB近く使うので、公式ドキュメント通り8GB割り当て推奨。

項目
仮想化基盤ProxmoxVE8.4
OSAlmaLinux9.6
ZabbixZabbix 7.0.14

構築手順
#

サーバの初期設定
#

サーバ起動後の定番の初期設定(Redhat系)

## パッケージのアップデート
sudo dnf update -y

## 時刻の設定
# 時刻の変更(JPT)
sudo timedatectl set-timezone Asia/Tokyo
# 時刻の確認
date

## SELinuxの無効化
# SELinuxの確認
getenforce
# SELinux無効化
setenforce 0
# SELinuxの永続無効化
vi /etc/selinux/config
SELINUX=disabled

## 再起動
reboot

必要な人はSWAP領域作成やユーザ作成も行っていいかもしれない。

MySQLとhttpdのインストールおよび設定
#

  1. MySQLとhttpdのインストール
sudo dnf -y install mysql-server httpd
  1. MySQLとhttpdのSystemd登録
# サービスを起動
sudo systemctl start mysqld
# サービスの自動起動を設定
sudo systemctl enable mysqld httpd
# 確認
sudo systemctl status mysqld httpd
  1. MySQLの初期設定
# Mysql初期設定コマンド実施
mysql_secure_installation
  1. 以下フローに従いrootユーザ設定などを行う
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: n

Please set the password for root here.
New password: [パスワードの設定]
Re-enter new password: [再度パスワード入力]

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.
All done! 

Zabbix7.0のインストール
#

基本コチラ のURLに従う。

  1. epelのパッケージを確認
sudo ls /etc/yum.repos.d/epel.repo
  1. /etc/yum.repos.d/epel.repoに以下を追記
[epel]
:
excludepkgs=zabbix*
  1. Zabbixのリポジトリの追加
rpm -Uvh https://repo.zabbix.com/zabbix/7.0/alma/9/x86_64/zabbix-release-latest-7.0.el9.noarch.rpm
dnf clean all
  1. Zabbixリポジトリの追加(WebサーバはApache)
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent zabbix-web-japanese
  1. mysqlに接続
mysql -uroot -p
  1. MySQLでZabbix用データベースの作成
CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER zabbix IDENTIFIED BY '[Zabbixユーザのパスワード]';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix';
SET global log_bin_trust_function_creators = 1;
quit;
  1. DBへ初期データをインポート
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p [zabbixユーザのパスワード]
  1. MySQLにログインしlog_bin_trust_function_creatorsを無効化
mysql -uroot -p
set global log_bin_trust_function_creators = 0;
quit;
  1. zabbix_server.confのパタメーターを変更
vi /etc/zabbix/zabbix_server.conf
DBPassword=[zabbixユーザのパスワード]
  1. Zabbixサービスを起動し自動起動設定
systemctl restart zabbix-server zabbix-agent httpd php-fpm
systemctl enable zabbix-server zabbix-agent httpd php-fpm

Zabbixの初期設定
#

  1. http://[サーバのIPアドレス]/zabbixにアクセス
  2. Default Languageを「日本語(ja_JP)」に設定
  3. 前提条件のチェック(特にいじらない)
  4. データベースの接続設定で「MySQL」「localhost」「0」「zabbix」「プレーンテキスト」「zabbix」「[zabbixユーザのパスワード]」を入力
  5. 設定でzabbixサーバ名を「zabbix.home」システム時刻を「UTC+9:00 Asia/Tokyo」にする
  6. 確認して問題なければ次へ
  7. 初期ユーザ名は「Admin」、パスワードは「zabbix」でログイン

おわり
#

Zabbixサーバの準備ができた。
後はここに監視対象を追加、ダッシュボードの作成、アラートのトリガーの作成などを行う。 本番運用ではAdminユーザのパスワード変更や役割ごとの運用ユーザの作成を推奨する。

関連記事

Proxmox VEのインストールと推奨設定
サーバ 仮想環境 Linux
Vagrant+VirtualBoxで仮想サーバ構築①Webサーバ編
サーバ 仮想環境 Linux
【AWS】LightSailへのWebアクセスをCloudFrontリクエスト以外を無効化する
サーバ AWS Linux