Zabbix 3.4.12
公式ページ

Contents

Zabbixについて


構成要素


Zabbixの構成要素はいくつかのノードに分けられる。
代表的なものは、サーバ、エージェント、データベース、フロントエンドで、それぞれ以下の役割を持つ。

最も簡単な構成では、サーバ、フロントエンド、データベースは同じホスト上で稼動させる。
他構成次第でプロキシや、Javaゲートウェイなどのノードが使用される。



用語


アイテム


Zabbixが各ホストに対して行うデータ監視項目。
整数値、浮動小数値、文字列値等のデータ型、単位、保存期間など各種設定を行うことが出来る。
アイテムのデータの取得はSNMP、Zabbixエージェントなど、いくつかの方法がある。
アイテムはキーによって識別される。

アイテムキー


アイテムを識別する文字列。
CPU使用率やディスク使用量などによって一意に定まる。
一部を変数化可能で、特定のパスのディスク使用量などというように設定可能。

アプリケーション


アイテムをグループ化したもの

タイプ


アイテムの監視方法のこと。
Zabbix Agentによる監視やエージェント不要の監視方法などがある。

ウェブシナリオ


連続したHTTPアクセスにより、特定のWEBページ内を巡回可能かどうかの監視が行える。
これによってログインが必要なサイトでログインし、その後特定のページが閲覧できるかといった監視を行うことが出来る。
1回のHTTPアクセスをウェブステップと呼び、シナリオは複数回のステップにより構成される。

マクロ


{$<文字列>}の形式で定義でき、値の対応を記述することができる。
マクロはホスト単位、テンプレート単位、グローバルで設定可能で、アイテムやトリガーなどで使用することで、
共通の設定を使いつつもホスト毎に使用する値を変えるといったことが可能となる。

テンプレート


アイテムやトリガー、グラフなどを登録しておき、ホスト作成時に適用することで、
テンプレート内で設定したアイテムなどが自動でそのホストでも有効になる。
テンプレート内で定義したアイテムなどは一部を除きテンプレートで設定した統一した共通設定値が利用されるため、
テンプレートを設定変更するとテンプレートを使用する全てのホストに一括反映できる。
共通項目内で個別の値を使用したい場合はマクロを使用すればよい。

ヒストリ


監視データのこと。

トレンド


一定期間のヒストリから算出した最大値や平均などの統計データのこと。

アクション


アイテムが指定した状態になった時にZabbix Serverが行う内容の事。
アラートメールを送ったり、指定したコマンド(リモートコマンド)を実行することができる。
異常状態から復帰した際に再度メールなどメッセージを送ることができるが、これをリカバリメッセージという。

正規表現


ログ監視で使用する正規表現データ。
正規表現データとして独立させることで、複数のログ監視に割り当てることができる。
正規表現に一致する特定文字列を障害とする、または障害としないことができる。
これはトリガーと目的は同じであるが、トリガーはサーバ側で判断するのに対し、正規表現はクライアント側で判断する。
つまり、正規表現を用いると、サーバ側に転送するログ量を制御できる。
反面、サーバで閲覧可能なログに欠損が発生するので、どちらを使用するかは状況により異なる。

オートディスカバリー


特定のネットワークアドレスに新規サーバが起動した場合、自動で検知して監視対象に加える機能。
そのサーバがシャットダウンした際に自動で削除することも可能。
ただしその場合は、過去の収集データが消えてしまう。
サーバ発見時に監視の有効化、終了時に無効化することでこれを防ぐことができる。
いずれにせよ死活監視をするとアラートが発生することになるので、注意。


サーバー構築


構築環境




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を開ける

  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=http
  2. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  3. ルールを適用する
    firewall-cmd --add-service=http --zone=public --permanent
  4. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  5. 設定を再読み込みして反映させる
    firewall-cmd --reload

HTTPSも開ける場合

  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=https
  2. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
  3. ルールを適用する
    firewall-cmd --add-service=https --zone=public --permanent
  4. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
  5. 設定を再読み込みして反映させる
    firewall-cmd --reload

Zabbix Serverポートを開ける

Zabbix Agentからの通知のような受動的な監視を行う場合に必要となる。

  1. 現在ルールが定義されていないか確認
    firewall-cmd --permanent --info-service=zabbix_server
  2. 新しいルールを定義
    firewall-cmd --permanent --new-service=zabbix_server
    firewall-cmd --permanent --service=zabbix_server --add-port=10051/tcp
  3. ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=zabbix_server
  4. 現在ルールが適用されていないことを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_server
  5. ルールを適用する
    firewall-cmd --permanent --add-service=zabbix_server --zone=public
  6. ルールが適用されていることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_server
  7. 設定を再読み込みして反映させる
    firewall-cmd --reload

