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?

Zabbixのグラフで日本語が表示されないときのフォントの設定

Posted at

あらまし

Zabbix 7.0 でグラフを作ったところ、下記のように日本語が表示されなかった。
image.png
これを修正する。

環境

% cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

% zabbix_server --version
zabbix_server (Zabbix) 7.0.11
Revision 7b462dfe68e 27 March 2025, compilation time: Mar 27 2025 06:24:15

Copyright (C) 2025 Zabbix SIA
License AGPLv3: GNU Affero General Public License version 3 <https://www.gnu.org/licenses/>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 3.0.9 30 May 2023
Running with OpenSSL 3.0.15 3 Sep 2024

やること

% sudo apt install fonts-ipafont
% sudo update-alternatives --install /usr/share/zabbix/assets/fonts/graphfont.ttf zabbix-frontend-font /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf 20
% update-alternatives --display zabbix-frontend-font

リンクは現在 /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf を指しています
と表示されればOK。
これでもう一度グラフを表示すると、ちゃんと日本語が見える。
image.png

解説

dpkg 系統のシステムでは alternatives という仕組みがあり、
あるファイルに複数の候補がある場合、ユーザ側でそれを任意に選択することができる。
あるあるなのは vi だろう。

% update-alternatives --config vi
alternative vi (/usr/bin/vi を提供) には 2 個の選択肢があります。

  選択肢    パス              優先度  状態
------------------------------------------------------------
* 0            /usr/bin/vim.basic   30        自動モード
  1            /usr/bin/vim.basic   30        手動モード
  2            /usr/bin/vim.tiny    15        手動モード

現在の選択 [*] を保持するには <Enter>、さもなければ選択肢の番号のキーを押してください:

こんな感じで /usr/bin/vi の実体を /usr/bin/vim.basic または /usr/bin/vim.tiny から選ぶことができる。

実はZabbixがグラフを描画するときに使うフォントもこの alternatives に登録されている。

% ls -l /usr/share/zabbix/assets/fonts/graphfont.ttf
lrwxrwxrwx 1 root root 38  3月 10  2023 /usr/share/zabbix/assets/fonts/graphfont.ttf -> /etc/alternatives/zabbix-frontend-font

ただし、初期状態では標準のDejaVuSansフォントしか登録されていない。

% update-alternatives --display zabbix-frontend-font
zabbix-frontend-font - 自動モード
  最適なリンクのバージョンは '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf' です
  リンクは現在 /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf を指しています
  リンク zabbix-frontend-font は /usr/share/zabbix/assets/fonts/graphfont.ttf です
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf - 優先度 10

なので、まずはaptでフォントをインストールした後、zabbix-frontend-font の候補としてインストールしたフォントを登録する。

% sudo update-alternatives --install /usr/share/zabbix/assets/fonts/graphfont.ttf zabbix-frontend-font /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf 20
update-alternatives: /usr/share/zabbix/assets/fonts/graphfont.ttf (zabbix-frontend-font) を提供するために自動モードで /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf を使います

% update-alternatives --display zabbix-frontend-font
zabbix-frontend-font - 自動モード
  最適なリンクのバージョンは '/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf' です
  リンクは現在 /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf を指しています
  リンク zabbix-frontend-font は /usr/share/zabbix/assets/fonts/graphfont.ttf です
/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf - 優先度 20
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf - 優先度 10

これで別に設定ファイルをいじることなく、Zabbixのフォントを変更することができる。

覚えておこう

/usr/ 配下のファイルを書き換える前にちょっと確認してみよう。
イマドキのシステムは、ほぼ全ての設定をコマンドか /etc 配下ファイルの変更で対応できる!
(ググると /usr/share/zabbix/include/defines.inc.php を書き換えろ、という解説ページがけっこうあったので)

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?