amegonの雑なブログ

日常的なものから技術的なものまでメモの雑記

FreeBSD に Zabbix agent をインストールしてみたメモ

FreeBSD に Zabbix agent をインストールしようと思った経緯

自作の Web アプリを作成しようと思い、実環境にあわせた検証環境を作成しました。
その検証環境が FreeBSD の 12 だったのですが、アプリの稼働確認などで Zabbix で監視できていたら便利かなと思い監視設定を行ってみました。

環境

root@freebsd12:~ # uname -a
FreeBSD freebsd12 12.3-RELEASE FreeBSD 12.3-RELEASE r371126 GENERIC  amd64
root@freebsd12:~ #

事前準備

システムのアップデート

コマンド

pkg update
pkg upgrade

Zabbix agent のインストール

Zabbix agent モジュールの確認

コマンド

pkg search zabbix | grep agent

実行結果

root@freebsd12:~ # pkg search zabbix | grep agent
zabbix4-agent-4.0.30           Enterprise-class open source distributed monitoring (agent) LTS
zabbix5-agent-5.0.28           Enterprise-class open source distributed monitoring (agent) LTS
zabbix6-agent-6.0.9            Enterprise-class open source distributed monitoring (agent)
zabbix62-agent-6.2.3           Enterprise-class open source distributed monitoring (agent)
root@freebsd12:~ #

Zabbix サーバーのバージョンが 5.0.x なので、zabbix5-agent-5.0.28 をインストールします。

インストール

コマンド

pkg install zabbix5-agent-5.0.28

実行結果

root@freebsd12:~ # pkg install zabbix5-agent-5.0.28
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 11 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        ca_root_nss: 3.83
        curl: 7.86.0
        gettext-runtime: 0.21
        indexinfo: 0.3.1
        libidn2: 2.3.3
        libnghttp2: 1.48.0
        libpsl: 0.21.1_4
        libssh2: 1.10.0,3
        libunistring: 1.0
        pcre: 8.45_1
        zabbix5-agent: 5.0.28

Number of packages to be installed: 11

The process will require 19 MiB more space.
4 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/11] Fetching indexinfo-0.3.1.pkg: 100%    6 KiB   5.9kB/s    00:01
[2/11] Fetching libnghttp2-1.48.0.pkg: 100%  127 KiB 130.3kB/s    00:01
[3/11] Fetching pcre-8.45_1.pkg: 100%    1 MiB   1.3MB/s    00:01
[4/11] Fetching libidn2-2.3.3.pkg: 100%  134 KiB 137.1kB/s    00:01
[5/11] Fetching zabbix5-agent-5.0.28.pkg: 100%  255 KiB 261.6kB/s    00:01
[6/11] Fetching libunistring-1.0.pkg: 100%  555 KiB 568.5kB/s    00:01
[7/11] Fetching libssh2-1.10.0,3.pkg: 100%  248 KiB 253.6kB/s    00:01
[8/11] Fetching libpsl-0.21.1_4.pkg: 100%   63 KiB  64.3kB/s    00:01
[9/11] Fetching curl-7.86.0.pkg: 100%    1 MiB   1.5MB/s    00:01
[10/11] Fetching gettext-runtime-0.21.pkg: 100%  165 KiB 168.8kB/s    00:01
[11/11] Fetching ca_root_nss-3.83.pkg: 100%  277 KiB 283.4kB/s    00:01
Checking integrity... done (0 conflicting)
[1/11] Installing indexinfo-0.3.1...
[1/11] Extracting indexinfo-0.3.1: 100%
[2/11] Installing libunistring-1.0...
[2/11] Extracting libunistring-1.0: 100%
[3/11] Installing libidn2-2.3.3...
[3/11] Extracting libidn2-2.3.3: 100%
[4/11] Installing gettext-runtime-0.21...
[4/11] Extracting gettext-runtime-0.21: 100%
[5/11] Installing libnghttp2-1.48.0...
[5/11] Extracting libnghttp2-1.48.0: 100%
[6/11] Installing libssh2-1.10.0,3...
[6/11] Extracting libssh2-1.10.0,3: 100%
[7/11] Installing libpsl-0.21.1_4...
[7/11] Extracting libpsl-0.21.1_4: 100%
[8/11] Installing ca_root_nss-3.83...
[8/11] Extracting ca_root_nss-3.83: 100%
[9/11] Installing pcre-8.45_1...
[9/11] Extracting pcre-8.45_1: 100%
[10/11] Installing curl-7.86.0...
[10/11] Extracting curl-7.86.0: 100%
[11/11] Installing zabbix5-agent-5.0.28...
===> Creating groups.
Creating group 'zabbix' with gid '122'.
===> Creating users
Creating user 'zabbix' with uid '122'.
[11/11] Extracting zabbix5-agent-5.0.28: 100%
=====
Message from ca_root_nss-3.83:

