Raspberry Pi OS (Bookworm) への Zabbix 7.0 LTS 導入メモ

# 実行環境
- Raspberry Pi 4 Model B (8GB)
- Raspberry Pi OS (Bookworm)

# 導入手順
- 基本は以下の URL に従って導入する
    - https://www.zabbix.com/download?zabbix=7.0&os_distribution=raspberry_pi_os&os_version=12&components=server_frontend_agent&db=pgsql&ws=nginx
- MySQL 導入は面倒そうだったので PostgreSQL を選択


## 1 Choose your platform
| Key | Value |
|:-|:-|
| ZABBIX VERSION | 7.0 LTS |
| OS DISTRIBUTION | Raspberry Pi OS |
| OS VERSION | 12 (Bookworm) |
| ZABBIX COMPONENT | Server, Fontend, Agent |
| DATABASE | PostgreSQL |
| WEB SERVER | Nginx |

## 2 Install and configure Zabbix for your platform

### a. Install Zabbix repository

```sh
wget https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_latest_7.0+debian12_all.deb
sudo dpkg -i zabbix-release_latest_7.0+debian12_all.deb
rm zabbix-release_latest_7.0+debian12_all.deb
sudo apt update 
```

### b. Install Zabbix server, frontend, agent

```sh
sudo apt install -y zabbix-server-pgsql zabbix-frontend-php php8.2-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
```

- 別で `PostgreSQL` の導入も必要だったので Install

```sh
sudo apt install -y postgresql postgresql-server-dev-all 
```

### c. Create initial database
- non-interactive で操作する

```sh
POSTGRES_USER="zabbix"
POSTGRES_PASSWORD="zabbix"
#sudo -u postgres createuser --pwprompt "${POSTGRES_USER}"
sudo -u postgres psql -c "create role ${POSTGRES_USER} with login password '${POSTGRES_PASSWORD}';"
sudo -u postgres createdb -O ${POSTGRES_USER} zabbix 
zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix 
```

### d. Configure the database for Zabbix server

```sh
sudo sed -i.bak -e "s/# DBPassword=/DBPassword=${POSTGRES_PASSWORD}/" /etc/zabbix/zabbix_server.conf
```

### e. Configure PHP for Zabbix frontend
- (ここの項目名 PHP じゃなくて Nginx じゃない？)
- 80 番ポートで待ち受けるようにする

```sh
sudo sed -i.bak -i "2i listen 80;" /etc/zabbix/nginx.conf
sudo sed -i.ba2k -i "3i server_name <your domain>;" /etc/zabbix/nginx.conf
```

- Zabbix 公式サイトの手順から抜けている Nginx の設定を行う
    - 初期設定のままだと、Nginx と Zabbix Nginx の設定が衝突して Nginx 側の設定が優先されてしまう

```diff
--- /etc/nginx/sites-enabled/default.bak        2025-01-02 09:10:38.301240963 +0900
+++ /etc/nginx/sites-enabled/default    2025-01-02 09:18:23.499717591 +0900
@@ -18,57 +18,57 @@
 
 # Default server configuration
 #
-server {
-       listen 80 default_server;
-       listen [::]:80 default_server;
-
-       # SSL configuration
-       #
-       # listen 443 ssl default_server;
-       # listen [::]:443 ssl default_server;
-       #
-       # Note: You should disable gzip for SSL traffic.
-       # See: https://bugs.debian.org/773332
-       #
-       # Read up on ssl_ciphers to ensure a secure configuration.
-       # See: https://bugs.debian.org/765782
-       #
-       # Self signed certs generated by the ssl-cert package
-       # Don't use them in a production server!
-       #
-       # include snippets/snakeoil.conf;
-
-       root /var/www/html;
-
-       # Add index.php to the list if you are using PHP
-       index index.html index.htm index.nginx-debian.html;
-
-       server_name _;
-
-       location / {
-               # First attempt to serve request as file, then
-               # as directory, then fall back to displaying a 404.
-               try_files $uri $uri/ =404;
-       }
-
-       # pass PHP scripts to FastCGI server
-       #
-       #location ~ \.php$ {
-       #       include snippets/fastcgi-php.conf;
-       #
-       #       # With php-fpm (or other unix sockets):
-       #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
-       #       # With php-cgi (or other tcp sockets):
-       #       fastcgi_pass 127.0.0.1:9000;
-       #}
-
-       # deny access to .htaccess files, if Apache's document root
-       # concurs with nginx's one
-       #
-       #location ~ /\.ht {
-       #       deny all;
-       #}
-}
+#server {
+#      listen 80 default_server;
+#      listen [::]:80 default_server;
+
+#      # SSL configuration
+#      #
+#      # listen 443 ssl default_server;
+#      # listen [::]:443 ssl default_server;
+#      #
+#      # Note: You should disable gzip for SSL traffic.
+#      # See: https://bugs.debian.org/773332
+#      #
+#      # Read up on ssl_ciphers to ensure a secure configuration.
+#      # See: https://bugs.debian.org/765782
+#      #
+#      # Self signed certs generated by the ssl-cert package
+#      # Don't use them in a production server!
+#      #
+#      # include snippets/snakeoil.conf;
+
+#      root /var/www/html;
+
+#      # Add index.php to the list if you are using PHP
+#      index index.html index.htm index.nginx-debian.html;
+
+#      server_name _;
+
+#      location / {
+#              # First attempt to serve request as file, then
+#              # as directory, then fall back to displaying a 404.
+#              try_files $uri $uri/ =404;
+#      }
+
+#      # pass PHP scripts to FastCGI server
+#      #
+#      #location ~ \.php$ {
+#      #       include snippets/fastcgi-php.conf;
+#      #
+#      #       # With php-fpm (or other unix sockets):
+#      #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
+#      #       # With php-cgi (or other tcp sockets):
+#      #       fastcgi_pass 127.0.0.1:9000;
+#      #}
+
+#      # deny access to .htaccess files, if Apache's document root
+#      # concurs with nginx's one
+#      #
+#      #location ~ /\.ht {
+#      #       deny all;
+#      #}
+#}
 
 
 # Virtual Host configuration for example.com
```


### z. raspi の初期設定だといくつかエラーが出るのでその設定を行う

```sh
# Locale (en_US) 導入
sudo raspi-config nonint do_change_locale en_US.UTF-8
```

### f. Start Zabbix server and agent processes

```sh
sudo systemctl restart zabbix-server zabbix-agent nginx php8.2-fpm
sudo systemctl enable zabbix-server zabbix-agent nginx php8.2-fpm 
```

### g. Open Zabbix UI web page
- Zabbix が走っているサーバの `http://***.***.***.***/` でアクセス
    - ユーザ名：`Admin`、パスワード：`zabbix`
- Pre-Check で Locale のエラーが出る場合は、適切 Locale が Install されていない
- Zabbix UI ではなく Nginx の Welcome page が表示される場合、Nginx 側の設定が無効化できていない