# [Zabbix](https://www.zabbix.com/jp) やんごとなき理由により某組織のネットワーク管理を予算ほぼゼロで保守する必要性があり, 数百のネットワーク機器の監視を行うため統合監視ツールのzabbixを用いて監視の自動化したそ際の備忘録である. 無料で使っているが予算があれば課金したいところ. ## installation [Download and install Zabbix](https://www.zabbix.com/download)よりinstallする.dabaseはmysqlを選択するが,debian 11の場合mysql = mariadbを意味する(公式のmysqlをinstallする必要性はない). 基本的には公式の手順に従うが,debian 11 ではmariadbがデフォルトで動いていないのでmariadbを起動する. ``` # systemctl start mariadb # systemctl enable mariadb ``` ## Install and configure Zabbix server for your platform ### a. Install Zabbix repository ``` # wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-1+debian11_all.deb # dpkg -i zabbix-release_6.0-1+debian11_all.deb # apt update ``` ### b. Install Zabbix server, frontend, agent ``` # apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent ``` ### c. Create initial database Documentation Make sure you have database server up and running. Run the following on your database host. 下記3行目の`<>` はマニュアル通りにコピペするとzabbix database のパスワードが`password` になるので注意する. ``` # mysql -uroot -p <> mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; mysql> create user zabbix@localhost identified by '<>'; mysql> grant all privileges on zabbix.* to zabbix@localhost; mysql> quit; ``` ### d. Configure the database for Zabbix server Edit file /etc/zabbix/zabbix_server.conf ``` DBPassword=<> ``` ## 旧データベースのdump 旧zabbixサーバーにて ``` # systemctl stop zabbix-server # mysqldump -u root -p zabbix > zabbix.sql ``` scpなどでzabbix.sqlを新サーバーに移す 新zabbixサーバーにて ``` mysql -u root -p zabbix < zabbix.sql Enter password: ``` ## php data.timezone zabbixのweb interfaceでphp timezoneがfailになる場合は ``` # php --ini Configuration File (php.ini) Path: /etc/php/7.4/cli Loaded Configuration File: /etc/php/7.4/cli/php.ini ... ``` で ``` 962 date.timezone = Asia/Tokyo ``` とすれば良い. ## 設定ファイル (zabbix-server.conf) 以下の項目をデフォルトから変更した. ``` # cat /etc/zabbix/zabbix_server.conf | grep -v "#" | sed '/^$/d' ``` ``` LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/run/zabbix/zabbix_server.pid SocketDir=/run/zabbix DBName=zabbix DBUser=zabbix DBPassword=******** StartPingers=5 StartDiscoverers=5 VMwareCacheSize=1G SNMPTrapperFile=/var/log/snmptrap/snmptrap.log CacheSize=8G HistoryCacheSize=1G HistoryIndexCacheSize=1G TrendCacheSize=1G TrendFunctionCacheSize=1G ValueCacheSize=1G Timeout=4 FpingLocation=/usr/bin/fping Fping6Location=/usr/bin/fping6 LogSlowQueries=3000 StatsAllowedIP=127.0.0.1 ``` ## Databaseの引越し mysql (mariadb)のdatabeseを デフォルトの ` /var/lib/mysql` から `/hddpool/mysql` に移行した.以前にもトライしたがうまくいかなったのだがChatGPTに聞くと原因はAppArmorだったようだ. 引越しの目的はzabbixの書き込みが想定より多く,OSが動いているSSDの書き込み総量を減らし寿命を伸ばしたい. 一応OS全体はbtrfsのbackupを/hddpool/backupに残しているのでSSDとHDD(RAID 10)が同時に死ななければシステムの復旧は比較的容易(なはず). 以降は引越し手順 1. データベースのパスの確認 ``` # mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 465 Server version: 10.11.14-MariaDB-0+deb12u2 Debian 12 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW VARIABLES LIKE 'datadir'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | datadir | /var/libl/mysql/ | +---------------+-----------------+ 1 row in set (0.000 sec) MariaDB [(none)]> quit; Bye ``` 2. 引越し先の作成 ``` # ディレクトリ作成 sudo mkdir -p /hddpool/mysql # 権限を一時的に変更してコピー sudo rsync -av /var/lib/mysql/ /hddpool/mysql/ # 所有権が mysql ユーザーになっていることを確認 sudo chown -R mysql:mysql /hddpool/mysql ``` 3. mariadbの設定 `/etc/mysql/mariadb.conf.d/50-server.cnf` を次のように書き換える ``` [mysqld] # datadir = /var/lib/mysql datadir = /hddpool/mysql ``` 4. AppArmorの設定 AppArmor のalias `/etc/apparmor.d/tunables/alias` を次のように書き換える ``` # cat /etc/apparmor.d/tunables/alias # ------------------------------------------------------------------ # # Copyright (C) 2010 Canonical Ltd. # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License published by the Free Software Foundation. # # ------------------------------------------------------------------ # Alias rules can be used to rewrite paths and are done after variable # resolution. For example, if '/usr' is on removable media: # alias /usr/ -> /mnt/usr/, # # Or if mysql databases are stored in /home: # alias /var/lib/mysql/ -> /home/mysql/, alias /var/lib/mysql/ -> /hddpool/mysql/, ``` 5. サービスの再起動 ``` sudo systemctl restart apparmor sudo systemctl start mariadb ``` 6. 引越しの確認 ``` mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 465 Server version: 10.11.14-MariaDB-0+deb12u2 Debian 12 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW VARIABLES LIKE 'datadir'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | datadir | /hddpool/mysql/ | +---------------+-----------------+ 1 row in set (0.000 sec) MariaDB [(none)]> quit; Bye ``` 7. zabbixの再起動 ``` sudo systemctl start zabbix-server ``` これでweb UIにログインできれば引越し完了 ```{toctree} :maxdepth: 1 another_page