--
FreeBSD does not, and can not warrant that the certification authorities
whose certificates are included in this package have in any way been
audited for trustworthiness or RFC 3647 compliance.

Assessment and verification of trust is the complete responsibility of the
system administrator.


This package installs symlinks to support root certificates discovery by
default for software that uses OpenSSL.

This enables SSL Certificate Verification by client software without manual
intervention.

If you prefer to do this manually, replace the following symlinks with
either an empty file or your site-local certificate bundle.

  * /etc/ssl/cert.pem
  * /usr/local/etc/ssl/cert.pem
  * /usr/local/openssl/cert.pem
root@freebsd12:~ #

Zabbix agent コンフィグ設定

sample ファイルをコピーして zabbix_agentd.conf を作成

コマンド

cp /usr/local/etc/zabbix5/zabbix_agentd.conf{.sample,}

↑ こんな書き方できるんですね。

実行結果

root@freebsd12:~ # ll /usr/local/etc/zabbix5/
total 36
-rw-r--r--  1 root  wheel  15932 Dec 16 08:12 zabbix_agentd.conf
drwxr-xr-x  2 root  wheel    512 Dec 21 11:14 zabbix_agentd.conf.d/
-rw-r--r--  1 root  wheel  15932 Dec 16 08:12 zabbix_agentd.conf.sample
root@freebsd12:~ #
root@freebsd12:~ # cp /usr/local/etc/zabbix5/zabbix_agentd.conf{.sample,}
root@freebsd12:~ #
root@freebsd12:~ # ll /usr/local/etc/zabbix5/
total 36
-rw-r--r--  1 root  wheel  15932 Dec 21 11:17 zabbix_agentd.conf
drwxr-xr-x  2 root  wheel    512 Dec 21 11:14 zabbix_agentd.conf.d/
-rw-r--r--  1 root  wheel  15932 Dec 16 08:12 zabbix_agentd.conf.sample
root@freebsd12:~ #

/usr/local/etc/zabbix5/zabbix_agentd.conf を修正

変更するのは以下の個所。
それぞれの環境にあわせた設定値にしましょう。

Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server

Zabbix agent の起動

コマンド
(起動チェックまで)

echo 'zabbix_agentd_enable="yes"' >> /etc/rc.conf
service zabbix_agentd start
service zabbix_agentd status

FreeBSD12 には systemctl コマンドは存在しなかった。
ので、service コマンドでサービスの起動を実施。

実行結果

root@freebsd12:~ # systemctl status zabbix-agent
systemctl: Command not found.
root@freebsd12:~ #
root@freebsd12:~ # service zabbix_agentd status
Cannot 'status' zabbix_agentd. Set zabbix_agentd_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
root@freebsd12:~ #
root@freebsd12:~ #
root@freebsd12:~ # echo 'zabbix_agentd_enable="yes"' >> /etc/rc.conf
root@freebsd12:~ # service zabbix_agentd start
root@freebsd12:~ #
root@freebsd12:~ # service zabbix_agentd status
zabbix_agentd is running as pid 1730.
root@freebsd12:~ #

Zabbix サーバーへの監視ホスト追加

テンプレートに FreeBSD の名前がついているものを適用。

データがとれた。