Zabbix Agentポートを開ける

別のサーバからZabbix Agentによる監視を受ける場合に必要となる。

  1. 現在ルールが定義されていないか確認
    firewall-cmd --permanent --info-service=zabbix_agent
  2. 新しいルールを定義
    firewall-cmd --permanent --new-service=zabbix_agent
    firewall-cmd --permanent --service=zabbix_agent --add-port=10050/tcp
  3. ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=zabbix_agent
  4. 現在ルールが適用されていないことを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
  5. ルールを適用する
    firewall-cmd --permanent --add-service=zabbix_agent --zone=public
  6. ルールが適用されていることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
  7. 設定を再読み込みして反映させる
    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をソースコードインストールしたとする。

データベースの作成


  1. ログインする
    mysql -p
  2. データベースを作成する
    create database zabbix character set utf8;
  3. zabbixユーザを作成する
    ユーザ名:zabbix、パスワード:zabbixで作成している
    • ローカルホストのデータベースを使用する場合
      grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
    • リモートホストのデータベースを使用する場合
      grant all privileges on zabbix.* to zabbix identified by 'zabbix';
  4. 接続を終了する
    exit

PHPのインストール


参考:php7.2.9

関連パッケージのインストール


yum install libpng-devel libXpm-devel gd gd-devel freetype-devel libxml2-devel gcc  -y

ソースのダウンロード


  1. ダウンロードサイト:http://php.net/downloads.phpからアーカイブのURLを取得する
  2. ダウンロードする
    curl -s -O http://jp2.php.net/distributions/php-<PHP_VERSION>.tar.gz
  3. アーカイブファイルを展開する
    tar xzfv php-*.tar.gz
  4. ソースコードディレクトリへ移動する
    cd php-*

ビルド時のオプション


※二度目以降のビルドの際は、次のコマンドを事前に実行すること
make clean

mysqlndを使用する。mysqliを使用する方法ではZabbixでエラーが出た。

  1. コンパイル最適化設定を行う
    export CFLAGS="-O3 -m64"
  2. 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
  3. ビルドする
    make 2>&1 | tee make.log
  4. インストールする
    make install 2>&1 | tee make_install.log

環境変数等


リンク作成、環境変数設定などを行う
  1. インストールディレクトリへのシンボリックリンクを作成する。
    これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
    各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
    rm -f /usr/local/php
    ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/php
  2. 簡単にアクセスできるように環境変数を設定する
    export PHP_HOME=/usr/local/php
  3. ツール類にパスを通す
    export PATH=$PHP_HOME/bin:$PATH
  4. 環境変数を再起動後も有効にする
    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
  5. 設定ファイルをコピーする
    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などのデータベースの用意が必要。
インストールする数が多いので、パッケージの方が簡単ではあるが、反面インストールするソフトウェアのディレクトリを完全に分離できない。

パッケージからインストール


参考

  1. 関連パッケージをインストールするためにリポジトリを追加する(バージョンによって異なる)
    rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
    # 古いバージョンのリポジトリが登録されている場合、ここで削除される
  2. インストールする
    yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
  3. 必要に応じて以下もインストールする
    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

