PostgreSQL14をZabbix用にパーティション構成で設定する
概要
監視サービスのZabbixに適したパーティション構成でPostgreSQLをインストールしていきます。
Zabbixは、直近の監視データを historyテーブルに保存し指定した期間を過ぎるとtrendsテーブルにデータを集約してコピーした後にhistoryテーブルのデータを削除します。しかし、監視対象が増えると削除処理が追い付かなくなってきます。パーティション構成にすると、不要になったパーティションをDropすることでデータの削除処理が大幅に軽減されます。
環境
- Debian 11
- PostgreSQL 14
- Zabbix 5.4
- CPU Intel(R) Celeron(R) CPU N3350 @ 1.10GHz
- メモリ 4GB
インストール
PostgreSQL 14
# apt install postgresql-common # sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh # sh -c "echo 'deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main' > /etc/apt/sources.list.d/timescaledb.list" # wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/timescale.keyring # apt update # apt install timescaledb-2-postgresql-14 # timescaledb-tune --quiet --yes
Zabbix
サイトの手順に従ってパッケージをインストールする
パッケージはOSなどに合わせて選択します。
- Install Zabbix repository
# wget https://repo.zabbix.com/zabbix/5.4/debian/pool/main/z/zabbix-release/zabbix-release_5.4-1+debian11_all.deb # dpkg -i zabbix-release_5.4-1+debian11_all.deb # apt update
- Install Zabbix server, frontend, agent
# apt install zabbix-server-pgsql zabbix-frontend-php php7.4-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
DBユーザーとDB作成
# su - postgres $ createuser --pwprompt zabbix $ createdb -O zabbix zabbix
アクセス権の設定
/etc/postgresql/14/main/postgresql.conf 内の以下の行のコメントを外す。
#listen_addresses = 'localhost' # what IP address(es) to listen on;
を
listen_addresses = 'localhost' # what IP address(es) to listen on;
にしてデータベースを再起動する。
# systemctl restart postgresql@14-main
Zabbix用のスキーマ(テーブルなど)を作成する
# zcat /usr/share/doc/zabbix-sql-scripts/postgresql/create.sql.gz | psql -h 127.0.0.1 -U zabbix zabbix Password for user zabbix:
timescaledbを有効にする
# psql -h 127.0.0.1 -U zabbix zabbix Password for user zabbix: zabbix=> CREATE extension timescaledb; WARNING: WELCOME TO _____ _ _ ____________ |_ _(_) | | | _ \ ___ \ | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ / | | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \ | | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ / |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/ Running version 2.5.0 For more information on TimescaleDB, please visit the following links: 1. Getting started: https://docs.timescale.com/timescaledb/latest/getting-started 2. API reference documentation: https://docs.timescale.com/api/latest 3. How TimescaleDB is designed: https://docs.timescale.com/timescaledb/latest/overview/core-concepts Note: TimescaleDB collects anonymous reports to better understand and assist our users. For more information and how to disable, please see our docs https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/telemetry. CREATE EXTENSION zabbix=> quit # cat /usr/share/doc/zabbix-sql-scripts/postgresql/timescaledb.sql | psql -h 127.0.0.1 -U zabbix zabbix Password for user zabbix: NOTICE: PostgreSQL version 14.0 (Debian 14.0-1.pgdg110+1) is valid NOTICE: TimescaleDB extension is detected NOTICE: TimescaleDB version 2.5.0 is valid NOTICE: TimescaleDB is configured successfully DO
Zabbix server のDBパスワードの設定
/etc/zabbix/zabbix_server.conf を編集する
DBPassword=password
Zabbixのフロントエンドを表示するための設定
/etc/zabbix/nginx.conf を編集して、以下の項目のコメントを外す
listen 80; server_name example.com;
/etc/php/7.4/fpm/pool.d/zabbix-php-fpm.conf を編集して、タイムゾーンを日本語にする
; php_value[date.timezone] = Europe/Riga ↓ php_value[date.timezone] = Asia/Tokyo
Zabbix server と agent を再起動して、自動起動するよう設定する
# systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm # systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm
フロントエンドの設定
ブラウザで http://
デフォルトは Admin / zabbix