Contents
- 1 Zabbixについて
- 2 サーバー構築
- 3 Zabbixエージェントのインストール
- 4 サーバー設定
- 5 Zabbixの運用
- 5.1 Web管理画面からの監視設定
- 5.1.1 監視対象ホストの登録
- 5.1.2 グラフの作成
- 5.1.3 アプリケーションの作成
- 5.1.4 アイテム(監視項目)の作成
- 5.1.4.1 よく使うZabbixエージェントのアイテム
- 5.1.4.1.1 Linux – CPU Uilization
- 5.1.4.1.2 Linux – Memory Available (byte)
- 5.1.4.1.3 Linux – Load Average
- 5.1.4.1.4 Linux – Disk Free Volume:/ (byte)
- 5.1.4.1.5 Linux – Disk Free Volume:/ (%)
- 5.1.4.1.6 Linux – Running Processes
- 5.1.4.1.7 Linux – Network In (Bps)
- 5.1.4.1.8 Linux – Network In (bps)
- 5.1.4.1.9 Linux – Network Out (Bps)
- 5.1.4.1.10 Linux – Network Out (bps)
- 5.1.4.1.11 Linux – Disk Read : <ディスク> (ops)
- 5.1.4.1.12 Linux – Disk Write : <ディスク> (ops)
- 5.1.4.1.13 ログ監視
- 5.1.4.1 よく使うZabbixエージェントのアイテム
- 5.1.5 正規表現の設定
- 5.1.6 トリガーの設定
- 5.1.7 ユーザ権限の変更
- 5.1.8 テンプレート
- 5.1.9 メンテナンス
- 5.2 Web管理画面からの監視情報閲覧
- 5.3 snmpwalkによる確認
- 5.4 監視項目の自動更新
- 5.5 カスタムアラートスクリプト
- 5.6 Tips
- 5.1 Web管理画面からの監視設定
- 6 自作アイテム
- 7 API
- 8 データベースの直接利用
- 9 ツール
Zabbixについて
構成要素
Zabbixの構成要素はいくつかのノードに分けられる。
代表的なものは、サーバ、エージェント、データベース、フロントエンドで、それぞれ以下の役割を持つ。
- サーバ
監視を実行し、各監視対象から値を取得する。 - エージェント
LinuxなどOSにインストールされ、サーバの要求に応じて値を返す。
エージェントを使用することで、OS上で取得可能なあらゆる値を監視できるが、エージェントを使用せずにSNMPを使用することも出来る。 - データベース
監視対象の各項目の値を保存しておく。 - フロントエンド
データベースから値を取得しグラフ化したり、各種設定を行う
フロントエンドで設定した内容はデータベースを通じてサーバに取得される。
つまり、フロントエンドとサーバは直接連携せず、サーバがダウンしていてもグラフの閲覧などは可能。
最も簡単な構成では、サーバ、フロントエンド、データベースは同じホスト上で稼動させる。
他構成次第でプロキシや、Javaゲートウェイなどのノードが使用される。
用語
アイテム
Zabbixが各ホストに対して行うデータ監視項目。
整数値、浮動小数値、文字列値等のデータ型、単位、保存期間など各種設定を行うことが出来る。
アイテムのデータの取得はSNMP、Zabbixエージェントなど、いくつかの方法がある。
アイテムはキーによって識別される。
アイテムキー
アイテムを識別する文字列。
CPU使用率やディスク使用量などによって一意に定まる。
一部を変数化可能で、特定のパスのディスク使用量などというように設定可能。
アプリケーション
アイテムをグループ化したもの
タイプ
アイテムの監視方法のこと。
Zabbix Agentによる監視やエージェント不要の監視方法などがある。
ウェブシナリオ
連続したHTTPアクセスにより、特定のWEBページ内を巡回可能かどうかの監視が行える。
これによってログインが必要なサイトでログインし、その後特定のページが閲覧できるかといった監視を行うことが出来る。
1回のHTTPアクセスをウェブステップと呼び、シナリオは複数回のステップにより構成される。
マクロ
{$<文字列>}の形式で定義でき、値の対応を記述することができる。
マクロはホスト単位、テンプレート単位、グローバルで設定可能で、アイテムやトリガーなどで使用することで、
共通の設定を使いつつもホスト毎に使用する値を変えるといったことが可能となる。
テンプレート
アイテムやトリガー、グラフなどを登録しておき、ホスト作成時に適用することで、
テンプレート内で設定したアイテムなどが自動でそのホストでも有効になる。
テンプレート内で定義したアイテムなどは一部を除きテンプレートで設定した統一した共通設定値が利用されるため、
テンプレートを設定変更するとテンプレートを使用する全てのホストに一括反映できる。
共通項目内で個別の値を使用したい場合はマクロを使用すればよい。
ヒストリ
監視データのこと。
トレンド
一定期間のヒストリから算出した最大値や平均などの統計データのこと。
アクション
アイテムが指定した状態になった時にZabbix Serverが行う内容の事。
アラートメールを送ったり、指定したコマンド(リモートコマンド)を実行することができる。
異常状態から復帰した際に再度メールなどメッセージを送ることができるが、これをリカバリメッセージという。
正規表現
ログ監視で使用する正規表現データ。
正規表現データとして独立させることで、複数のログ監視に割り当てることができる。
正規表現に一致する特定文字列を障害とする、または障害としないことができる。
これはトリガーと目的は同じであるが、トリガーはサーバ側で判断するのに対し、正規表現はクライアント側で判断する。
つまり、正規表現を用いると、サーバ側に転送するログ量を制御できる。
反面、サーバで閲覧可能なログに欠損が発生するので、どちらを使用するかは状況により異なる。
オートディスカバリー
特定のネットワークアドレスに新規サーバが起動した場合、自動で検知して監視対象に加える機能。
そのサーバがシャットダウンした際に自動で削除することも可能。
ただしその場合は、過去の収集データが消えてしまう。
サーバ発見時に監視の有効化、終了時に無効化することでこれを防ぐことができる。
いずれにせよ死活監視をするとアラートが発生することになるので、注意。
サーバー構築
構築環境
- Zabbix
3.4.12
パッケージ版は3.4.12-1.el7
- OS
CentOS 7.5
OS設定
ネットワーク
固定IPアドレス割り当て
次のファイルを編集する
# ifcfg-loはループバックインタフェースであるため、触らない vi /etc/sysconfig/network-scripts/ifcfg-<インタフェース名>
以下では例として192.168.0.51/24を割り当てた
BOOTPROTO=static ONBOOT=yes IPADDR=192.168.0.51 NETMASK=255.255.255.0 NETWORK=192.168.0.0 GATEWAY=192.168.0.1
ネットワークを再起動する
systemctl restart network
ip addressコマンドにより、インタフェースが有効になっていることを確認する
これによりホストマシンなどからSSHでログイン可能となる
firewalld
HTTPを開ける
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=http
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- ルールを適用する
firewall-cmd --add-service=http --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- 設定を再読み込みして反映させる
firewall-cmd --reload
HTTPSも開ける場合
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=https
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- ルールを適用する
firewall-cmd --add-service=https --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- 設定を再読み込みして反映させる
firewall-cmd --reload
Zabbix Serverポートを開ける
Zabbix Agentからの通知のような受動的な監視を行う場合に必要となる。
- 現在ルールが定義されていないか確認
firewall-cmd --permanent --info-service=zabbix_server
- 新しいルールを定義
firewall-cmd --permanent --new-service=zabbix_server firewall-cmd --permanent --service=zabbix_server --add-port=10051/tcp
- ルールが定義されていることを確認
firewall-cmd --permanent --info-service=zabbix_server
- 現在ルールが適用されていないことを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_server
- ルールを適用する
firewall-cmd --permanent --add-service=zabbix_server --zone=public
- ルールが適用されていることを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_server
- 設定を再読み込みして反映させる
firewall-cmd --reload
Zabbix Agentポートを開ける
別のサーバからZabbix Agentによる監視を受ける場合に必要となる。
- 現在ルールが定義されていないか確認
firewall-cmd --permanent --info-service=zabbix_agent
- 新しいルールを定義
firewall-cmd --permanent --new-service=zabbix_agent firewall-cmd --permanent --service=zabbix_agent --add-port=10050/tcp
- ルールが定義されていることを確認
firewall-cmd --permanent --info-service=zabbix_agent
- 現在ルールが適用されていないことを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
- ルールを適用する
firewall-cmd --permanent --add-service=zabbix_agent --zone=public
- ルールが適用されていることを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
- 設定を再読み込みして反映させる
firewall-cmd --reload
ホスト名
ホスト名としてzabbixを設定する
# 再起動しても有効にする hostnamectl set-hostname zabbix.corp再ログインすることで有効になる。
ユーザ作成
Zabbix用のユーザを作成する
useradd --user-group --no-create-home --shell /sbin/false zabbix
Apacheの構築
Apacheのインストール
参考:apache2.4.34
今回はバージョン2.4.34をソースコードインストールしたとする。
MariaDBの構築
MariaDBのインストール
参考:mariadb
今回はバージョン10.3.7をソースコードインストールしたとする。
データベースの作成
- ログインする
mysql -p
- データベースを作成する
create database zabbix character set utf8;
- zabbixユーザを作成する
ユーザ名:zabbix、パスワード:zabbixで作成している
- ローカルホストのデータベースを使用する場合
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
- リモートホストのデータベースを使用する場合
grant all privileges on zabbix.* to zabbix identified by 'zabbix';
- ローカルホストのデータベースを使用する場合
- 接続を終了する
exit
PHPのインストール
参考:php7.2.9
関連パッケージのインストール
yum install libpng-devel libXpm-devel gd gd-devel freetype-devel libxml2-devel gcc -y
ソースのダウンロード
- ダウンロードサイト:http://php.net/downloads.phpからアーカイブのURLを取得する
- ダウンロードする
curl -s -O http://jp2.php.net/distributions/php-<PHP_VERSION>.tar.gz
- アーカイブファイルを展開する
tar xzfv php-*.tar.gz
- ソースコードディレクトリへ移動する
cd php-*
ビルド時のオプション
※二度目以降のビルドの際は、次のコマンドを事前に実行すること
make clean
mysqlndを使用する。mysqliを使用する方法ではZabbixでエラーが出た。
- コンパイル最適化設定を行う
export CFLAGS="-O3 -m64"
- configure設定を行う
./configure --prefix=/usr/local/`pwd | sed "s/.*\///"` \ --with-apxs2=$APACHE_HOME/bin/apxs \ --enable-mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-mysql-sock=/tmp/mysql.sock \ --enable-bcmath \ --enable-mbstring \ --enable-sockets \ --with-gd \ --with-jpeg-dir=/usr/lib64/ \ --with-freetype-dir=/usr/lib64/ \ 2>&1 | tee configure.log
- ビルドする
make 2>&1 | tee make.log
- インストールする
make install 2>&1 | tee make_install.log
環境変数等
リンク作成、環境変数設定などを行う
- インストールディレクトリへのシンボリックリンクを作成する。
これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
rm -f /usr/local/php ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/php
- 簡単にアクセスできるように環境変数を設定する
export PHP_HOME=/usr/local/php
- ツール類にパスを通す
export PATH=$PHP_HOME/bin:$PATH
- 環境変数を再起動後も有効にする
echo "" >> /etc/bashrc echo "# PHP ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export PHP_HOME=$PHP_HOME" >> /etc/bashrc echo "export PATH=\$PHP_HOME/bin:\$PHP_HOME/sbin:\$PATH" >> /etc/bashrc
- 設定ファイルをコピーする
cp php.ini-production $PHP_HOME/lib/php.ini
拡張モジュールのインストール
zlib
cd ext/zlib yum install autoconf -y ln -s config0.m4 config.m4 phpize ./configure --with-zlib=/usr/local/zlib make make install cd ../../
gettext
※php -mでモジュール確認するとデフォルトでgettextが有効になっているが、下記手順を実施しないとZabbixでは認識できない
cd ext/gettext phpize ./configure make make install cd ../../ sed "s/;extension=gettext/extension=gettext/g" -i $PHP_HOME/lib/php.ini
Zabbixの構築
サーバ・フロントエンドインストール
事前準備としてMySQLなどのデータベースの用意が必要。
インストールする数が多いので、パッケージの方が簡単ではあるが、反面インストールするソフトウェアのディレクトリを完全に分離できない。
パッケージからインストール
参考
- 関連パッケージをインストールするためにリポジトリを追加する(バージョンによって異なる)
rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm # 古いバージョンのリポジトリが登録されている場合、ここで削除される
- インストールする
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
- 必要に応じて以下もインストールする
yum install zabbix-sender -y yum install zabbix-get -y
Apacheの初期設定
vi /etc/httpd/conf.d/zabbix.conf
# php_value date.timezone XXXXXXXとなっている行があるので、これを以下に修正する。
php_value date.timezone Asia/Tokyo
更に<Directory “/usr/share/zabbix”>ディレクティブ内で以下を修正する。
# 追加 Require all granted # 削除 Order allow,deny Allow from all
再起動して設定を反映する。
httpd -k restart
Zabbixの初期設定
vi /etc/zabbix/zabbix_server.conf
以下を追加する。
DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBPassword=zabbixソケット接続する場合は、DBSocketの値を適切に変更する
例:DBSocket=/tmp/mysql.sock
ソースコードからインストール
- 関連パッケージをインストールする
yum install libevent-devel pcre-devel fping -y
- ソースコードを取得する
- ダウンロードサイトからURLを取得する
- ダウンロードする
curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
- アーカイブファイルを展開する
tar xzfv zabbix-*.tar.gz
- ソースコードディレクトリへ移動する
cd zabbix-*
- コンパイル、インストールを行う
- コンパイル最適化設定を行う
export CFLAGS="-O3 -m64"
- Makefileを生成する
./configure --prefix=/usr/local/`pwd | sed "s/.*\///"` --enable-server --enable-agent --with-mysql 2>&1 | tee configure.log
- オプション一覧
[root@zabbix zabbix-3.4.12]# ./configure --help `configure' configures Zabbix 3.4.12 to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/zabbix] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build --disable-largefile omit support for large files --enable-static Build statically linked binaries --enable-server Turn on build of Zabbix server --enable-proxy Turn on build of Zabbix proxy --enable-agent Turn on build of Zabbix agent and client utilities --enable-java Turn on build of Zabbix Java gateway --enable-ipv6 Turn on support of IPv6 Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-ibm-db2=[ARG] use IBM DB2 CLI from given sqllib directory (ARG=path); use /home/db2inst1/sqllib (ARG=yes); disable IBM DB2 support (ARG=no) --with-ibm-db2-include=[DIR] use IBM DB2 CLI headers from given path --with-ibm-db2-lib=[DIR] use IBM DB2 CLI libraries from given path --with-mysql[=ARG] use MySQL client library [default=no], optionally specify path to mysql_config --with-oracle=[ARG] use Oracle OCI API from given Oracle home (ARG=path); use existing ORACLE_HOME (ARG=yes); disable Oracle OCI support (ARG=no) --with-oracle-include=[DIR] use Oracle OCI API headers from given path --with-oracle-lib=[DIR] use Oracle OCI API libraries from given path --with-postgresql[=ARG] use PostgreSQL library [default=no], optionally specify path to pg_config --with-sqlite3[=ARG] use SQLite 3 library [default=no], optionally specify the prefix for sqlite3 library If you want to use Jabber protocol for messaging: --with-jabber[=DIR] Include Jabber support [default=no]. DIR is the iksemel library install directory. If you want to use XML library: --with-libxml2[=ARG] use libxml2 client library [default=no], optionally specify path to xml2-config If you want to use unixODBC library: --with-unixodbc[=ARG] use ODBC driver against unixODBC package [default=no], optionally specify full path to odbc_config binary. If you want to use Net-SNMP library: --with-net-snmp[=ARG] use Net-SNMP package [default=no], optionally specify path to net-snmp-config If you want to use SSH2 based checks: --with-ssh2[=DIR] use SSH2 package [default=no], DIR is the SSH2 library install directory. If you want to check IPMI devices: --with-openipmi[=DIR] Include OPENIPMI support [default=no]. DIR is the OPENIPMI base install directory, default is to search through a number of common places for the OPENIPMI files. If you want to specify libevent installation directories: --with-libevent[=DIR] use libevent from given base install directory (DIR), default is to search through a number of common places for the libevent files. --with-libevent-include[=DIR] use libevent include headers from given path. --with-libevent-lib[=DIR] use libevent libraries from given path. If you want to use encryption provided by mbed TLS (PolarSSL) library: --with-mbedtls[=DIR] use mbed TLS (PolarSSL) package [default=no], DIR is the libpolarssl install directory. If you want to use encryption provided by GnuTLS library: --with-gnutls[=DIR] use GnuTLS package [default=no], DIR is the libgnutls install directory. If you want to use encryption provided by OpenSSL library: --with-openssl[=DIR] use OpenSSL package [default=no], DIR is the libssl and libcrypto install directory. If you want to check LDAP servers: --with-ldap[=DIR] Include LDAP support [default=no]. DIR is the LDAP base install directory, default is to search through a number of common places for the LDAP files. If you want to use cURL library: --with-libcurl[=DIR] use cURL package [default=no], optionally specify path to curl-config If you want to specify libpcre installation directories: --with-libpcre[=DIR] use libpcre from given base install directory (DIR), default is to search through a number of common places for the libpcre files. --with-libpcre-include[=DIR] use libpcre include headers from given path. --with-libpcre-lib[=DIR] use libpcre libraries from given path. If you want to specify iconv installation directories: --with-iconv[=DIR] use iconv from given base install directory (DIR), default is to search through a number of common places for the iconv files. --with-iconv-include[=DIR] use iconv include headers from given path. --with-iconv-lib[=DIR] use iconv libraries from given path. Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path IKSEMEL_CFLAGS C compiler flags for IKSEMEL, overriding pkg-config IKSEMEL_LIBS linker flags for IKSEMEL, overriding pkg-config Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider.
- オプション一覧
- コンパイルする
make 2>&1 | tee make.log
- インストールを行う。
make install 2>&1 | tee make_install.log
- DBライブラリのパスを通す
ln -s $MARIADB_HOME/lib/libmariadb.so /usr/lib64/libmariadb.so.3
- コンパイル最適化設定を行う
- リンク作成、環境変数設定などを行う
- インストールディレクトリへのシンボリックリンクを作成する。
これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
rm -f /usr/local/zabbix ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
- 簡単にアクセスできるように環境変数を設定する
export ZABBIX_HOME=/usr/local/zabbix
- ツール類にパスを通す
export PATH=$ZABBIX_HOME/bin:$ZABBIX_HOME/sbin:$PATH
- 環境変数を再起動後も有効にする
echo "" >> /etc/bashrc echo "# ZABBIX ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export ZABBIX_HOME=$ZABBIX_HOME" >> /etc/bashrc echo "export PATH=\$ZABBIX_HOME/bin:\$ZABBIX_HOME/sbin:\$PATH" >> /etc/bashrc
- 実行できることを確認する
zabbix_server -V # バージョン情報が出力される
- インストールディレクトリへのシンボリックリンクを作成する。
- DBのスキーマ作成を行う
- ローカルホストのデータベースを使用する場合
mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
- ローカルホストのデータベースを使用する場合
- Frontendのインストールを行う
cp -r frontends/php $ZABBIX_HOME/frontends ls $ZABBIX_HOME/frontends/*/.htaccess | xargs rm -f
- 不要なソースコードを削除する
cd ../ rm -rf zabbix*
- systemdの設定する
- サーバーのサービスファイルを作成する
cat > /etc/systemd/system/zabbix-server.service << EOT [Unit] Description=Zabbix Server After=syslog.target After=network.target [Service] Environment="CONFFILE=$ZABBIX_HOME/etc/zabbix_server.conf" #EnvironmentFile=-/etc/sysconfig/zabbix-server Type=forking Restart=on-failure PIDFile=$ZABBIX_HOME/run/zabbix_server.pid KillMode=control-group ExecStart=$ZABBIX_HOME/sbin/zabbix_server -c \$CONFFILE ExecStop=/bin/kill -SIGTERM \$MAINPID RestartSec=10s TimeoutSec=0 [Install] WantedBy=multi-user.target EOT
- エージェントのサービスファイルを作成する
cat > /etc/systemd/system/zabbix-agent.service << EOT [Unit] Description=Zabbix Agent After=syslog.target After=network.target [Service] Environment="CONFFILE=$ZABBIX_HOME/etc/zabbix_agentd.conf" #EnvironmentFile=-/etc/sysconfig/zabbix-agent Type=forking Restart=on-failure PIDFile=$ZABBIX_HOME/run/zabbix_agentd.pid KillMode=control-group ExecStart=$ZABBIX_HOME/sbin/zabbix_agentd -c \$CONFFILE ExecStop=/bin/kill -SIGTERM \$MAINPID RestartSec=10s [Install] WantedBy=multi-user.target EOT
- 作成したファイルを反映する
systemctl daemon-reload
- サービスを有効化する
systemctl enable zabbix-server systemctl enable zabbix-agent
- サービスが有効化されていることを確認する
systemctl list-unit-files --type service --no-pager | grep zabbix
- サーバーのサービスファイルを作成する
- インストールしたディレクトリに移動する
cd $ZABBIX_HOME
- 初期設定を行う
- ディレクトリ作成
- ログ
ログをsyslogではなくファイルに直接出力する設定を行ったので、出力先のディレクトリを作成する。
mkdir log
- PID
mkdir run
- ログ
- 基本設定を行う
※リモートのDBサーバを利用する場合は、次の設定を「DBSocket」の代わりに入れる。
DBHost=<接続先IPアドレス>
設定ファイルを作成する(デフォルトファイルを上書きする)
cat > etc/zabbix_server.conf << EOT LogFile=$ZABBIX_HOME/log/zabbix_server.log PidFile=$ZABBIX_HOME/run/zabbix_server.pid DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/tmp/mysql.sock EOT sed -e "s/# PidFile=.*/PidFile=\/usr\/local\/zabbix\/run\/zabbix_agentd.pid/g" -i etc/zabbix_agentd.conf sed -e "s/LogFile=.*/LogFile=\/usr\/local\/zabbix\/log\/zabbix_agentd.log/g" -i etc/zabbix_agentd.conf
- ディレクトリ作成
- ファイル所有者を変更する
chown -R zabbix:zabbix /usr/local/zabbix* chown -R apache:apache $ZABBIX_HOME/frontends
- Zabbixを起動する
systemctl start zabbix-server systemctl start zabbix-agent
- 稼働確認
systemctl status zabbix-server systemctl status zabbix-agent
正常に起動していない場合、ログを確認する。
journalctl -u zabbix-server journalctl -u zabbix-agent cat /var/log/messages
- 停止
systemctl stop zabbix-server systemctl stop zabbix-agent
- Apacheの設定を行う
- 設定ファイルを編集する
※PHPのLoadModule設定はPHPのインストール時に自動で設定される。
cat >> $APACHE_HOME/conf/httpd.conf << EOT # Zabbix Configuration <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> AddType text/html .php Alias /zabbix $ZABBIX_HOME/frontends <Directory "$ZABBIX_HOME/frontends"> Options None AllowOverride None Require all granted DirectoryIndex index.php <IfModule php7_module> php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value max_input_vars 10000 php_value always_populate_raw_post_data -1 php_value date.timezone Asia/Tokyo </IfModule> </Directory> <Directory "$ZABBIX_HOME/frontends/conf"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/app"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/include"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/local"> Require all denied </Directory> EOT
- 再起動して設定を反映する。
apachectl restart
- 設定ファイルを編集する
- Frontendの初期設定を行う
- 下記にブラウザでアクセスする
http://<ホスト名 or IPアドレス>/zabbix/
- Next Step
- PHP設定の要件チェックが行われる
不備がある場合、PHPのモジュール追加、設定を行いApacheを再起動した後、再度ここまで進める - Next Step
- DB接続情報を入力する
基本的に全て入力済みなので、ホストとパスワードのみ入力すればよい
※「Database host」はデフォルトの「localhost」だとUNIXソケット(/tmp/mysql.sock)を使用するが、エラーが出る場合がある。その場合、「127.0.0.1」を指定する。
※MariaDBのソケットも同様のパスを指定している。
Database type:MySQL
Database host:localhost
Database port:0(default port)
Database name:zabbix
User:zabbix
Password:zabbix - Next Step
- Zabbix Server情報を入力する
デフォルトのままでよい - Next Step
- Next Step
- Finish
※「Unable to create the configuration file.」というエラーが表示される場合、PHPのディレクトリの権限がなく、設定ファイルが生成できない。
次のコマンドで所有者が「apache」になっていることを確認する
ls -ld $ZABBIX_HOME/frontends
異なる場合は所有者を変更する。
更に、次のコマンドで、「apache」ユーザでapacheが動作していることを確認する
ps aux | grep httpd
異なる場合、apacheの実行ユーザを変更する。
egrep "^(User|Group)" $APACHE_HOME/conf/httpd.conf sed -e "s/^User daemon/User apache/" -e "s/^Group daemon/Group apache/" -i $APACHE_HOME/conf/httpd.conf egrep "^(User|Group)" $APACHE_HOME/conf/httpd.conf apachectl restart
- 下記にブラウザでアクセスする
- 次のユーザ名でアカウントする
Admin / zabbix
事後的にFrontendの設定変更をしたい場合、下記のパスのファイルを編集する
/usr/local/zabbix/frontends/conf/zabbix.conf.php
言語設定
使用する言語を変更できる。
- Frontend設定
- Administration
- Users
- Adminユーザを選択
- LanguageをJapaneseに変更
- Update
- 次に開いたページから日本語になる
- Server設定
日本語にする場合、画像で使用されるフォントがDejaVuSansのため、日本語表示できない。
設定変更が必要であるが、Linuxを英語版でインストールした場合、日本語対応フォントがインストールされていない。
任意の日本語フォントファイル(.ttf形式、.otf形式不可)を用意する必要がある。
今回は無料で使用できるGoogle FontのM PLUS 1pを使用する。
- ダウンロードする
mkdir mplus cd mplus curl -s -o mplus.zip https://fonts.google.com/download?family=M%20PLUS%201p
- 展開する
unzip mplus.zip
※unzipがインストールされていない場合はインストールする
# yum install unzip -y
- 普通サイズフォントのみを移動する
mv MPLUS1p-Regular.ttf $ZABBIX_HOME/frontends/fonts/
- 設定変更する
sed "s/DejaVuSans/MPLUS1p-Regular/g" -i $ZABBIX_HOME/frontends/include/defines.inc.php
- その他のフォントファイルを削除する
cd ../ rm -rf mplus
管理者のパスワード変更
デフォルトのzabbixからパスワードを変更する
- 管理
- ユーザー
- Adminユーザを選択
- パスワード変更
- パスワードを入力する
- 更新
- OK
ゲストユーザの無効
デフォルトユーザであるGuestは削除できないので、無効化しておく。
- 管理
- ユーザー
- Guestユーザを選択
- グループからGuestsを削除する
- グループにDisabledを追加する
- 更新
メール設定
障害時にアラートメールを送信する設定を行う。
Zabbix Serverと同じホストにSMTPサーバが稼動しているとする。
- メールサーバを設定する
- 管理
- メディアタイプ
- Emailを選択する
- SMTPサーバー、SMTP heloに「localhost」と入力する
- 送信元メールアドレスにメールサーバのドメイン名を使用したメールアドレスを記入する
- 更新
- 不要であれば、Email以外のメディアタイプを無効にしておく
- 宛先を登録する
- 管理
- ユーザー
- Adminを選択する
- 「メディア」タブを開く
- 「追加」
- 「送信先」に宛先メールアドレスを入力する
- 「指定した深刻度のときに使用」欄を必要に応じて選択する
※一般的には軽度の障害か重度の障害以上で良い - 「追加」ボタンをクリックする
- 更新
- 更新
- アクションを設定する
- 設定
- アクション
- 「Report problems to Zabbix administrators」を選択する
- 有効にチェックする
- 「実行内容」タブを開く
- デフォルトの件名、デフォルトのメッセージを適宜修正する
- 実行内容の1の変更をクリックする
- 「次のメディアのみ使用」ドロップダウンボックスをEmailに変更する
- 更新をクリックする
- 「復旧時実行内容」タブを開く
- 復旧通知の件名、リカバリメッセージを適宜修正する
- 更新
メールのみのアカウント作成
障害時などに通知するメールアドレスはユーザアカウントとひも付けられるため、
WEBログインはしないが障害通知用のメールアドレスを登録する場合、専用のアカウントを作成する必要がある。
- 管理
- ユーザー
- ユーザーに画面右部のドロップダウンリストを切り替える
- ユーザーの作成
- エイリアスからパスワードまでを入力する
- グループに「No access to the frontend」を選択して追加する
- メディアタブを開く
- 「追加」をクリックし、メールアドレスを追加する
- 保存
- この作成したアカウントを使用してアクションを作成する
Zabbixエージェントのインストール
Zabbixエージェントを監視対象のホストにインストールすることで、様々な情報を取得することができる。
監視対象の各サーバにて下記手順を実施する。
サーバー設定
ユーザ作成
Zabbix用のユーザを作成する
useradd --user-group --no-create-home --shell /sbin/false zabbix
Firewalld設定
- 現在ルールが定義されていないか確認
firewall-cmd --permanent --info-service=zabbix_agent
- 新しいルールを定義
firewall-cmd --permanent --new-service=zabbix_agent firewall-cmd --permanent --service=zabbix_agent --add-port=10050/tcp
- ルールが定義されていることを確認
firewall-cmd --permanent --info-service=zabbix_agent
- 現在ルールが適用されていないことを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
- ルールを適用する
firewall-cmd --permanent --add-service=zabbix_agent --zone=public
- ルールが適用されていることを確認する
firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
- 設定を再読み込みして反映させる
firewall-cmd --reload
エージェントのインストール
パッケージからインストール
- リポジトリを追加する(バージョンによって異なる)
rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
- パッケージをインストールする
yum install zabbix-agent -y
- 必要に応じて以下もインストールする
yum install zabbix-sender -y yum install zabbix-get -y
ソースコードからインストール
- ソースコードを取得する
- ダウンロードサイトからURLを取得する
- ダウンロードする
curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
- アーカイブファイルを展開する
tar xzfv zabbix-*.tar.gz
- ソースコードディレクトリへ移動する
cd zabbix-*
- コンパイル、インストールを行う
- コンパイル最適化設定を行う
export CFLAGS="-O3 -m64"
- Makefileを生成する
./configure --prefix=/usr/local/`pwd | sed "s/.*\///"` --enable-agent 2>&1 | tee configure.log
- オプション一覧
[root@zabbix zabbix-3.4.12]# ./configure --help `configure' configures Zabbix 3.4.12 to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/zabbix] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build --disable-largefile omit support for large files --enable-static Build statically linked binaries --enable-server Turn on build of Zabbix server --enable-proxy Turn on build of Zabbix proxy --enable-agent Turn on build of Zabbix agent and client utilities --enable-java Turn on build of Zabbix Java gateway --enable-ipv6 Turn on support of IPv6 Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-ibm-db2=[ARG] use IBM DB2 CLI from given sqllib directory (ARG=path); use /home/db2inst1/sqllib (ARG=yes); disable IBM DB2 support (ARG=no) --with-ibm-db2-include=[DIR] use IBM DB2 CLI headers from given path --with-ibm-db2-lib=[DIR] use IBM DB2 CLI libraries from given path --with-mysql[=ARG] use MySQL client library [default=no], optionally specify path to mysql_config --with-oracle=[ARG] use Oracle OCI API from given Oracle home (ARG=path); use existing ORACLE_HOME (ARG=yes); disable Oracle OCI support (ARG=no) --with-oracle-include=[DIR] use Oracle OCI API headers from given path --with-oracle-lib=[DIR] use Oracle OCI API libraries from given path --with-postgresql[=ARG] use PostgreSQL library [default=no], optionally specify path to pg_config --with-sqlite3[=ARG] use SQLite 3 library [default=no], optionally specify the prefix for sqlite3 library If you want to use Jabber protocol for messaging: --with-jabber[=DIR] Include Jabber support [default=no]. DIR is the iksemel library install directory. If you want to use XML library: --with-libxml2[=ARG] use libxml2 client library [default=no], optionally specify path to xml2-config If you want to use unixODBC library: --with-unixodbc[=ARG] use ODBC driver against unixODBC package [default=no], optionally specify full path to odbc_config binary. If you want to use Net-SNMP library: --with-net-snmp[=ARG] use Net-SNMP package [default=no], optionally specify path to net-snmp-config If you want to use SSH2 based checks: --with-ssh2[=DIR] use SSH2 package [default=no], DIR is the SSH2 library install directory. If you want to check IPMI devices: --with-openipmi[=DIR] Include OPENIPMI support [default=no]. DIR is the OPENIPMI base install directory, default is to search through a number of common places for the OPENIPMI files. If you want to specify libevent installation directories: --with-libevent[=DIR] use libevent from given base install directory (DIR), default is to search through a number of common places for the libevent files. --with-libevent-include[=DIR] use libevent include headers from given path. --with-libevent-lib[=DIR] use libevent libraries from given path. If you want to use encryption provided by mbed TLS (PolarSSL) library: --with-mbedtls[=DIR] use mbed TLS (PolarSSL) package [default=no], DIR is the libpolarssl install directory. If you want to use encryption provided by GnuTLS library: --with-gnutls[=DIR] use GnuTLS package [default=no], DIR is the libgnutls install directory. If you want to use encryption provided by OpenSSL library: --with-openssl[=DIR] use OpenSSL package [default=no], DIR is the libssl and libcrypto install directory. If you want to check LDAP servers: --with-ldap[=DIR] Include LDAP support [default=no]. DIR is the LDAP base install directory, default is to search through a number of common places for the LDAP files. If you want to use cURL library: --with-libcurl[=DIR] use cURL package [default=no], optionally specify path to curl-config If you want to specify libpcre installation directories: --with-libpcre[=DIR] use libpcre from given base install directory (DIR), default is to search through a number of common places for the libpcre files. --with-libpcre-include[=DIR] use libpcre include headers from given path. --with-libpcre-lib[=DIR] use libpcre libraries from given path. If you want to specify iconv installation directories: --with-iconv[=DIR] use iconv from given base install directory (DIR), default is to search through a number of common places for the iconv files. --with-iconv-include[=DIR] use iconv include headers from given path. --with-iconv-lib[=DIR] use iconv libraries from given path. Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path IKSEMEL_CFLAGS C compiler flags for IKSEMEL, overriding pkg-config IKSEMEL_LIBS linker flags for IKSEMEL, overriding pkg-config Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider.
- オプション一覧
- コンパイルする
make 2>&1 | tee make.log
- インストールを行う。
make install 2>&1 | tee make_install.log
- コンパイル最適化設定を行う
- リンク作成、環境変数設定などを行う
- インストールディレクトリへのシンボリックリンクを作成する。
これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
rm -f /usr/local/zabbix ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
- 簡単にアクセスできるように環境変数を設定する
export ZABBIX_HOME=/usr/local/zabbix
- ツール類にパスを通す
export PATH=$ZABBIX_HOME/bin:$ZABBIX_HOME/sbin:$PATH
- 環境変数を再起動後も有効にする
echo "" >> /etc/bashrc echo "# ZABBIX ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export ZABBIX_HOME=$ZABBIX_HOME" >> /etc/bashrc echo "export PATH=\$ZABBIX_HOME/bin:\$ZABBIX_HOME/sbin:\$PATH" >> /etc/bashrc
- インストールディレクトリへのシンボリックリンクを作成する。
- 不要なソースコードを削除する
cd ../ rm -rf zabbix*
- systemdの設定する
- エージェントのサービスファイルを作成する
cat > /etc/systemd/system/zabbix-agent.service << EOT [Unit] Description=Zabbix Agent After=syslog.target After=network.target [Service] Environment="CONFFILE=$ZABBIX_HOME/etc/zabbix_agentd.conf" #EnvironmentFile=-/etc/sysconfig/zabbix-agent Type=forking Restart=on-failure PIDFile=$ZABBIX_HOME/run/zabbix_agentd.pid KillMode=control-group ExecStart=$ZABBIX_HOME/sbin/zabbix_agentd -c \$CONFFILE ExecStop=/bin/kill -SIGTERM \$MAINPID RestartSec=10s [Install] WantedBy=multi-user.target EOT
- 作成したファイルを反映する
systemctl daemon-reload
- サービスを有効化する
systemctl enable zabbix-agent
- サービスが有効化されていることを確認する
systemctl list-unit-files --type service --no-pager | grep zabbix
- エージェントのサービスファイルを作成する
- インストールしたディレクトリに移動する
cd $ZABBIX_HOME
- 初期設定を行う
- ディレクトリ作成
- ログ
ログをsyslogではなくファイルに直接出力する設定を行ったので、出力先のディレクトリを作成する。
mkdir log
- PID
mkdir run
- ログ
- 基本設定を行う
設定ファイルを作成する(デフォルトファイルを上書きする)
sed -e "s/# PidFile=.*/PidFile=\/usr\/local\/zabbix\/run\/zabbix_agentd.pid/g" -i etc/zabbix_agentd.conf sed -e "s/LogFile=.*/LogFile=\/usr\/local\/zabbix\/log\/zabbix_agentd.log/g" -i etc/zabbix_agentd.conf
- ディレクトリ作成
- ファイル所有者を変更する
chown -R zabbix:zabbix /usr/local/zabbix*
- Zabbixを起動する
systemctl start zabbix-agent
- 稼働確認
systemctl status zabbix-agent
正常に起動していない場合、ログを確認する。
journalctl -u zabbix-agent cat /var/log/messages
- 停止
systemctl stop zabbix-agent
エージェントの起動
- コマンドでの起動
/usr/sbin/zabbix_agent &
- サービスによる起動
systemctl start zabbix-agent
設定変更
設定ファイルが以下のパスに存在するので、修正することで設定変更を行うことができる。
/etc/zabbix/zabbix_agentd.conf設定変更後は再起動が必要。
systemctl restart zabbix-agent
設定項目
基本設定
- PIDファイルのパス
- インストール時の設定
PidFile=/var/run/zabbix/zabbix_agentd.pid
- デフォルト
PidFile=/tmp/zabbix_agentd.pid
- インストール時の設定
- 出力インタフェース
- インストール時の設定
なし
- デフォルト
SourceIP=
- インストール時の設定
- 待ち受けポート
1024-32767の間で指定する必要がある。
- インストール時の設定
なし
- デフォルト
ListenPort=10050
- インストール時の設定
- プロセス数
Agentプロセスをいくつ起動するかを指定する。
0を指定するとプロセスが起動できず、サーバとの通信ができなくなる。
- インストール時の設定
なし
- デフォルト
StartAgents=3
- インストール時の設定
ログ設定
- ログファイルパス
指定がない場合、syslogに出力される。
- インストール時の設定
LogFile=/var/log/zabbix/zabbix_agentd.log
- デフォルト
なし(syslogに出力)
- インストール時の設定
- ログファイルサイズ
ローテーションを行うログファイルのサイズをMB単位で指定する。
0を指定した場合、ローテーションを行わない。
- インストール時の設定
LogFileSize=0
- デフォルト
LogFileSize=1
- インストール時の設定
- ログレベル
0~4が指定可能で、それぞれ以下の意味を持つ
0 no debug 1 critical information 2 error information 3 warnings 4 for debugging (produces lots of information) - インストール時の設定
なし
- デフォルト
DebugLevel=3
- インストール時の設定
サーバ設定
サーバとして予め設定したホストからの要求しかエージェントは値を返さない。
そのため、サーバのホスト名 / IPアドレスの設定を行う必要がある。
- 通信許可サーバ
- インストール時の設定
Server=127.0.0.1
- デフォルト
Server=
- インストール時の設定
- インストール時の設定
ServerActive=127.0.0.1
- デフォルト
ServerActive=
アクティブチェック
サーバで監視対象を追加した際の識別子で、サーバ側とエージェント側で一致させる必要がある。
実際の表示名は別に設定できるので何でもよい。
- インストール時の設定
Hostname=Zabbix server
- デフォルト
Hostname=
設定ファイル読み込み
外部に定義した別の設定ファイルをロードすることができる。
ディレクトリを指定した場合は、その直下のファイルがロードされる。
- インストール時の設定
Include=/etc/zabbix/zabbix_agentd.d/
- デフォルト
なし
リモートコマンド
サーバからの任意のリモートコマンドによる監視を行う設定をする。
監視項目は下記
system.run[command,<mode>]
- 例
ルートディレクトリのファイル一覧を取得する
zabbix_get -s <対象サーバ> -k system.run[ls -l /]
system.runをサーバ側で設定する場合、エージェントサーバ側にリモートコマンドをの実行を許可する設定が必要である。
EnableRemoteCommandsの項目で設定し、値は0か1をとり、0は不許可、1は許可である。
- インストール時の設定
なし
- デフォルト
EnableRemoteCommands=0
- 許可設定する
EnableRemoteCommands=0
- 実行内容のログ
実行されたコマンドをログに記録するかどうかを指定する。
ログレベルはwarning(3)となる。
0か1をとり、0は記録しない、1は記録する、である。
- インストール時の設定
なし
- デフォルト
LogRemoteCommands=0
- インストール時の設定
独自監視項目の作成
特定のスクリプトやコマンドを実行して値を取得することで、その値を監視することができる。
- 書式
UserParameter=<監視項目名(キー)>,<実行コマンド>
- 引数
キーに [*] を含めることで、引数として文字列を受け取ることができる。
引数は $1、$2等で参照可能
例えば、UserParameter=ping[*],echo $1と設定し、アイテムにping[0]と登録した場合、echo 0が実行される。
引数を複数渡す場合は、 , で区切る。例えば、ping[0,1,2,3]のようにすることで、それぞれ $1~$4で参照可能。
- 引数
ここで設定したキー名を用いてZabbixサーバのアイテムのキー値に設定する
設定した監視項目が正しく動作するかはzabbix_getコマンドにより確認できる
zabbix_get -s <監視対象> -k <監視項目名>※存在しない監視項目名を指定したり、Serverで指定しているホスト以外から実行した場合は何も表示されない。Serverで127.0.0.1と指定している場合は、zabbix_get でlocalhostと指定しても何も表示されない。
- サンプル
- 現在の秒
UserParameter=now.second,date | sed "s/.*://g"|sed "s/ .*//g"
- 現在の秒
設定例
監視サーバ
PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=10 DebugLevel=3 Server=127.0.0.1 StartAgents=3 Include=/etc/zabbix/my_zabbix_agentd.linux.conf
WEBサーバ
PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=10 DebugLevel=3 Server=X.X.X.X StartAgents=3 Include=/etc/zabbix/my_zabbix_agentd.linux.conf Include=/etc/zabbix/my_zabbix_agentd.apache.conf
サーバー設定
サーバーの設定ファイルは次のパスにある
$ZABBIX_HOME/etc/zabbix_server.conf
初期設定
# This is a configuration file for Zabbix server daemon # To get more information about Zabbix, visit http://www.zabbix.com ############ GENERAL PARAMETERS ################# ### Option: ListenPort # Listen port for trapper. # # Mandatory: no # Range: 1024-32767 # Default: # ListenPort=10051 ### Option: SourceIP # Source IP address for outgoing connections. # # Mandatory: no # Default: # SourceIP= ### Option: LogType # Specifies where log messages are written to: # system - syslog # file - file specified with LogFile parameter # console - standard output # # Mandatory: no # Default: # LogType=file ### Option: LogFile # Log file name for LogType 'file' parameter. # # Mandatory: no # Default: # LogFile= LogFile=/tmp/zabbix_server.log ### Option: LogFileSize # Maximum size of log file in MB. # 0 - disable automatic log rotation. # # Mandatory: no # Range: 0-1024 # Default: # LogFileSize=1 ### Option: DebugLevel # Specifies debug level: # 0 - basic information about starting and stopping of Zabbix processes # 1 - critical information # 2 - error information # 3 - warnings # 4 - for debugging (produces lots of information) # 5 - extended debugging (produces even more information) # # Mandatory: no # Range: 0-5 # Default: # DebugLevel=3 ### Option: PidFile # Name of PID file. # # Mandatory: no # Default: PidFile=/usr/local/zabbix/run/zabbix_server.pid ### Option: SocketDir # IPC socket directory. # Directory to store IPC sockets used by internal Zabbix services. # # Mandatory: no # Default: # SocketDir=/tmp ### Option: DBHost # Database host name. # If set to localhost, socket is used for MySQL. # If set to empty string, socket is used for PostgreSQL. # # Mandatory: no # Default: # DBHost=localhost ### Option: DBName # Database name. # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored. # # Mandatory: yes # Default: # DBName= DBName=zabbix ### Option: DBSchema # Schema name. Used for IBM DB2 and PostgreSQL. # # Mandatory: no # Default: # DBSchema= ### Option: DBUser # Database user. Ignored for SQLite. # # Mandatory: no # Default: # DBUser= DBUser=zabbix ### Option: DBPassword # Database password. Ignored for SQLite. # Comment this line if no password is used. # # Mandatory: no # Default: # DBPassword= ### Option: DBSocket # Path to MySQL socket. # # Mandatory: no # Default: # DBSocket=/tmp/mysql.sock ### Option: DBPort # Database port when not using local socket. Ignored for SQLite. # # Mandatory: no # Range: 1024-65535 # Default (for MySQL): # DBPort=3306 ### Option: HistoryStorageURL # History storage HTTP[S] URL. # # Mandatory: no # Default: # HistoryStorageURL= ### Option: HistoryStorageTypes # Comma separated list of value types to be sent to the history storage. # # Mandatory: no # Default: # HistoryStorageTypes=uint,dbl,str,log,text ############ ADVANCED PARAMETERS ################ ### Option: StartPollers # Number of pre-forked instances of pollers. # # Mandatory: no # Range: 0-1000 # Default: # StartPollers=5 ### Option: StartIPMIPollers # Number of pre-forked instances of IPMI pollers. # The IPMI manager process is automatically started when at least one IPMI poller is started. # # Mandatory: no # Range: 0-1000 # Default: # StartIPMIPollers=0 ### Option: StartPreprocessors # Number of pre-forked instances of preprocessing workers. # The preprocessing manager process is automatically started when preprocessor worker is started. # # Mandatory: no # Range: 1-1000 # Default: # StartPreprocessors=3 ### Option: StartPollersUnreachable # Number of pre-forked instances of pollers for unreachable hosts (including IPMI and Java). # At least one poller for unreachable hosts must be running if regular, IPMI or Java pollers # are started. # # Mandatory: no # Range: 0-1000 # Default: # StartPollersUnreachable=1 ### Option: StartTrappers # Number of pre-forked instances of trappers. # Trappers accept incoming connections from Zabbix sender, active agents and active proxies. # At least one trapper process must be running to display server availability and view queue # in the frontend. # # Mandatory: no # Range: 0-1000 # Default: # StartTrappers=5 ### Option: StartPingers # Number of pre-forked instances of ICMP pingers. # # Mandatory: no # Range: 0-1000 # Default: # StartPingers=1 ### Option: StartDiscoverers # Number of pre-forked instances of discoverers. # # Mandatory: no # Range: 0-250 # Default: # StartDiscoverers=1 ### Option: StartHTTPPollers # Number of pre-forked instances of HTTP pollers. # # Mandatory: no # Range: 0-1000 # Default: # StartHTTPPollers=1 ### Option: StartTimers # Number of pre-forked instances of timers. # Timers process time-based trigger functions and maintenance periods. # Only the first timer process handles the maintenance periods. # # Mandatory: no # Range: 1-1000 # Default: # StartTimers=1 ### Option: StartEscalators # Number of pre-forked instances of escalators. # # Mandatory: no # Range: 0-100 # Default: # StartEscalators=1 ### Option: StartAlerters # Number of pre-forked instances of alerters. # Alerters send the notifications created by action operations. # # Mandatory: no # Range: 0-100 # Default: # StartAlerters=3 ### Option: JavaGateway # IP address (or hostname) of Zabbix Java gateway. # Only required if Java pollers are started. # # Mandatory: no # Default: # JavaGateway= ### Option: JavaGatewayPort # Port that Zabbix Java gateway listens on. # # Mandatory: no # Range: 1024-32767 # Default: # JavaGatewayPort=10052 ### Option: StartJavaPollers # Number of pre-forked instances of Java pollers. # # Mandatory: no # Range: 0-1000 # Default: # StartJavaPollers=0 ### Option: StartVMwareCollectors # Number of pre-forked vmware collector instances. # # Mandatory: no # Range: 0-250 # Default: # StartVMwareCollectors=0 ### Option: VMwareFrequency # How often Zabbix will connect to VMware service to obtain a new data. # # Mandatory: no # Range: 10-86400 # Default: # VMwareFrequency=60 ### Option: VMwarePerfFrequency # How often Zabbix will connect to VMware service to obtain performance data. # # Mandatory: no # Range: 10-86400 # Default: # VMwarePerfFrequency=60 ### Option: VMwareCacheSize # Size of VMware cache, in bytes. # Shared memory size for storing VMware data. # Only used if VMware collectors are started. # # Mandatory: no # Range: 256K-2G # Default: # VMwareCacheSize=8M ### Option: VMwareTimeout # Specifies how many seconds vmware collector waits for response from VMware service. # # Mandatory: no # Range: 1-300 # Default: # VMwareTimeout=10 ### Option: SNMPTrapperFile # Temporary file used for passing data from SNMP trap daemon to the server. # Must be the same as in zabbix_trap_receiver.pl or SNMPTT configuration file. # # Mandatory: no # Default: # SNMPTrapperFile=/tmp/zabbix_traps.tmp ### Option: StartSNMPTrapper # If 1, SNMP trapper process is started. # # Mandatory: no # Range: 0-1 # Default: # StartSNMPTrapper=0 ### Option: ListenIP # List of comma delimited IP addresses that the trapper should listen on. # Trapper will listen on all network interfaces if this parameter is missing. # # Mandatory: no # Default: # ListenIP=0.0.0.0 # ListenIP=127.0.0.1 ### Option: HousekeepingFrequency # How often Zabbix will perform housekeeping procedure (in hours). # Housekeeping is removing outdated information from the database. # To prevent Housekeeper from being overloaded, no more than 4 times HousekeepingFrequency # hours of outdated information are deleted in one housekeeping cycle, for each item. # To lower load on server startup housekeeping is postponed for 30 minutes after server start. # With HousekeepingFrequency=0 the housekeeper can be only executed using the runtime control option. # In this case the period of outdated information deleted in one housekeeping cycle is 4 times the # period since the last housekeeping cycle, but not less than 4 hours and not greater than 4 days. # # Mandatory: no # Range: 0-24 # Default: # HousekeepingFrequency=1 ### Option: MaxHousekeeperDelete # The table "housekeeper" contains "tasks" for housekeeping procedure in the format: # [housekeeperid], [tablename], [field], [value]. # No more than 'MaxHousekeeperDelete' rows (corresponding to [tablename], [field], [value]) # will be deleted per one task in one housekeeping cycle. # SQLite3 does not use this parameter, deletes all corresponding rows without a limit. # If set to 0 then no limit is used at all. In this case you must know what you are doing! # # Mandatory: no # Range: 0-1000000 # Default: # MaxHousekeeperDelete=5000 ### Option: CacheSize # Size of configuration cache, in bytes. # Shared memory size for storing host, item and trigger data. # # Mandatory: no # Range: 128K-8G # Default: # CacheSize=8M ### Option: CacheUpdateFrequency # How often Zabbix will perform update of configuration cache, in seconds. # # Mandatory: no # Range: 1-3600 # Default: # CacheUpdateFrequency=60 ### Option: StartDBSyncers # Number of pre-forked instances of DB Syncers. # # Mandatory: no # Range: 1-100 # Default: # StartDBSyncers=4 ### Option: HistoryCacheSize # Size of history cache, in bytes. # Shared memory size for storing history data. # # Mandatory: no # Range: 128K-2G # Default: # HistoryCacheSize=16M ### Option: HistoryIndexCacheSize # Size of history index cache, in bytes. # Shared memory size for indexing history cache. # # Mandatory: no # Range: 128K-2G # Default: # HistoryIndexCacheSize=4M ### Option: TrendCacheSize # Size of trend cache, in bytes. # Shared memory size for storing trends data. # # Mandatory: no # Range: 128K-2G # Default: # TrendCacheSize=4M ### Option: ValueCacheSize # Size of history value cache, in bytes. # Shared memory size for caching item history data requests. # Setting to 0 disables value cache. # # Mandatory: no # Range: 0,128K-64G # Default: # ValueCacheSize=8M ### Option: Timeout # Specifies how long we wait for agent, SNMP device or external check (in seconds). # # Mandatory: no # Range: 1-30 # Default: # Timeout=3 Timeout=4 ### Option: TrapperTimeout # Specifies how many seconds trapper may spend processing new data. # # Mandatory: no # Range: 1-300 # Default: # TrapperTimeout=300 ### Option: UnreachablePeriod # After how many seconds of unreachability treat a host as unavailable. # # Mandatory: no # Range: 1-3600 # Default: # UnreachablePeriod=45 ### Option: UnavailableDelay # How often host is checked for availability during the unavailability period, in seconds. # # Mandatory: no # Range: 1-3600 # Default: # UnavailableDelay=60 ### Option: UnreachableDelay # How often host is checked for availability during the unreachability period, in seconds. # # Mandatory: no # Range: 1-3600 # Default: # UnreachableDelay=15 ### Option: AlertScriptsPath # Full path to location of custom alert scripts. # Default depends on compilation options. # # Mandatory: no # Default: # AlertScriptsPath=${datadir}/zabbix/alertscripts ### Option: ExternalScripts # Full path to location of external scripts. # Default depends on compilation options. # # Mandatory: no # Default: # ExternalScripts=${datadir}/zabbix/externalscripts ### Option: FpingLocation # Location of fping. # Make sure that fping binary has root ownership and SUID flag set. # # Mandatory: no # Default: # FpingLocation=/usr/sbin/fping ### Option: Fping6Location # Location of fping6. # Make sure that fping6 binary has root ownership and SUID flag set. # Make empty if your fping utility is capable to process IPv6 addresses. # # Mandatory: no # Default: # Fping6Location=/usr/sbin/fping6 ### Option: SSHKeyLocation # Location of public and private keys for SSH checks and actions. # # Mandatory: no # Default: # SSHKeyLocation= ### Option: LogSlowQueries # How long a database query may take before being logged (in milliseconds). # Only works if DebugLevel set to 3, 4 or 5. # 0 - don't log slow queries. # # Mandatory: no # Range: 1-3600000 # Default: # LogSlowQueries=0 LogSlowQueries=3000 ### Option: TmpDir # Temporary directory. # # Mandatory: no # Default: # TmpDir=/tmp ### Option: StartProxyPollers # Number of pre-forked instances of pollers for passive proxies. # # Mandatory: no # Range: 0-250 # Default: # StartProxyPollers=1 ### Option: ProxyConfigFrequency # How often Zabbix Server sends configuration data to a Zabbix Proxy in seconds. # This parameter is used only for proxies in the passive mode. # # Mandatory: no # Range: 1-3600*24*7 # Default: # ProxyConfigFrequency=3600 ### Option: ProxyDataFrequency # How often Zabbix Server requests history data from a Zabbix Proxy in seconds. # This parameter is used only for proxies in the passive mode. # # Mandatory: no # Range: 1-3600 # Default: # ProxyDataFrequency=1 ### Option: AllowRoot # Allow the server to run as 'root'. If disabled and the server is started by 'root', the server # will try to switch to the user specified by the User configuration option instead. # Has no effect if started under a regular user. # 0 - do not allow # 1 - allow # # Mandatory: no # Default: # AllowRoot=0 ### Option: User # Drop privileges to a specific, existing user on the system. # Only has effect if run as 'root' and AllowRoot is disabled. # # Mandatory: no # Default: # User=zabbix ### Option: Include # You may include individual files or all files in a directory in the configuration file. # Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time. # # Mandatory: no # Default: # Include= # Include=/usr/local/etc/zabbix_server.general.conf # Include=/usr/local/etc/zabbix_server.conf.d/ # Include=/usr/local/etc/zabbix_server.conf.d/*.conf ### Option: SSLCertLocation # Location of SSL client certificates. # This parameter is used only in web monitoring. # # Mandatory: no # Default: # SSLCertLocation=${datadir}/zabbix/ssl/certs ### Option: SSLKeyLocation # Location of private keys for SSL client certificates. # This parameter is used only in web monitoring. # # Mandatory: no # Default: # SSLKeyLocation=${datadir}/zabbix/ssl/keys ### Option: SSLCALocation # Override the location of certificate authority (CA) files for SSL server certificate verification. # If not set, system-wide directory will be used. # This parameter is used only in web monitoring and SMTP authentication. # # Mandatory: no # Default: # SSLCALocation= ####### LOADABLE MODULES ####### ### Option: LoadModulePath # Full path to location of server modules. # Default depends on compilation options. # # Mandatory: no # Default: # LoadModulePath=${libdir}/modules ### Option: LoadModule # Module to load at server startup. Modules are used to extend functionality of the server. # Format: LoadModule=<module.so> # The modules must be located in directory specified by LoadModulePath. # It is allowed to include multiple LoadModule parameters. # # Mandatory: no # Default: # LoadModule= ####### TLS-RELATED PARAMETERS ####### ### Option: TLSCAFile # Full pathname of a file containing the top-level CA(s) certificates for # peer certificate verification. # # Mandatory: no # Default: # TLSCAFile= ### Option: TLSCRLFile # Full pathname of a file containing revoked certificates. # # Mandatory: no # Default: # TLSCRLFile= ### Option: TLSCertFile # Full pathname of a file containing the server certificate or certificate chain. # # Mandatory: no # Default: # TLSCertFile= ### Option: TLSKeyFile # Full pathname of a file containing the server private key. # # Mandatory: no # Default: # TLSKeyFile=
Zabbixの運用
Web管理画面からの監視設定
監視対象ホストの登録
- 設定
- ホスト
- 「ホストの作成」ボタンをクリック
- 必要情報を入力する
- ホストを設定する
- ホスト名
エージェントで設定しているホスト名。エージェント側設定と一致している必要がある。 - 表示名
Zabbix Frontend上での表示名。省略した場合、「ホスト名」と同じになる。 - エージェントのインターフェース
エージェントのIPアドレスかホスト名を入力する。 - SNMPなど監視方法によって使用するインタフェースを選択し、不要なものは削除する
- ホスト名
- テンプレートを適用する
- 「新規テンプレートをリンク」から選択をクリックする
- 適用したいテンプレートを選択する
- 選択をクリックする
- 追加をクリックする
- マクロを設定する
- ホストを設定する
- 更新
グラフの作成
数値データを監視している場合、自動的に時間軸と値の2軸の折れ線グラフが作られるが、
円グラフや積算グラフを表示させる場合や、複数の項目を1つのグラフ内で表示させる場合はグラフの作成を行う必要がある。
- 設定
- グラフを作成するホスト / テンプレートを選択する
- グラフを作成するホスト / テンプレートの「グラフ」をクリック
- 各パラメータを入力する
- 表示させたいアイテムを追加する
- 追加したアイテムのパラメータを設定する
- 関数
グラフを表示した(表示中に時間の単位を変更した)際の時間軸単位に複数の値が存在する場合、どの値を表示するかを決定する
- すべて
最小、平均、最大をすべて表示する - 最小
- 平均
- 最大
- すべて
- 関数
- 追加したアイテムのパラメータを設定する
- 追加
ダッシュボードに追加
- 監視データ > ダッシュボード
- ダッシュボードの変更
- ウィジェットを追加
- タイプをグラフに変更する
- グラフ名を入力する
- グラフ選択ボタンをクリックし、表示したいグラフを選択する
- 追加
- 変更を保存
アプリケーションの作成
アプリケーションはホストやテンプレート単位で作成し、グローバルには設定できない。
従って、テンプレートやホストが異なると、同名のアプリケーションでも再度作成する必要がある。
- 設定
- アイテム追加先の選択(ホスト or テンプレート)
- 「アプリケーション」リンクをクリック
- アプリケーションの作成
- 名前を入力する
- 保存
アイテム(監視項目)の作成
- 設定
- アイテム追加先の選択(ホスト or テンプレート)
- 「アイテム」リンクをクリック
- アイテムの作成
- 名前、キーなどを入力する
- 保存
- 設定項目について
- 名前
アイテムの名前 - タイプ
ZabbixエージェントやSNMPなどアイテムの値の取得方法 - キー
アイテムの識別名
- 名前
- タイプについて
- Zabbixエージェント
サーバからの要求に対し、予め監視対象にインストールしたZabbixエージェントが応答することで値を収集する。 - Zabbixエージェント(アクティブ)
イベントが発生すると、予め監視対象にインストールしたZabbixエージェントがZabbixサーバに対し値を送る。 - シンプルチェック
pingやポート監視など、Zabbixサーバの機能のみで値を収集する。 - SNMPエージェント
サーバからの要求に対し、監視対象のSNMPデーモンが応答することで値を収集する。 - SNMPトラップ
イベントが発生すると、監視対象のSNMPクライアントがZabbixサーバに対し値を送る。 - Zabbixトラッパー
zabbixの付属ソフトのzabbix_senderによって、任意のタイミングで監視対象からZabbixサーバに対し値を送る。
- Zabbixエージェント
- Tips
- 取得した値がByte値でBit値に変換したい場合等は「乗数」に8を指定する。乗数は小数も指定可能なので、除算を行う場合は小数を指定する。
- SNMPは数値のみのOIDだけではなく、サブツリー名を指定したOIDの指定が可能。
- snmpwalkで取得した値がCounter系のものであれば、「保存時の計算」を「差分」や「差分/時間」にする
よく使うZabbixエージェントのアイテム
参考
Linux – CPU Uilization
- キー
system.cpu.util
- データ型
数値(浮動小数)
- 単位
%
Linux – Memory Available (byte)
- キー
vm.memory.size[available]
- データ型
数値(浮動小数)
- 単位
%
Linux – Load Average
- キー
system.cpu.load
- データ型
数値(浮動小数)
Linux – Disk Free Volume:/ (byte)
マウントポイントで対象ディスクを指定するが、マウントポイントよりディスクで指定したい場合は使用しない
- キー
vfs.fs.size[/,free]
- 単位
byte
Linux – Disk Free Volume:/ (%)
マウントポイントで対象ディスクを指定するが、マウントポイントよりディスクで指定したい場合は使用しない
- キー
vfs.fs.size[/,pfree]
- データ型
数値(浮動小数)
- 単位
%
Linux – Running Processes
- キー
proc.num[,,run]
Linux – Network In (Bps)
- キー
net.if.in[eth0,bytes]
- 単位
byte
- 保存時の計算
差分/時間
Linux – Network In (bps)
- キー
net.if.in[eth0]
- 単位
bps
- 乗数
8
- 保存時の計算
差分/時間
Linux – Network Out (Bps)
- キー
net.if.out[eth0,bytes]
- 単位
Bps
- 保存時の計算
差分/時間
Linux – Network Out (bps)
- キー
net.if.out[eth0]
- 単位
bps
- 乗数
8
- 保存時の計算
差分/時間
Linux – Disk Read : <ディスク> (ops)
- キー
vfs.dev.read[<ディスク>,ops]
※ディスク部分にはパーティションではなくディスク名を入力する点に注意
<ディスク>は空白、または”all”とすることで、ディスク全体の合計を取得可能 - データ型
数値(浮動小数)
- 単位
ops
Linux – Disk Write : <ディスク> (ops)
- キー
vfs.dev.write[<ディスク>,ops]
※ディスク部分にはパーティションではなくディスク名を入力する点に注意
<ディスク>は空白、または”all”とすることで、ディスク全体の合計を取得可能 - データ型
数値(浮動小数)
- 単位
ops
ログ監視
- キー
log[<ファイルパス>]
- データ型
ログ
正規表現の設定
正規表現の作成
- 管理
- 一般設定
- 正規表現を選択
- 正規表現の作成
- 正規表現を設定する
- 名前を入力する
- 条件式を設定する
- 条件式の新規をクリックする
- 条件式に正規表現を入力する
- 条件式の形式を選択する
- 文字列が含まれる
- いずれかの文字列が含まれる
- 文字列が含まれない
- 結果が真
- 結果が偽
- 必要であれば大文字小文字を区別するかにチェックを入れる
- 追加
- テスト文字列に文字列を入力しテストをクリックすることでテストができる
- 保存
正規表現の割り当て
ログ監視に作成した正規表現を割り当てるには、アイテムキーの第二引数に@と正規表現名を入力する
- ログ監視用のアイテムの設定画面を開く
- タイプに「Zabbixエージェント」を選択する
- キーに次の書式で入力する
log[<監視対象ファイルパス>,@<正規表現名>]
- データ型に「ログ」を選択する
- その他は任意に設定し、保存する
トリガーの設定
トリガーは監視データに条件を設定し、その条件を満たした場合に発生させるアラートを定義する。
監視データはアイテムとして定義され、取得中のものでなければならない。
トリガーの条件式にアイテムキーを記載することで、自動でアイテムとトリガーの関連付けが行われる。
トリガーの記法
トリガーの書式は次のとおりである。
{<サーバー/テンプレート名>:<アイテムキー>.<関数>}<比較演算子><比較値>
比較演算子
- 同じ
=
- 異なる
#
- 大なり
>
- 小なり
<
その他の演算子
- AND
&
- OR
|
- 四則演算
+ - * /
イベント生成
- ノーマル
トリガーのステータスが変更されると、エラーが発生したとされる。
エラー状態が解除されない限り、次にトリガーが発動しても、エラー時アクションが実行されない。
- ノーマル + 障害イベントを継続して生成
トリガーのステータスが変更され度に、常にエラー時アクションを実行する。
関数
count
過去指定回数分のデータを一定ルールで比較し、合致数を返す。
CPUの一時的な急騰時にアラート発生を避けるなどのために使用可能。
- パラメータ
- 集計対象
- 個数
#<個数>
- 時間
<現在から過去への秒数>
- 個数
- 比較値
省略可能 - 比較演算子
省略可能。
ダブルクォーテーションで囲う。
- eq
等しい - ne
等しくない - gt
より大きい - ge
以上 - lt
未満 - le
以下 - like
値にパターンが含まれれば一致
- eq
- 過去時間へのシフト
省略可能。
第一引数を現在からの秒数ではなく、指定秒前から始める。
- 集計対象
- 例
- 直近10分間の「12」に等しい値の出現回数。
count(600,12,"eq")
- 直近10個の値の中、「12」より大きい値の出現回数。
count(#10,12,"gt")
- 直近10分間の「12」に等しい値の出現回数。
last
直近の値を取得する
- パラメータ
- 0
最新の値 - #<数値>
N個前の値。
1から始まる。
last(#1)はlast(0)と同じである。
- 0
regexp
大文字小文字を無視した正規表現に一致するかどうか。
一致した場合、1を返す。
iregexp
大文字小文字を無視しない正規表現に一致するかどうか
一致した場合、1を返す。
トリガーの例
サーバ名はいずれもtest_serverとする
Ping監視
Ping監視は成功が1、失敗が0と記録される。
- 最新のPingデータが失敗の場合
{test_server:icmpping[].last(0)}=0
ユーザ権限の変更
ユーザごとに監視対象の設定の書き込み、監視の値の読み込み権限を設定できる。
権限設定はユーザが所属するグループごとに行う。
- 管理
- ユーザー
- 権限を変更するグループを選択する
- 権限タブを開く
- 「権限の編集」欄の「追加」ボタンをクリックする
- 追加したい項目を選択する
- 「選択」ボタンをクリックする
- 「保存」ボタンをクリックする
テンプレート
テンプレートのエクスポート
- 設定
- テンプレート
- 対象テンプレートにチェックを入れる
- 選択をエクスポート
- 実行
- XMLファイルがダウンロードされる
テンプレートのインポート
- 設定
- テンプレート
- テンプレートのインポート
- ローカルのファイルを選択する
- インポート
メンテナンス
メンテナンスを設定すると特定ホストのみ、一定期間アラートの停止ができる。
メンテナンス期間中は情報収集を続けることも止めることもできる。
- 設定
- メンテナンス
- メンテナンス期間の作成
- 次のパラメータを設定する
- 名前:メンテナンスの管理名
- メンテナンスタイプ:データ収集あり/なし
- 開始日時:このメンテナンス設定の開始期間
- 終了日時:このメンテナンス設定の終了期間
- 説明:コメント
- メンテナンス中のホスト
- 期間のタイプ:
- 一度限り
- 毎日
- 毎週
- 毎月
- メンテナンス期間詳細
期間のタイプの種類によって異なる
- 一度限り
- 日付:開始日時
- メンテナンス期間:継続時間
- 毎日
- 繰返し間隔(日)
- 開始時刻
- メンテナンス期間:継続時間
- 毎週
- 繰返し間隔(週)
- 一度限り
- ーー曜日:何曜日を有効にするか
- 開始時刻
- メンテナンス期間:継続時間
- 毎月
- 月:何月を有効にするか
- 日付:日/曜日
- ーー日/曜日
- 開始時刻
- メンテナンス期間:継続時間
- 保存
Web管理画面からの監視情報閲覧
監視データを閲覧する
- 監視データ
- 最新データ
- 閲覧したいホスト、監視項目を選択して開く
データのみを削除
設定は残しつつ、保存されている取得データを削除する。
- 設定
- ホスト
- アイテム
- 削除したいアイテムをチェック
- 「選択したヒストリを削除」を実行
snmpwalkによる確認
snmpwalkコマンドを使用することで、監視対象にSNMPアクセスが可能かどうか確認できる。
snmpwalkがインストールされていない場合は別途インストールが必要。
- snmpwalkのインストール
- snmpwalkがインストールされているか確認する
snmpwalk -V
- net-snmp-utilsをインストールする
yum install net-snmp-utils -y
- snmpwalkがインストールされたか確認する
snmpwalk -V
- snmpwalkがインストールされているか確認する
- 対象のMIBを確認
snmpwalkコマンドを使用して監視できるMIB一覧を取得する。
snmpwalk -v 2c -c <コミュニティ値> <対象ホスト>バージョンオプション-vは 1 や 3 も選択可能。
- 特定のMIBの値を取得
snmpgetコマンドを使用すると、特定のMIBのみの値を取得できる。
snmpget -v 2c -c <コミュニティ値> <対象ホスト> <OID>
監視項目の自動更新
- WEBサーバを用意し、設定ファイルを設置する
- アイテム更新のスクリプトを作成する
vi /usr/local/bin/zabbix_item_updater.sh
- 以下を修正して貼り付ける
- ITEM_FILES:ダウンロードするファイル
- ITEM_URL:ダウンロードするURL
ITEM_FILES=("my_zabbix_agentd.linux.conf" "my_zabbix_agentd.apache.conf") ITEM_URL="http://XXXXX" UPDATE_COUNT=0 for next in $ITEM_FILES; do UPDATE_COUNT=`expr $UPDATE_COUNT + \`wget "$ITEM_URL""$next" -N -O /etc/zabbix/"$next" 2>&1 | grep saved | wc -l \`` done if [ "$UPDATE_COUNT" -gt 0 ]; then /etc/init.d/zabbix-agent restart fi
- 実行権限を付与する
chmod 774 /usr/local/bin/zabbix_item_updater.sh
- cronに登録する(30分間隔)
echo "*/30 * * * * root /usr/local/bin/zabbix_item_updater.sh" > /etc/cron.d/zabbix
カスタムアラートスクリプト
Zabbixで障害発生を検知した際にメール送信に代わる指定のスクリプトを実行することができる。
スクリプトの仕様
引数
スクリプトは3つの引数をとる。順番に「送信先」、「件名」、「メッセージ」である。
なお、引数文字列中にZabbixユーザのログインシェルで展開可能な文字列($変数やバッククォートコマンド)があると、展開された状態でスクリプトに渡されるので注意。
- 送信先
ユーザ > メディアで設定した値である。
つまり、ユーザとカスタムアラートスクリプトの組み合わせ毎に1つ設定できる。 - 件名
アクションの設定で記述した「デフォルトの件名」が入る。 - メッセージ
アクションの設定で記述した「デフォルトのメッセージ」が入る。
パス
実行時のカレンとディレクトリは「/」である。
実行時ユーザ
zabbixで実行される
スクリプトの配置
Zabbixサーバの任意のパスに配置する
カスタムアラートスクリプトの登録
- メディアタイプの登録を行う
- 通知したいユーザのメディアに登録したメディアタイプを追加する
- 「送信先」を記載する。この「送信先」はスクリプトの引数の一つとなる。
- アクションとユーザを関連付ける
スクリプトを実行するユーザは障害通知をする監視対象サーバが属するサーバグループに対する読み取り権限が必要
Tips
閲覧のみのZabbix Frontendの構築
閲覧のみ可能なZabbix Frontendを構築する。
例えば、特定の場所からのアクセスではZabbixの更新はさせたくないが、閲覧はしたい場合に使用できる。
- Apacheを構築する
- PHPを構築する
- MariaDBを構築する
- MariaDBのユーザ作成は次のように行う
grant select on zabbix.* to zabbix@localhost identified by 'zabbix'; grant Insert,Update on zabbix.sessions to zabbix@localhost; grant Insert,Update on zabbix.profiles to zabbix@localhost; grant Insert,Update on zabbix.ids to zabbix@localhost;
- MariaDBのユーザ作成は次のように行う
- ソースコードを取得する
- ダウンロードサイトからURLを取得する
- ダウンロードする
curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
- アーカイブファイルを展開する
tar xzfv zabbix-*.tar.gz
- ソースコードディレクトリへ移動する
cd zabbix-*
- Frontendのインストールを行う
- インストールディレクトリを作成する
mkdir /usr/local/`pwd | sed "s/.*\///"`
- インストールディレクトリへのシンボリックリンクを作成する。
これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
rm -f /usr/local/zabbix ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
- 簡単にアクセスできるように環境変数を設定する
export ZABBIX_HOME=/usr/local/zabbix
- 環境変数を再起動後も有効にする
echo "" >> /etc/bashrc echo "# ZABBIX ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export ZABBIX_HOME=$ZABBIX_HOME" >> /etc/bashrc
- 必要なファイルをコピーする
cp -r frontends/php $ZABBIX_HOME/frontends ls $ZABBIX_HOME/frontends/*/.htaccess | xargs rm -f
- インストールディレクトリを作成する
- 不要なソースコードを削除する
cd ../ rm -rf zabbix*
- インストールしたディレクトリに移動する
cd $ZABBIX_HOME
- Apacheの設定を行う
- 設定ファイルを編集する
cat >> $APACHE_HOME/conf/httpd.conf << EOT # Zabbix Configuration <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> AddType text/html .php Alias /zabbix $ZABBIX_HOME/frontends <Directory "$ZABBIX_HOME/frontends"> Options None AllowOverride None Require all granted DirectoryIndex index.php <IfModule php7_module> php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value max_input_vars 10000 php_value always_populate_raw_post_data -1 php_value date.timezone Asia/Tokyo </IfModule> </Directory> <Directory "$ZABBIX_HOME/frontends/conf"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/app"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/include"> Require all denied </Directory> <Directory "$ZABBIX_HOME/frontends/local"> Require all denied </Directory> EOT
- 再起動して設定を反映する。
apachectl restart
- 設定ファイルを編集する
- Frontendの初期設定を行う
- 下記にブラウザでアクセスする
http://<ホスト名 or IPアドレス>/zabbix/
- Next Step
- PHP設定の要件チェックが行われる
不備がある場合、PHPのモジュール追加、設定を行いApacheを再起動した後、再度ここまで進める - Next Step
- DB接続情報を入力する
基本的に全て入力済みなので、ホストとパスワードのみ入力すればよい
※「Database host」はデフォルトの「localhost」だとUNIXソケット(/tmp/mysql.sock)を使用するが、エラーが出る場合がある。その場合、「127.0.0.1」を指定する。
※MariaDBのソケットも同様のパスを指定している。
Database type:MySQL
Database host:localhost
Database port:0(default port)
Database name:zabbix
User:zabbix
Password:zabbix - Next Step
- Zabbix Server情報を入力する
デフォルトのままでよい - Next Step
- Next Step
- Finish
※「Unable to create the configuration file.」というエラーが表示される場合、PHPのディレクトリの権限がなく、設定ファイルが生成できない。
次のコマンドで所有者が「apache」になっていることを確認する
ls -ld $ZABBIX_HOME/frontends
異なる場合は所有者を変更する。
更に、次のコマンドで、「apache」ユーザでapacheが動作していることを確認する
ps aux | grep httpd
異なる場合、apacheの実行ユーザを変更する。
egrep "^(User|Group)" $APACHE_HOME/conf/httpd.conf sed -e "s/^User daemon/User apache/" -e "s/^Group daemon/Group apache/" -i $APACHE_HOME/conf/httpd.conf egrep "^(User|Group)" $APACHE_HOME/conf/httpd.conf apachectl restart
- 下記にブラウザでアクセスする
- 次のユーザ名でアカウントする
Admin / zabbix
ホストのZabbix Agentが緑点灯しない
設定 > ホスト ページのZabbix Agentが緑点灯しないことがある。
このままでもZabbix Agentによる監視は可能であるが、気になる場合は下記対応で直る可能性がある。
※Zabbix Agentによる監視ができていない場合、zabbix_agentd.confの「ServerActive」、「Hostname」設定が間違っている可能性が高い。
- ホストのステータスを有効、無効、有効と切り替える
- 設定変更ページからエージェントのインターフェースのIPアドレス or ホスト名を適当な値に変更して保存する。
保存後、再度元に戻す。
自作アイテム
変更後は再起動が必要
service zabbix-agent restart
Linux
ディスク使用量
- UserParameter
UserParameter=my.disk.utilization.byte[*],df | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 3
- アイテム情報
Linux - Disk Utilization : <ディスク> (byte)
- キー
my.disk.utilization.byte[*]
- 単位
byte
- 乗数
1024
- キー
ディスク使用率
- UserParameter
UserParameter=my.disk.utilization.percent[*],df | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 5 | sed "s/%//"
- アイテム情報
Linux - Disk Utilization : <ディスク> (%)
- キー
my.disk.utilization.percent[*]
- 単位
%
- キー
ディスク残量
- UserParameter
UserParameter=my.disk.available.byte[*],df | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 4
- アイテム情報
Linux - Disk Available : <ディスク> (byte)
- キー
my.disk.available.byte[*]
- 単位
byte
- 乗数
1024
- キー
ディスク残量率
- UserParameter
UserParameter=my.disk.available.percent[*],expr 100 - `df | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 5 | sed "s/%//"`
- アイテム情報
Linux - Disk Available : <ディスク> (%)
- キー
my.disk.available.percent[*]
- 単位
%
- キー
ディスク読み込み (bps)
sysstatパッケージが必要
- UserParameter
UserParameter=my.disk.read.bps[*],iostat -k | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 3
- アイテム情報
Linux - Disk Read : <ディスク> (bps)
- キー
my.disk.read.bps[*]
- データ型
数値(浮動小数)
- 単位
bps
- 乗数
1024
- キー
ディスク書き込み (bps)
sysstatパッケージが必要
- UserParameter
UserParameter=my.disk.write.bps[*],iostat -k | grep $1 | sed 's/\s\{1,\}/ /g' | cut -d " " -f 4
- アイテム情報
Linux - Disk Write : <ディスク> (bps)
- キー
my.disk.write.bps[*]
- データ型
数値(浮動小数)
- 単位
bps
- 乗数
1024
- キー
TCP/UDPコネクション数 (IPv4)
- UserParameter
UserParameter=my.network.connections,netstat -notu | grep -v :: | grep [0-9] | wc -l
- アイテム情報
Linux - TCP/UDP Connections
- キー
my.network.connections
- キー
メモリ使用率
- UserParameter
UserParameter=my.memory.utilization.percent,expr 100 \* `free | grep Mem | sed 's/\s\{1,\}/ /g' | cut -f 3 -d " "` / `free | grep Mem | sed 's/\s\{1,\}/ /g' | cut -f 2 -d " "`
- アイテム情報
Linux - Memory Utilization (%)
- キー
my.memory.utilization.percent
- 単位
%
- キー
メモリ残量率
- UserParameter
UserParameter=my.memory.available.percent,expr 100 - 100 \* `free | grep Mem | sed 's/\s\{1,\}/ /g' | cut -f 3 -d " "` / `free | grep Mem | sed 's/\s\{1,\}/ /g' | cut -f 2 -d " "`
- アイテム情報
Linux - Memory Available (%)
- キー
my.memory.available.percent
- 単位
%
- キー
メモリ使用量
- UserParameter
UserParameter=my.memory.utilization.byte,free | grep Mem | sed 's/\s\{1,\}/ /g' | cut -f 3 -d " "
- アイテム情報
Linux - Memory Utilization (byte)
- キー
my.memory.utilization.byte
- 単位
byte
- キー
Apache
apachectl fullstatusコマンドが使用できる必要できるようディレクティブを設定しておく必要がある。
また、apachectlスクリプトを一部修正する。
vi `which apachectl`旧:LYNX=”/usr/bin/links -dump”
新:LYNX=”/usr/bin/links -dump -no-home”
Requests / Second
- UserParameter
UserParameter=my.apache.rps,/usr/local/apache-httpd/bin/apachectl fullstatus | grep requests/sec | sed 's/\s\{1,\}/ /g' | cut -d " " -f 2
- アイテム情報
Apache - Requests / Second
- キー
my.apache.rps
- データ型
数値(浮動小数)
- キー
Processing Workers
- UserParameter
UserParameter=my.apache.pworker,/usr/local/apache-httpd/bin/apachectl fullstatus | grep workers|sed 's/\s\{1,\}/ /g' | cut -d " " -f 2
- アイテム情報
Apache - Processing Workers
- キー
my.apache.pworker
- キー
Idle Workers
- UserParameter
UserParameter=my.apache.iworker,/usr/local/apache-httpd/bin/apachectl fullstatus | grep workers | sed 's/\s\{1,\}/ /g' | cut -d " " -f 7
- アイテム情報
Apache - Idle Workers
- キー
my.apache.iworker
- キー
CPU使用率
- UserParameter
UserParameter=my.apache.cpu,printf 0;/usr/local/apache-httpd/bin/apachectl fullstatus|grep "CPU load" | sed 's/\s\{1,\}/ /g' | cut -d " " -f 9 | sed "s/%//g"
- アイテム情報
Apache - CPU Utilization
- キー
my.apache.cpu
- データ型
数値(浮動小数)
- 単位
%
- キー
最大応答時間
アクセスログに応答時間を出力している必要がある。
またaccess_log読み取れるよう、ディレクトリに実行権限をつける。
※実行ユーザはzabbixではないため、apacheグループにzabbixユーザを入れる対応は出来ない。
chmod o+rx /etc/httpd/logs
- スクリプト
以下のスクリプトを設置する。
- パス
/usr/local/bin/apache_accesslog_maxresponse_getter.sh
- 内容
if [ "$1" = "" ]; then TAIL_TARGET=100 else TAIL_TARGET=$1 fi if [ "$2" = "" ]; then TIME_ROLL=100 else TIME_ROLL=$2 fi if [ "$3" = "" ]; then ACCESS_LOG=/etc/httpd/logs/access_log else ACCESS_LOG=$3 fi compared_time=`date +"%Y%m%d%H%M%S"` compared_time=`expr $compared_time - $TIME_ROLL` max=0 IFS=$'\n' for next in `tail -n $TAIL_TARGET $ACCESS_LOG`; do time=`echo $next | cut -c 1-4,6-7,9-10,17-18,20-21,23-24` if [ "$time" -ge "$compared_time" ]; then response=`echo $next | sed "s/.*(//g" | sed "s/ .*//g"` if [ "$max" -lt "$response" ]; then max=$response fi fi done echo $max
- パス
- UserParameter
UserParameter=my.apache.response.maxtime[*],/usr/local/bin/apache_accesslog_maxresponse_getter.sh
- アイテム情報
Apache - Max Response Time
- キー
my.apache.response.maxtime[100,100]
- データ型
数値(浮動小数)
- キー
プロセス数
- UserParameter
UserParameter=my.apache.processes,ps aux | grep "^apache" | wc -l
- アイテム情報
Apache - Processes Count
- キー
my.apache.processes
- キー
Memcahced
CPU使用率
- UserParameter
UserParameter=my.memcahced.cpu,pidstat|grep memcached|sed 's/\s\{1,\}/ /g'|cut -d " " -f 7
- アイテム情報
Memcahced - CPU Utilization
- キー
my.memcahced.cpu
- データ型
数値(浮動小数)
- 単位
%
- キー
メモリ使用率
- UserParameter
UserParameter=my.memcahced.memory,ps aux | grep memc | grep -v grep | sed 's/\s\{1,\}/ /g'|cut -d " " -f 4
- アイテム情報
Memcahced - Memory Utilization
- キー
my.memcahced.memory
- データ型
数値(浮動小数)
- 単位
%
- キー
データ使用率
- UserParameter
UserParameter=my.memcahced.data.percent,expr `/usr/local/memcached/bin/memcached-tool localhost stats | grep " bytes " | sed "s/[^0-9]*//g"` \* 100 / `/usr/local/memcached/bin/memcached-tool localhost stats | grep limit_maxbytes | sed "s/[^0-9]*//g"`
- アイテム情報
Memcahced - Data Usage (%)
- キー
my.memcahced.data.percent
- 単位
%
- キー
コネクション数
- UserParameter
UserParameter=my.memcahced.connections.all,netstat -nao|grep 11211|egrep -v "LISTEN|udp"|wc -l
- アイテム情報
Memcahced - Connections Count : All
- キー
my.memcahced.connections.all
- キー
memcached-toolによる各種値
- UserParameter
UserParameter=my.memcahced.memcachedtool[*],/usr/local/memcached/bin/memcached-tool localhost stats|grep "$1"|head -n 1|sed "s/[^0-9]*//g"
- データ量
- アイテム情報
Memcahced - Data Usage (byte)
- キー
my.memcahced.memcachedtool[byte]
- 単位
byte
- キー
- アイテム情報
- アイテム数
- アイテム情報
Memcahced - Items Count
- キー
my.memcahced.items
- キー
- アイテム情報
- アクティブコネクション数
- アイテム情報
Memcahced - Connections Count : Active
- キー
my.memcahced.memcachedtool[curr_connections]
- キー
- アイテム情報
- 削除コマンド数(Hit)
- アイテム情報
Memcahced - Command Count : Delete (Hit)
- キー
my.memcahced.memcachedtool[delete_hits]
- キー
- アイテム情報
- 削除コマンド数(Miss)
- アイテム情報
Memcahced - Command Count : Delete (Miss)
- キー
my.memcahced.memcachedtool[delete_misses]
- キー
- アイテム情報
- 取得コマンド数
- アイテム情報
Memcahced - Command Count : Get
- キー
my.memcahced.memcachedtool[cmd_get]
- キー
- アイテム情報
- 保存コマンド数
- アイテム情報
Memcahced - Command Count : Set
- キー
my.memcahced.memcachedtool[cmd_set]
- キー
- アイテム情報
- 読み込みデータ量
- アイテム情報
Memcahced - Data Read
- キー
my.memcahced.memcachedtool[bytes_read]
- 保存時の計算
差分
- キー
- アイテム情報
- 書き込みデータ量
- アイテム情報
Memcahced - Data Written
- キー
my.memcahced.memcachedtool[bytes_written]
- 保存時の計算
差分
- キー
- アイテム情報
- データ領域使用率
- アイテム情報
Memcahced - Data Space Usage (%)
- キー
my.memcahced.data.percent
- キー
- アイテム情報
- データ領域使用量
- アイテム情報
Memcahced - Data Space Usage (byte)
- キー
my.memcahced.memcachedtool[byte]
- キー
- アイテム情報
- 破棄アイテム数
- アイテム情報
Memcahced - Dropped Items Count
- キー
my.memcahced.memcachedtool[evictions]
- 保存時の計算
差分
- キー
- アイテム情報
- SLAB枯渇数
- アイテム情報
Memcahced - SLAB Exhausted Count
- キー
my.memcahced.fullcount
- キー
- アイテム情報
- 取得失敗回数
- アイテム情報
Memcahced - Get Misses
- キー
my.memcahced.memcachedtool[get_misses]
- 保存時の計算
差分
- キー
- アイテム情報
- アイテム数
- アイテム情報
Memcahced - Items Count
- キー
my.memcahced.memcachedtool[curr_items]
- キー
- アイテム情報
- コネクション拒否回数
- アイテム情報
Memcahced - Rejected Connections
- キー
my.memcahced.memcachedtool[listen_disabled_num]
- 保存時の計算
差分
- キー
- アイテム情報
MariaDB
Zabbix Agentの設定
- UserParameter
# MariaDB UserParameter=my.mariadb.mysqladmin_extended-status[*],/usr/local/mariadb/bin/mysqladmin extended-status -u root|egrep " $1 "|sed -r -e "s/ +\|$//" -e "s/.* //" UserParameter=my.mariadb.mysqladmin_ping,/usr/local/mariadb/bin/mysqladmin ping -u root UserParameter=my.mariadb.mysqladmin_version,mysqladmin version -u root|grep "Server version"|sed -r -e "s/.*\s//g"
アイテムキー
命令実行回数
- アイテム情報
MariaDB - begin operations
- キー
my.mariadb.mysqladmin_extended-status[Com_begin]
- 保存時の計算
差分
- キー
受信データ量
- アイテム情報
MariaDB - bytes received
- キー
my.mariadb.mysqladmin_extended-status[Bytes_received]
- 保存時の計算
差分
- キー
送信データ量
- アイテム情報
MariaDB - bytes sent
- キー
my.mariadb.mysqladmin_extended-status[Bytes_sent]
- 保存時の計算
差分
- キー
commit実行回数
- アイテム情報
MariaDB - commit operations
- キー
my.mariadb.mysqladmin_extended-status[Com_commit]
- 保存時の計算
差分
- キー
select実行回数
- アイテム情報
MariaDB - select operations
- キー
my.mariadb.mysqladmin_extended-status[Com_select]
- 保存時の計算
差分
- キー
update実行回数
- アイテム情報
MariaDB - update operations
- キー
my.mariadb.mysqladmin_extended-status[Com_update]
- 保存時の計算
差分
- キー
delete実行回数
- アイテム情報
MariaDB - delete operations
- キー
my.mariadb.mysqladmin_extended-status[Com_delete]
- 保存時の計算
差分
- キー
insert実行回数
- アイテム情報
MariaDB - insert operations
- キー
my.mariadb.mysqladmin_extended-status[Com_insert]
- 保存時の計算
差分
- キー
クエリ実行回数
- アイテム情報
MariaDB - queries
- キー
my.mariadb.mysqladmin_extended-status[Questions]
- 保存時の計算
差分
- キー
rollback実行回数
- アイテム情報
MariaDB - rollback operations
- キー
my.mariadb.mysqladmin_extended-status[Com_rollback]
- 保存時の計算
差分
- キー
slow queries件数回数
- アイテム情報
MariaDB - slow queries
- キー
my.mariadb.mysqladmin_extended-status[Slow_queries]
- 保存時の計算
差分
- キー
稼働時間
- アイテム情報
MariaDB - uptime
- キー
my.mariadb.mysqladmin_extended-status[Uptime]
- 保存前処理のステップ
- 名前
計算 / 乗数
- パラメータ
0.00001157407
- 名前
- 更新間隔
1d
- 単位
日
死活確認
- アイテム情報
MariaDB - ping
- キー
my.mariadb.mysqladmin_ping
- 保存前処理のステップ1
- 名前
テキスト / 正規表現
- パラメータ パターン
mysqld is alive
- パラメータ 出力
1
- 名前
- 保存前処理のステップ2
- 名前
テキスト / 正規表現
- パラメータ パターン
.*
- パラメータ 出力
0
- 名前
バージョン
- アイテム情報
MariaDB - version
- キー
mysqladmin_version
- 更新間隔
1d
API
APIの概要
- APIはJSON RPCを使用して、JSON形式でメッセージの送受信を行う
- APIにアクセスするURLは以下である
http://<ホスト名>/zabbix/api_jsonrpc.php
使用方法
以下の形式のJSONを送信し、結果をJSON形式で受信する
{ "jsonrpc": "2.0", "method": "<メソッド名>", "params": { "<パラメータ名>": "<パラメータ値>", "<パラメータ名>": "<パラメータ値>", 、、、 }, "id": <リクエスト識別番号>, "auth": "<認証トークン>" }
- method
呼び出すAPI名を指定する。
利用可能なAPIと結果は以下を参照。
https://www.zabbix.com/documentation/2.2/manual/api/reference
- params
使用するmethodに対応するパラメータを指定する。
使用できるパラメータは上記URLを参照。
- id
リクエストに指定した識別番号(自然数)をレスポンスに埋め込まれて返される。
複数同時にリクエストを送信する場合、各レスポンスの識別に利用できる。
1つしか送信しなくてもidの指定は必須である。
- auth
APIを利用する場合、最初にログインして認証トークンを取得する必要がある。
取得したトークンをリクエストに埋め込むことで、APIのリクエストに対して認証が行われる。
データベースの直接利用
テーブル
hosts
- テーブル定義
CREATE TABLE `hosts` ( `hostid` bigint(20) unsigned NOT NULL, `proxy_hostid` bigint(20) unsigned DEFAULT NULL, `host` varchar(64) NOT NULL DEFAULT '', `status` int(11) NOT NULL DEFAULT '0', `disable_until` int(11) NOT NULL DEFAULT '0', `error` varchar(128) NOT NULL DEFAULT '', `available` int(11) NOT NULL DEFAULT '0', `errors_from` int(11) NOT NULL DEFAULT '0', `lastaccess` int(11) NOT NULL DEFAULT '0', `ipmi_authtype` int(11) NOT NULL DEFAULT '0', `ipmi_privilege` int(11) NOT NULL DEFAULT '2', `ipmi_username` varchar(16) NOT NULL DEFAULT '', `ipmi_password` varchar(20) NOT NULL DEFAULT '', `ipmi_disable_until` int(11) NOT NULL DEFAULT '0', `ipmi_available` int(11) NOT NULL DEFAULT '0', `snmp_disable_until` int(11) NOT NULL DEFAULT '0', `snmp_available` int(11) NOT NULL DEFAULT '0', `maintenanceid` bigint(20) unsigned DEFAULT NULL, `maintenance_status` int(11) NOT NULL DEFAULT '0', `maintenance_type` int(11) NOT NULL DEFAULT '0', `maintenance_from` int(11) NOT NULL DEFAULT '0', `ipmi_errors_from` int(11) NOT NULL DEFAULT '0', `snmp_errors_from` int(11) NOT NULL DEFAULT '0', `ipmi_error` varchar(128) NOT NULL DEFAULT '', `snmp_error` varchar(128) NOT NULL DEFAULT '', `jmx_disable_until` int(11) NOT NULL DEFAULT '0', `jmx_available` int(11) NOT NULL DEFAULT '0', `jmx_errors_from` int(11) NOT NULL DEFAULT '0', `jmx_error` varchar(128) NOT NULL DEFAULT '', `name` varchar(64) NOT NULL DEFAULT '', `flags` int(11) NOT NULL DEFAULT '0', `templateid` bigint(20) unsigned DEFAULT NULL, PRIMARY KEY (`hostid`), KEY `hosts_1` (`host`), KEY `hosts_2` (`status`), KEY `hosts_3` (`proxy_hostid`), KEY `hosts_4` (`name`), KEY `hosts_5` (`maintenanceid`), KEY `c_hosts_3` (`templateid`), CONSTRAINT `c_hosts_3` FOREIGN KEY (`templateid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE, CONSTRAINT `c_hosts_1` FOREIGN KEY (`proxy_hostid`) REFERENCES `hosts` (`hostid`), CONSTRAINT `c_hosts_2` FOREIGN KEY (`maintenanceid`) REFERENCES `maintenances` (`maintenanceid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
interface
- テーブル定義
CREATE TABLE `interface` ( `interfaceid` bigint(20) unsigned NOT NULL, `hostid` bigint(20) unsigned NOT NULL, `main` int(11) NOT NULL DEFAULT '0', `type` int(11) NOT NULL DEFAULT '0', `useip` int(11) NOT NULL DEFAULT '1', `ip` varchar(64) NOT NULL DEFAULT '127.0.0.1', `dns` varchar(64) NOT NULL DEFAULT '', `port` varchar(64) NOT NULL DEFAULT '10050', PRIMARY KEY (`interfaceid`), KEY `interface_1` (`hostid`,`type`), KEY `interface_2` (`ip`,`dns`), CONSTRAINT `c_interface_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
hosts_groups
- テーブル定義
CREATE TABLE `hosts_groups` ( `hostgroupid` bigint(20) unsigned NOT NULL, `hostid` bigint(20) unsigned NOT NULL, `groupid` bigint(20) unsigned NOT NULL, PRIMARY KEY (`hostgroupid`), UNIQUE KEY `hosts_groups_1` (`hostid`,`groupid`), KEY `hosts_groups_2` (`groupid`), CONSTRAINT `c_hosts_groups_2` FOREIGN KEY (`groupid`) REFERENCES `groups` (`groupid`) ON DELETE CASCADE, CONSTRAINT `c_hosts_groups_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
hosts_templates
- テーブル定義
CREATE TABLE `hosts_templates` ( `hosttemplateid` bigint(20) unsigned NOT NULL, `hostid` bigint(20) unsigned NOT NULL, `templateid` bigint(20) unsigned NOT NULL, PRIMARY KEY (`hosttemplateid`), UNIQUE KEY `hosts_templates_1` (`hostid`,`templateid`), KEY `hosts_templates_2` (`templateid`), CONSTRAINT `c_hosts_templates_2` FOREIGN KEY (`templateid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE, CONSTRAINT `c_hosts_templates_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
items
- テーブル定義
CREATE TABLE `items` ( `itemid` bigint(20) unsigned NOT NULL, `type` int(11) NOT NULL DEFAULT '0', `snmp_community` varchar(64) NOT NULL DEFAULT '', `snmp_oid` varchar(255) NOT NULL DEFAULT '', `hostid` bigint(20) unsigned NOT NULL, `name` varchar(255) NOT NULL DEFAULT '', `key_` varchar(255) NOT NULL DEFAULT '', `delay` int(11) NOT NULL DEFAULT '0', `history` int(11) NOT NULL DEFAULT '90', `trends` int(11) NOT NULL DEFAULT '365', `status` int(11) NOT NULL DEFAULT '0', `value_type` int(11) NOT NULL DEFAULT '0', `trapper_hosts` varchar(255) NOT NULL DEFAULT '', `units` varchar(255) NOT NULL DEFAULT '', `multiplier` int(11) NOT NULL DEFAULT '0', `delta` int(11) NOT NULL DEFAULT '0', `snmpv3_securityname` varchar(64) NOT NULL DEFAULT '', `snmpv3_securitylevel` int(11) NOT NULL DEFAULT '0', `snmpv3_authpassphrase` varchar(64) NOT NULL DEFAULT '', `snmpv3_privpassphrase` varchar(64) NOT NULL DEFAULT '', `formula` varchar(255) NOT NULL DEFAULT '1', `error` varchar(128) NOT NULL DEFAULT '', `lastlogsize` bigint(20) unsigned NOT NULL DEFAULT '0', `logtimefmt` varchar(64) NOT NULL DEFAULT '', `templateid` bigint(20) unsigned DEFAULT NULL, `valuemapid` bigint(20) unsigned DEFAULT NULL, `delay_flex` varchar(255) NOT NULL DEFAULT '', `params` text NOT NULL, `ipmi_sensor` varchar(128) NOT NULL DEFAULT '', `data_type` int(11) NOT NULL DEFAULT '0', `authtype` int(11) NOT NULL DEFAULT '0', `username` varchar(64) NOT NULL DEFAULT '', `password` varchar(64) NOT NULL DEFAULT '', `publickey` varchar(64) NOT NULL DEFAULT '', `privatekey` varchar(64) NOT NULL DEFAULT '', `mtime` int(11) NOT NULL DEFAULT '0', `flags` int(11) NOT NULL DEFAULT '0', `filter` varchar(255) NOT NULL DEFAULT '', `interfaceid` bigint(20) unsigned DEFAULT NULL, `port` varchar(64) NOT NULL DEFAULT '', `description` text NOT NULL, `inventory_link` int(11) NOT NULL DEFAULT '0', `lifetime` varchar(64) NOT NULL DEFAULT '30', `snmpv3_authprotocol` int(11) NOT NULL DEFAULT '0', `snmpv3_privprotocol` int(11) NOT NULL DEFAULT '0', `state` int(11) NOT NULL DEFAULT '0', `snmpv3_contextname` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`itemid`), UNIQUE KEY `items_1` (`hostid`,`key_`), KEY `items_3` (`status`), KEY `items_4` (`templateid`), KEY `items_5` (`valuemapid`), KEY `items_6` (`interfaceid`), CONSTRAINT `c_items_4` FOREIGN KEY (`interfaceid`) REFERENCES `interface` (`interfaceid`), CONSTRAINT `c_items_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE, CONSTRAINT `c_items_2` FOREIGN KEY (`templateid`) REFERENCES `items` (`itemid`) ON DELETE CASCADE, CONSTRAINT `c_items_3` FOREIGN KEY (`valuemapid`) REFERENCES `valuemaps` (`valuemapid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
triggers
- テーブル定義
CREATE TABLE `triggers` ( `triggerid` bigint(20) unsigned NOT NULL default '0', `expression` varchar(255) NOT NULL default '', `description` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', `status` int(11) NOT NULL default '0', `value` int(11) NOT NULL default '0', `priority` int(11) NOT NULL default '0', `lastchange` int(11) NOT NULL default '0', `dep_level` int(11) NOT NULL default '0', `comments` blob NOT NULL, `error` varchar(128) NOT NULL default '', `templateid` bigint(20) unsigned NOT NULL default '0', `type` int(11) NOT NULL default '0', PRIMARY KEY (`triggerid`), KEY `triggers_1` (`status`), KEY `triggers_2` (`value`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
正規表現
使用中か確認する
select key_ from items where key_ like '%<正規表現名>%';
バックアップ
設定系のみバックアップし、イベントなどはバックアップしない
使用量の確認
- 直接実行する場合
mysql zabbix -e "select table_name, table_rows, floor((data_length)/1024/1024) as data_MB \ from information_schema.tables where table_schema=database() order by (data_MB) desc;"
- mysqlコマンドでログインして行う場合
use zabbix; select table_name, table_rows, floor((data_length)/1024/1024) as data_MB from information_schema.tables where table_schema=database() order by (data_MB) desc;
バックアップ
mysqldump -u zabbix -p zabbix \ --ignore-table=zabbix.alerts \ --ignore-table=zabbix.history \ --ignore-table=zabbix.history_uint \ --ignore-table=zabbix.history_log \ --ignore-table=zabbix.history_str \ --ignore-table=zabbix.history_text \ --ignore-table=zabbix.auditlog \ --ignore-table=zabbix.auditlog_details \ --ignore-table=zabbix.trends \ --ignore-table=zabbix.trends_uint \ --ignore-table=zabbix.events \ --ignore-table=zabbix.events_history_relation \ --ignore-table=zabbix.sessions \ --ignore-table=zabbix.user_history \ --skip-comments --skip-lock-tables --no-create-info > zabbix_mysql_dump.`date +%Y%m%d`
ツール
zabbix_get
Zabbix Agentに対し、特定監視項目の現在の値の取得を行う。
ただし、Zabbix Agent設定で指定しているサーバからしか取得できない。
これにはローカルホストも含まれる。
- 書式
zabbix_get -s <監視対象> -k <監視項目名>
存在しない監視項目名を指定したり、Serverで指定しているホスト以外から実行した場合は何も表示されない。
Serverで127.0.0.1と指定している場合は、zabbix_get でlocalhostと指定しても何も表示されない。