ソースコードからインストール



  1. 関連パッケージをインストールする
    yum install libevent-devel pcre-devel fping -y
  2. ソースコードを取得する
    1. ダウンロードサイトからURLを取得する
    2. ダウンロードする
      curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
    3. アーカイブファイルを展開する
      tar xzfv zabbix-*.tar.gz
    4. ソースコードディレクトリへ移動する
      cd zabbix-*
  3. コンパイル、インストールを行う
    1. コンパイル最適化設定を行う
      export CFLAGS="-O3 -m64"
    2. 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.
    3. コンパイルする
      make 2>&1 | tee make.log
    4. インストールを行う。
      make install 2>&1 | tee make_install.log
    5. DBライブラリのパスを通す
      ln -s $MARIADB_HOME/lib/libmariadb.so /usr/lib64/libmariadb.so.3
  4. リンク作成、環境変数設定などを行う
    1. インストールディレクトリへのシンボリックリンクを作成する。
      これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
      各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
      rm -f /usr/local/zabbix
      ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
    2. 簡単にアクセスできるように環境変数を設定する
      export ZABBIX_HOME=/usr/local/zabbix
    3. ツール類にパスを通す
      export PATH=$ZABBIX_HOME/bin:$ZABBIX_HOME/sbin:$PATH
    4. 環境変数を再起動後も有効にする
      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
    5. 実行できることを確認する
      zabbix_server -V
      # バージョン情報が出力される
  5. 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
  6. Frontendのインストールを行う
    cp -r frontends/php $ZABBIX_HOME/frontends
    ls $ZABBIX_HOME/frontends/*/.htaccess | xargs rm -f
  7. 不要なソースコードを削除する
    cd ../
    rm -rf zabbix*
  8. systemdの設定する
    1. サーバーのサービスファイルを作成する
      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
    2. エージェントのサービスファイルを作成する
      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
    3. 作成したファイルを反映する
      systemctl daemon-reload
    4. サービスを有効化する
      systemctl enable zabbix-server
      systemctl enable zabbix-agent
    5. サービスが有効化されていることを確認する
      systemctl list-unit-files --type service --no-pager | grep zabbix
  9. インストールしたディレクトリに移動する
    cd $ZABBIX_HOME
  10. 初期設定を行う
    1. ディレクトリ作成
      1. ログ
        ログをsyslogではなくファイルに直接出力する設定を行ったので、出力先のディレクトリを作成する。
        mkdir log
      2. PID
        mkdir run
    2. 基本設定を行う
      ※リモートの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
  11. ファイル所有者を変更する
    chown -R zabbix:zabbix /usr/local/zabbix*
    chown -R apache:apache $ZABBIX_HOME/frontends
  12. Zabbixを起動する
    systemctl start zabbix-server
    systemctl start zabbix-agent
  13. 稼働確認
    systemctl status zabbix-server
    systemctl status zabbix-agent
    正常に起動していない場合、ログを確認する。
    journalctl -u zabbix-server
    journalctl -u zabbix-agent
    cat /var/log/messages
  14. 停止
    systemctl stop zabbix-server
    systemctl stop zabbix-agent
  15. Apacheの設定を行う
    1. 設定ファイルを編集する
      ※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
    2. 再起動して設定を反映する。
      apachectl restart
  16. Frontendの初期設定を行う
    1. 下記にブラウザでアクセスする
      http://<ホスト名 or IPアドレス>/zabbix/
    2. Next Step
    3. PHP設定の要件チェックが行われる
      不備がある場合、PHPのモジュール追加、設定を行いApacheを再起動した後、再度ここまで進める
    4. Next Step
    5. 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
    6. Next Step
    7. Zabbix Server情報を入力する
      デフォルトのままでよい
    8. Next Step
    9. Next Step
    10. 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
  17. 次のユーザ名でアカウントする
    Admin / zabbix

事後的にFrontendの設定変更をしたい場合、下記のパスのファイルを編集する
/usr/local/zabbix/frontends/conf/zabbix.conf.php

言語設定


使用する言語を変更できる。



今回は無料で使用できるGoogle FontのM PLUS 1pを使用する。

  1. ダウンロードする
    mkdir mplus
    cd mplus
    curl -s -o mplus.zip https://fonts.google.com/download?family=M%20PLUS%201p
  2. 展開する
    unzip mplus.zip
    ※unzipがインストールされていない場合はインストールする
    # yum install unzip -y
  3. 普通サイズフォントのみを移動する
    mv MPLUS1p-Regular.ttf $ZABBIX_HOME/frontends/fonts/
  4. 設定変更する
    sed "s/DejaVuSans/MPLUS1p-Regular/g" -i $ZABBIX_HOME/frontends/include/defines.inc.php
  5. その他のフォントファイルを削除する
    cd ../
    rm -rf mplus

管理者のパスワード変更


デフォルトのzabbixからパスワードを変更する

  1. 管理
  2. ユーザー
  3. Adminユーザを選択
  4. パスワード変更
  5. パスワードを入力する
  6. 更新
  7. OK

ゲストユーザの無効


デフォルトユーザであるGuestは削除できないので、無効化しておく。

  1. 管理
  2. ユーザー
  3. Guestユーザを選択
  4. グループからGuestsを削除する
  5. グループにDisabledを追加する
  6. 更新


メール設定


障害時にアラートメールを送信する設定を行う。
Zabbix Serverと同じホストにSMTPサーバが稼動しているとする。

  1. メールサーバを設定する
    1. 管理
    2. メディアタイプ
    3. Emailを選択する
    4. SMTPサーバー、SMTP heloに「localhost」と入力する
    5. 送信元メールアドレスにメールサーバのドメイン名を使用したメールアドレスを記入する
    6. 更新
    7. 不要であれば、Email以外のメディアタイプを無効にしておく
  2. 宛先を登録する
    1. 管理
    2. ユーザー
    3. Adminを選択する
    4. 「メディア」タブを開く
    5. 「追加」
    6. 「送信先」に宛先メールアドレスを入力する
    7. 「指定した深刻度のときに使用」欄を必要に応じて選択する
      ※一般的には軽度の障害か重度の障害以上で良い
    8. 「追加」ボタンをクリックする
    9. 更新
    10. 更新
  3. アクションを設定する
    1. 設定
    2. アクション
    3. 「Report problems to Zabbix administrators」を選択する
    4. 有効にチェックする
    5. 「実行内容」タブを開く
    6. デフォルトの件名、デフォルトのメッセージを適宜修正する
    7. 実行内容の1の変更をクリックする
    8. 「次のメディアのみ使用」ドロップダウンボックスをEmailに変更する
    9. 更新をクリックする
    10. 「復旧時実行内容」タブを開く
    11. 復旧通知の件名、リカバリメッセージを適宜修正する
    12. 更新

メールのみのアカウント作成


障害時などに通知するメールアドレスはユーザアカウントとひも付けられるため、
WEBログインはしないが障害通知用のメールアドレスを登録する場合、専用のアカウントを作成する必要がある。

  1. 管理
  2. ユーザー
  3. ユーザーに画面右部のドロップダウンリストを切り替える
  4. ユーザーの作成
  5. エイリアスからパスワードまでを入力する
  6. グループに「No access to the frontend」を選択して追加する
  7. メディアタブを開く
  8. 「追加」をクリックし、メールアドレスを追加する
  9. 保存
  10. この作成したアカウントを使用してアクションを作成する

Zabbixエージェントのインストール


Zabbixエージェントを監視対象のホストにインストールすることで、様々な情報を取得することができる。
監視対象の各サーバにて下記手順を実施する。

サーバー設定


ユーザ作成


Zabbix用のユーザを作成する
useradd --user-group --no-create-home --shell /sbin/false zabbix

Firewalld設定


  1. 現在ルールが定義されていないか確認
    firewall-cmd --permanent --info-service=zabbix_agent
  2. 新しいルールを定義
    firewall-cmd --permanent --new-service=zabbix_agent
    firewall-cmd --permanent --service=zabbix_agent --add-port=10050/tcp
  3. ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=zabbix_agent
  4. 現在ルールが適用されていないことを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
  5. ルールを適用する
    firewall-cmd --permanent --add-service=zabbix_agent --zone=public
  6. ルールが適用されていることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep zabbix_agent
  7. 設定を再読み込みして反映させる
    firewall-cmd --reload

エージェントのインストール


パッケージからインストール


  1. リポジトリを追加する(バージョンによって異なる)
    rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
  2. パッケージをインストールする
    yum install zabbix-agent -y
  3. 必要に応じて以下もインストールする
    yum install zabbix-sender -y
    yum install zabbix-get -y

ソースコードからインストール



  1. ソースコードを取得する
    1. ダウンロードサイトからURLを取得する
    2. ダウンロードする
      curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
    3. アーカイブファイルを展開する
      tar xzfv zabbix-*.tar.gz
    4. ソースコードディレクトリへ移動する
      cd zabbix-*
  2. コンパイル、インストールを行う
    1. コンパイル最適化設定を行う
      export CFLAGS="-O3 -m64"
    2. 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.
    3. コンパイルする
      make 2>&1 | tee make.log
    4. インストールを行う。
      make install 2>&1 | tee make_install.log
  3. リンク作成、環境変数設定などを行う
    1. インストールディレクトリへのシンボリックリンクを作成する。
      これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
      各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
      rm -f /usr/local/zabbix
      ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
    2. 簡単にアクセスできるように環境変数を設定する
      export ZABBIX_HOME=/usr/local/zabbix
    3. ツール類にパスを通す
      export PATH=$ZABBIX_HOME/bin:$ZABBIX_HOME/sbin:$PATH
    4. 環境変数を再起動後も有効にする
      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
  4. 不要なソースコードを削除する
    cd ../
    rm -rf zabbix*
  5. systemdの設定する
    1. エージェントのサービスファイルを作成する
      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
    2. 作成したファイルを反映する
      systemctl daemon-reload
    3. サービスを有効化する
      systemctl enable zabbix-agent
    4. サービスが有効化されていることを確認する
      systemctl list-unit-files --type service --no-pager | grep zabbix
  6. インストールしたディレクトリに移動する
    cd $ZABBIX_HOME
  7. 初期設定を行う
    1. ディレクトリ作成
      1. ログ
        ログをsyslogではなくファイルに直接出力する設定を行ったので、出力先のディレクトリを作成する。
        mkdir log
      2. PID
        mkdir run
    2. 基本設定を行う
      設定ファイルを作成する(デフォルトファイルを上書きする)
      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
  8. ファイル所有者を変更する
    chown -R zabbix:zabbix /usr/local/zabbix*
  9. Zabbixを起動する
    systemctl start zabbix-agent
  10. 稼働確認
    systemctl status zabbix-agent
    正常に起動していない場合、ログを確認する。
    journalctl -u zabbix-agent
    cat /var/log/messages
  11. 停止
    systemctl stop zabbix-agent


エージェントの起動




設定変更


設定ファイルが以下のパスに存在するので、修正することで設定変更を行うことができる。
/etc/zabbix/zabbix_agentd.conf
設定変更後は再起動が必要。
systemctl restart zabbix-agent

設定項目


基本設定







ログ設定





サーバ設定


サーバとして予め設定したホストからの要求しかエージェントは値を返さない。
そのため、サーバのホスト名 / IPアドレスの設定を行う必要がある。



アクティブチェック


サーバで監視対象を追加した際の識別子で、サーバ側とエージェント側で一致させる必要がある。
実際の表示名は別に設定できるので何でもよい。


設定ファイル読み込み


外部に定義した別の設定ファイルをロードすることができる。
ディレクトリを指定した場合は、その直下のファイルがロードされる。



リモートコマンド


サーバからの任意のリモートコマンドによる監視を行う設定をする。
監視項目は下記
system.run[command,<mode>]


system.runをサーバ側で設定する場合、エージェントサーバ側にリモートコマンドをの実行を許可する設定が必要である。
EnableRemoteCommandsの項目で設定し、値は0か1をとり、0は不許可、1は許可である。


独自監視項目の作成


特定のスクリプトやコマンドを実行して値を取得することで、その値を監視することができる。



ここで設定したキー名を用いてZabbixサーバのアイテムのキー値に設定する

設定した監視項目が正しく動作するかはzabbix_getコマンドにより確認できる
zabbix_get -s <監視対象> -k <監視項目名>
※存在しない監視項目名を指定したり、Serverで指定しているホスト以外から実行した場合は何も表示されない。Serverで127.0.0.1と指定している場合は、zabbix_get でlocalhostと指定しても何も表示されない。


設定例


監視サーバ


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管理画面からの監視設定


監視対象ホストの登録



  1. 設定
  2. ホスト
  3. 「ホストの作成」ボタンをクリック
  4. 必要情報を入力する
    1. ホストを設定する
      • ホスト名
        エージェントで設定しているホスト名。エージェント側設定と一致している必要がある。
      • 表示名
        Zabbix Frontend上での表示名。省略した場合、「ホスト名」と同じになる。
      • エージェントのインターフェース
        エージェントのIPアドレスかホスト名を入力する。
      • SNMPなど監視方法によって使用するインタフェースを選択し、不要なものは削除する
    2. テンプレートを適用する
      1. 「新規テンプレートをリンク」から選択をクリックする
      2. 適用したいテンプレートを選択する
      3. 選択をクリックする
      4. 追加をクリックする
    3. マクロを設定する
  5. 更新

グラフの作成


数値データを監視している場合、自動的に時間軸と値の2軸の折れ線グラフが作られるが、
円グラフや積算グラフを表示させる場合や、複数の項目を1つのグラフ内で表示させる場合はグラフの作成を行う必要がある。

  1. 設定
  2. グラフを作成するホスト / テンプレートを選択する
  3. グラフを作成するホスト / テンプレートの「グラフ」をクリック
  4. 各パラメータを入力する
  5. 表示させたいアイテムを追加する
    1. 追加したアイテムのパラメータを設定する
      • 関数
        グラフを表示した(表示中に時間の単位を変更した)際の時間軸単位に複数の値が存在する場合、どの値を表示するかを決定する
        • すべて
          最小、平均、最大をすべて表示する
        • 最小
        • 平均
        • 最大
  6. 追加

ダッシュボードに追加



  1. 監視データ > ダッシュボード
  2. ダッシュボードの変更
  3. ウィジェットを追加
  4. タイプをグラフに変更する
  5. グラフ名を入力する
  6. グラフ選択ボタンをクリックし、表示したいグラフを選択する
  7. 追加
  8. 変更を保存

アプリケーションの作成


アプリケーションはホストやテンプレート単位で作成し、グローバルには設定できない。
従って、テンプレートやホストが異なると、同名のアプリケーションでも再度作成する必要がある。

  1. 設定
  2. アイテム追加先の選択(ホスト or テンプレート)
  3. 「アプリケーション」リンクをクリック
  4. アプリケーションの作成
  5. 名前を入力する
  6. 保存


アイテム(監視項目)の作成



  1. 設定
  2. アイテム追加先の選択(ホスト or テンプレート)
  3. 「アイテム」リンクをクリック
  4. アイテムの作成
  5. 名前、キーなどを入力する
  6. 保存





よく使うZabbixエージェントのアイテム


参考

Linux – CPU Uilization



Linux – Memory Available (byte)



Linux – Load Average



Linux – Disk Free Volume:/ (byte)

マウントポイントで対象ディスクを指定するが、マウントポイントよりディスクで指定したい場合は使用しない


Linux – Disk Free Volume:/ (%)

マウントポイントで対象ディスクを指定するが、マウントポイントよりディスクで指定したい場合は使用しない


Linux – Running Processes



Linux – Network In (Bps)



Linux – Network In (bps)



Linux – Network Out (Bps)



Linux – Network Out (bps)



Linux – Disk Read : <ディスク> (ops)



Linux – Disk Write : <ディスク> (ops)



ログ監視



正規表現の設定



正規表現の作成


  1. 管理
  2. 一般設定
  3. 正規表現を選択
  4. 正規表現の作成
  5. 正規表現を設定する
    1. 名前を入力する
    2. 条件式を設定する
      1. 条件式の新規をクリックする
      2. 条件式に正規表現を入力する
      3. 条件式の形式を選択する
        • 文字列が含まれる
        • いずれかの文字列が含まれる
        • 文字列が含まれない
        • 結果が真
        • 結果が偽
      4. 必要であれば大文字小文字を区別するかにチェックを入れる
      5. 追加
    3. テスト文字列に文字列を入力しテストをクリックすることでテストができる
    4. 保存


正規表現の割り当て


ログ監視に作成した正規表現を割り当てるには、アイテムキーの第二引数に@と正規表現名を入力する

  1. ログ監視用のアイテムの設定画面を開く
  2. タイプに「Zabbixエージェント」を選択する
  3. キーに次の書式で入力する
    log[<監視対象ファイルパス>,@<正規表現名>]
  4. データ型に「ログ」を選択する
  5. その他は任意に設定し、保存する

トリガーの設定


トリガーは監視データに条件を設定し、その条件を満たした場合に発生させるアラートを定義する。
監視データはアイテムとして定義され、取得中のものでなければならない。
トリガーの条件式にアイテムキーを記載することで、自動でアイテムとトリガーの関連付けが行われる。

トリガーの記法



トリガーの書式は次のとおりである。
{<サーバー/テンプレート名>:<アイテムキー>.<関数>}<比較演算子><比較値>

比較演算子


その他の演算子


イベント生成





関数


count

過去指定回数分のデータを一定ルールで比較し、合致数を返す。
CPUの一時的な急騰時にアラート発生を避けるなどのために使用可能。




last

直近の値を取得する


regexp

大文字小文字を無視した正規表現に一致するかどうか。
一致した場合、1を返す。

iregexp

大文字小文字を無視しない正規表現に一致するかどうか
一致した場合、1を返す。

トリガーの例


サーバ名はいずれもtest_serverとする

Ping監視

Ping監視は成功が1、失敗が0と記録される。




ユーザ権限の変更


ユーザごとに監視対象の設定の書き込み、監視の値の読み込み権限を設定できる。
権限設定はユーザが所属するグループごとに行う。

  1. 管理
  2. ユーザー
  3. 権限を変更するグループを選択する
  4. 権限タブを開く
  5. 「権限の編集」欄の「追加」ボタンをクリックする
  6. 追加したい項目を選択する
  7. 「選択」ボタンをクリックする
  8. 「保存」ボタンをクリックする

テンプレート


テンプレートのエクスポート


  1. 設定
  2. テンプレート
  3. 対象テンプレートにチェックを入れる
  4. 選択をエクスポート
  5. 実行
  6. XMLファイルがダウンロードされる

テンプレートのインポート


  1. 設定
  2. テンプレート
  3. テンプレートのインポート
  4. ローカルのファイルを選択する
  5. インポート

メンテナンス


メンテナンスを設定すると特定ホストのみ、一定期間アラートの停止ができる。
メンテナンス期間中は情報収集を続けることも止めることもできる。

  1. 設定
  2. メンテナンス
  3. メンテナンス期間の作成
  4. 次のパラメータを設定する
    • 名前:メンテナンスの管理名
    • メンテナンスタイプ:データ収集あり/なし
    • 開始日時:このメンテナンス設定の開始期間
    • 終了日時:このメンテナンス設定の終了期間
    • 説明:コメント
    • メンテナンス中のホスト
    • 期間のタイプ:
      • 一度限り
      • 毎日
      • 毎週
      • 毎月
    • メンテナンス期間詳細
      期間のタイプの種類によって異なる
      • 一度限り
        • 日付:開始日時
        • メンテナンス期間:継続時間
      • 毎日
        • 繰返し間隔(日)
        • 開始時刻
        • メンテナンス期間:継続時間
      • 毎週
        • 繰返し間隔(週)
    • ーー曜日:何曜日を有効にするか
      • 開始時刻
      • メンテナンス期間:継続時間
      • 毎月
        • 月:何月を有効にするか
        • 日付:日/曜日
    • ーー日/曜日
      • 開始時刻
      • メンテナンス期間:継続時間
  5. 保存

Web管理画面からの監視情報閲覧


監視データを閲覧する


  1. 監視データ
  2. 最新データ
  3. 閲覧したいホスト、監視項目を選択して開く

データのみを削除


設定は残しつつ、保存されている取得データを削除する。

  1. 設定
  2. ホスト
  3. アイテム
  4. 削除したいアイテムをチェック
  5. 「選択したヒストリを削除」を実行

snmpwalkによる確認


snmpwalkコマンドを使用することで、監視対象にSNMPアクセスが可能かどうか確認できる。
snmpwalkがインストールされていない場合は別途インストールが必要。



snmpwalk -v 2c -c <コミュニティ値> <対象ホスト>
バージョンオプション-vは 1 や 3 も選択可能。


監視項目の自動更新


  1. WEBサーバを用意し、設定ファイルを設置する
  2. アイテム更新のスクリプトを作成する
    vi /usr/local/bin/zabbix_item_updater.sh
  3. 以下を修正して貼り付ける
    • 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
  4. 実行権限を付与する
    chmod 774 /usr/local/bin/zabbix_item_updater.sh
  5. cronに登録する(30分間隔)
    echo "*/30 * * * * root /usr/local/bin/zabbix_item_updater.sh" > /etc/cron.d/zabbix

