0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AlmaLinux9 に Zabbix Agent2 をインストールしてみた

Posted at

はじめに

こんにちは!山をこよなく愛する 7mountains です!
先日 Zabbix Server 7.0 LTS を AlmaLinux9 にインストールした記事を投稿したので、今回は Zabbix Agent2 のインストール手順を記事にしていきます。
Zabbix Server の記事は こちら を参照してください。

Zabbix Agent2 をインストールする環境

Hyper-V 上に構築した仮想マシンに、AlmaLinux9 をインストールして検証機を構築しました

項目
Zabbix Agent2 をインストールするホスト名 Almalinux002
OS AlmaLinux 9.5
Zabbix ServerのIPアドレス 192.168.1.10

事前準備

Zabbix Server と同様に、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]
..... 省略 .....

インストールしていく

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

Zabbix リポジトリをインストールします

Zabbix リポジトリのインストール
[root@Almalinux002 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/7.0/alma/9/x86_64/zabbix-release-latest-7.0.el9.noarch.rpmrpm -Uvh

Zabbix Agent2 のインストール

Zabbix Agent2 と Zabbix-Get もインストールします

Zabbix Agent2 のインストール
[root@Almalinux002 ~]# dnf -y install zabbix-agent2 zabbix-get

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

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

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

Zabbix Agent2 の設定

/etc/zabbix/zabbix_agent2.conf を開いて、下記3ヶ所の設定変更を行います
Hostname はフロントエンドにホスト登録する際の名前になります

/etc/zabbix/zabbix_agent2.conf
..... 省略 .....
# Server=

Server=192.168.1.10        ←-- Zabbix Server のIPアドレスを入力する

### Option: ListenPort
..... 省略 .....
# ServerActive=
ServerActive=192.168.1.10  ←-- Zabbix Server のIPアドレスを入力する
### Option: Hostname
#       List of comma delimited unique, case sensitive hostnames.
#       Required for active checks and must match hostnames as configured on the server.
#       Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=
Hostname=Almalinux002      ←-- Zabbix Agent2 をインストールしたホスト名を入力する

Zabbix Agent2 の起動

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

zabbix-agent2 起動
[root@Almalinux002 ~]# systemctl enable 0--now zabbix-agent2.service   ←-- 自動起動の設定と起動
[root@Almalinux002 ~]# system ctl 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 Thu 2025-04-17 13:35:18 JST; 10s ago
   Main PID: 8823 (zabbix_agent2)
..... 省略 .....

root 権限に変更

サービスの実行ユーザとグループを変更

/etc/systemd/system/multi-user.target.wants/zabbix-agent2.service を編集して実行ユーザを root に変更します

/etc/systemd/system/multi-user.target.wants/zabbix-agent2.service
[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent2
Type=simple
Restart=on-failure
PIDFile=/run/zabbix/zabbix_agent2.pid
KillMode=control-group
ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=root          ←-- zabbix から root に変更する
Group=root         ←-- zabbix から root に変更する
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target

デーモンのリロードとサービスの再起動

設定変更前は zabbix ユーザで実行しているので、デーモンのリロードを行い、Zabbix Agent2 サービスを再起動します

daemon reload
[root@Almalinux002 ~]# ps -aux | grep zabbix                     ←-- 実行ユーザの確認
zabbix      8823  0.0  1.0 1695112 27432 ?       Ssl  13:35   0:00 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

[root@Almalinux002 ~]# systemctl daemon-reload                   ←-- デーモンリロード
[root@Almalinux002 ~]# systemctl restart zabbix-agent2.service   ←-- サービス再起動
[root@Almalinux002 ~]# ps -aux | grep zabbix
root        8943  0.0  1.1 1694924 28936 ?       Ssl  13:36   0:00 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

[root@Almalinux002 ~]# 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 Thu 2025-04-17 13:36:54 JST; 19s ago
   Main PID: 8943 (zabbix_agent2)
..... 省略 .....

さいごに

昔は zabbix_agent2.conf に AllowRoot=1 を設定すると root で実行してくれたのに、5.0 あたりから仕様が変わったようです。
アイテムのログ監視等で Permission denied のエラーが発生した際は、Zabbix agent2 サービスの実行ユーザを root に変更してみてください。

参考文献

Get Zabbix
Zabbix Documentation

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?