カスタムアラートスクリプト


Zabbixで障害発生を検知した際にメール送信に代わる指定のスクリプトを実行することができる。

スクリプトの仕様


引数


スクリプトは3つの引数をとる。順番に「送信先」、「件名」、「メッセージ」である。
なお、引数文字列中にZabbixユーザのログインシェルで展開可能な文字列($変数やバッククォートコマンド)があると、展開された状態でスクリプトに渡されるので注意。


パス


実行時のカレンとディレクトリは「/」である。

実行時ユーザ


zabbixで実行される

スクリプトの配置


Zabbixサーバの任意のパスに配置する

カスタムアラートスクリプトの登録


  1. メディアタイプの登録を行う
  2. 通知したいユーザのメディアに登録したメディアタイプを追加する
    1. 「送信先」を記載する。この「送信先」はスクリプトの引数の一つとなる。
  3. アクションとユーザを関連付ける
    スクリプトを実行するユーザは障害通知をする監視対象サーバが属するサーバグループに対する読み取り権限が必要

Tips


閲覧のみのZabbix Frontendの構築


閲覧のみ可能なZabbix Frontendを構築する。
例えば、特定の場所からのアクセスではZabbixの更新はさせたくないが、閲覧はしたい場合に使用できる。

  1. Apacheを構築する
  2. PHPを構築する
  3. 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;
  4. ソースコードを取得する
    1. ダウンロードサイトからURLを取得する
    2. ダウンロードする
      curl -s -O https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
    3. アーカイブファイルを展開する
      tar xzfv zabbix-*.tar.gz
    4. ソースコードディレクトリへ移動する
      cd zabbix-*
  5. Frontendのインストールを行う
    1. インストールディレクトリを作成する
      mkdir /usr/local/`pwd | sed "s/.*\///"`
    2. インストールディレクトリへのシンボリックリンクを作成する。
      これによって、複数のバージョンを同居させ、リンクを切り替えることで、バージョン変更が可能となる。
      各バージョンの実行ファイルはデフォルトでは各バージョンの設定ファイルを読み込むこととなる。
      rm -f /usr/local/zabbix
      ln -s /usr/local/`pwd | sed "s/.*\///"` /usr/local/zabbix
    3. 簡単にアクセスできるように環境変数を設定する
      export ZABBIX_HOME=/usr/local/zabbix
    4. 環境変数を再起動後も有効にする
      echo "" >> /etc/bashrc
      echo "# ZABBIX ENVIRONMENT VARIABLE" >> /etc/bashrc
      echo "export ZABBIX_HOME=$ZABBIX_HOME" >> /etc/bashrc
    5. 必要なファイルをコピーする
      cp -r frontends/php $ZABBIX_HOME/frontends
      ls $ZABBIX_HOME/frontends/*/.htaccess | xargs rm -f
  6. 不要なソースコードを削除する
    cd ../
    rm -rf zabbix*
  7. インストールしたディレクトリに移動する
    cd $ZABBIX_HOME
  8. Apacheの設定を行う
    1. 設定ファイルを編集する
      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
    2. 再起動して設定を反映する。
      apachectl restart
  9. Frontendの初期設定を行う
    1. 下記にブラウザでアクセスする
      http://<ホスト名 or IPアドレス>/zabbix/
    2. Next Step
    3. PHP設定の要件チェックが行われる
      不備がある場合、PHPのモジュール追加、設定を行いApacheを再起動した後、再度ここまで進める
    4. Next Step
    5. 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
    6. Next Step
    7. Zabbix Server情報を入力する
      デフォルトのままでよい
    8. Next Step
    9. Next Step
    10. 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
  10. 次のユーザ名でアカウントする
    Admin / zabbix

ホストのZabbix Agentが緑点灯しない


設定 > ホスト ページのZabbix Agentが緑点灯しないことがある。
このままでもZabbix Agentによる監視は可能であるが、気になる場合は下記対応で直る可能性がある。
※Zabbix Agentによる監視ができていない場合、zabbix_agentd.confの「ServerActive」、「Hostname」設定が間違っている可能性が高い。

  1. ホストのステータスを有効、無効、有効と切り替える
  2. 設定変更ページからエージェントのインターフェースのIPアドレス or ホスト名を適当な値に変更して保存する。
    保存後、再度元に戻す。


自作アイテム


変更後は再起動が必要
service zabbix-agent restart

Linux


ディスク使用量




ディスク使用率




ディスク残量




ディスク残量率




ディスク読み込み (bps)


sysstatパッケージが必要



ディスク書き込み (bps)


sysstatパッケージが必要



TCP/UDPコネクション数 (IPv4)




メモリ使用率




メモリ残量率




メモリ使用量





Apache


apachectl fullstatusコマンドが使用できる必要できるようディレクティブを設定しておく必要がある。
また、apachectlスクリプトを一部修正する。
vi `which apachectl`
旧:LYNX=”/usr/bin/links -dump”
新:LYNX=”/usr/bin/links -dump -no-home”

Requests / Second





Processing Workers




Idle Workers




CPU使用率




最大応答時間


アクセスログに応答時間を出力している必要がある。
またaccess_log読み取れるよう、ディレクトリに実行権限をつける。
※実行ユーザはzabbixではないため、apacheグループにzabbixユーザを入れる対応は出来ない。
chmod o+rx /etc/httpd/logs




プロセス数




Memcahced


CPU使用率




メモリ使用率




データ使用率




コネクション数





memcached-toolによる各種値


















MariaDB


Zabbix Agentの設定



アイテムキー


命令実行回数



受信データ量



送信データ量



commit実行回数



select実行回数



update実行回数



delete実行回数



insert実行回数



クエリ実行回数



rollback実行回数



slow queries件数回数



稼働時間



死活確認



バージョン



API


APIの概要



使用方法


以下の形式のJSONを送信し、結果をJSON形式で受信する
{
	"jsonrpc": "2.0",
	"method": "<メソッド名>",
	"params": {
		"<パラメータ名>": "<パラメータ値>",
		"<パラメータ名>": "<パラメータ値>",
		、、、
	},
	"id": <リクエスト識別番号>,
	"auth": "<認証トークン>"
}







データベースの直接利用


テーブル


hosts



interface



hosts_groups



hosts_templates



items



triggers




正規表現


使用中か確認する


select key_ from items where key_ like '%<正規表現名>%';

バックアップ


設定系のみバックアップし、イベントなどはバックアップしない

使用量の確認



バックアップ


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設定で指定しているサーバからしか取得できない。
これにはローカルホストも含まれる。


Notice: Trying to get property 'queue' of non-object in /usr/local/wordpress/wp-includes/script-loader.php on line 2876

Warning: Invalid argument supplied for foreach() in /usr/local/wordpress/wp-includes/script-loader.php on line 2876