§2024-05-19
-
Install Zabbix Server on Ubuntu 20.04 VM with Postgres and NginxMustafa Altunok, Nov 24, 2022
-
機器: hc4nas02.yushei.net]
- ubuntu 20.04, /dev/md0
$ sudo apt install postgresql postgresql-contrib
alexlai@hc4nas02:~$ systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2024-05-21 07:53:13 CST; 45s ago
Main PID: 273525 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 3462)
Memory: 0B
CGroup: /system.slice/postgresql.service
May 21 07:53:13 hc4nas02 systemd[1]: Starting PostgreSQL RDBMS...
May 21 07:53:13 hc4nas02 systemd[1]: Finished PostgreSQL RDBMS.
alexlai@hc4nas02:~$ dpkg -l postgresql
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-===============-============-==================================================
ii postgresql 12+214ubuntu0.1 all object-relational SQL database (supported version)
alexlai@hc4nas02:~$ dpkg -L postgresql-12|less
alexlai@hc4nas02:~$ /usr/lib/postgresql/12/bin/postgres --version
postgres (PostgreSQL) 12.18 (Ubuntu 12.18-0ubuntu0.20.04.1)
- After having Postgres up and running, I can start installing Zabbix.
2.1. Install Zabbix repository;
alexlai@hc4nas02:~/Downloads$ wget wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu20.04_all.deb
alexlai@hc4nas02:~/Downloads$ sudo dpkg -i zabbix-release_6.4-1+ubuntu20.04_all.deb
Selecting previously unselected package zabbix-release.
(Reading database ... 129464 files and directories currently installed.)
Preparing to unpack zabbix-release_6.4-1+ubuntu20.04_all.deb ...
Unpacking zabbix-release (1:6.4-1+ubuntu20.04) ...
Setting up zabbix-release (1:6.4-1+ubuntu20.04) ...
# apt update
2.2. Install Zabbix server, frontend, agent;
alexlai@hc4nas02:~/Downloads$ sudo apt install zabbix-server-pgsql zabbix-frontend-php php7.4-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
fonts-dejavu fonts-dejavu-extra fping libblas3 libiksemel3 liblinear4 libodbc1 libonig5 libopenipmi0 libssh2-1 lua-lpeg nmap nmap-common php-bcmath
php-common php-fpm php-gd php-ldap php-mbstring php-xml php7.4-bcmath php7.4-cli php7.4-common php7.4-fpm php7.4-gd php7.4-json php7.4-ldap
php7.4-mbstring php7.4-opcache php7.4-readline php7.4-xml snmpd traceroute
Suggested packages:
liblinear-tools liblinear-dev libmyodbc odbc-postgresql tdsodbc unixodbc-bin ncat ndiff zenmap php-pear snmptrapd zabbix-apache-conf snmp-mibs-downloader
The following NEW packages will be installed:
fonts-dejavu fonts-dejavu-extra fping libblas3 libiksemel3 liblinear4 libodbc1 libonig5 libopenipmi0 libssh2-1 lua-lpeg nmap nmap-common php-bcmath
php-common php-fpm php-gd php-ldap php-mbstring php-xml php7.4-bcmath php7.4-cli php7.4-common php7.4-fpm php7.4-gd php7.4-json php7.4-ldap
php7.4-mbstring php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml snmpd traceroute zabbix-agent zabbix-frontend-php zabbix-nginx-conf
zabbix-server-pgsql zabbix-sql-scripts
0 upgraded, 39 newly installed, 0 to remove and 1 not upgraded.
Need to get 30.2 MB of archives.
After this operation, 111 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
....
- Initialize Database
alexlai@hc4nas02:~$ sudo -u postgres createuser --pwprompt zabbix
[sudo] password for alexlai:
Enter password for new role: b2nnnnnnn
Enter it again: b2nnnnnn5
alexlai@hc4nas02:~$ sudo -u postgres createdb -O zabbix zabbix
3.1. On Zabbix server host import initial schema and data;
$ sudo zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix
....
INSERT 0 1
INSERT 0 1
INSERT 0 1
DELETE 98754
COMMIT
3.2. Configure the database for Zabbix server
alexlai@hc4nas02:~$ sudo cp -v /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.backup
'/etc/zabbix/zabbix_server.conf' -> '/etc/zabbix/zabbix_server.conf.backup'
alexlai@hc4nas02:~$ sudo nano /etc/zabbix/zabbix_server.conf
alexlai@hc4nas02:~$ sudo diff /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.backup
119c119
< DBPassword=b2nnnnnn5
---
> # DBPassword=
3.3. Configure PHP for Zabbix frontend;
$ sudo cp -v /etc/zabbix/nginx.conf /etc/zabbix/nginx.conf.backup
$ sudo nano /etc/zabbix/nginx.conf
alexlai@hc4nas02:~$ sudo diff /etc/zabbix/nginx.conf /etc/zabbix/nginx.conf.backup
2,3c2,3
< listen 8088;
< server_name hc4nas02.yushei.net;
---
> # listen 8080;
> # server_name example.com;
- Start Zabbix server and agent processes;
alexlai@hc4nas02:~$ sudo systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
alexlai@hc4nas02:~$ sudo systemctl status zabbix-server zabbix-agent nginx php7.4-fpm
● zabbix-server.service - Zabbix Server (PostgreSQL)
Loaded: loaded (/lib/systemd/system/zabbix-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-05-21 10:12:36 CST; 8s ago
Docs: man:zabbix_server
Process: 300451 ExecStart=/usr/sbin/zabbix_server --foreground (code=exited, status=1/FAILURE)
Main PID: 300451 (code=exited, status=1/FAILURE)
May 21 10:12:36 hc4nas02 systemd[1]: Started Zabbix Server (PostgreSQL).
May 21 10:12:36 hc4nas02 zabbix_server[300451]: Starting Zabbix Server. Zabbix 4.0.17 (revision a528a0a4bc).
May 21 10:12:36 hc4nas02 zabbix_server[300451]: Press Ctrl+C to exit.
May 21 10:12:36 hc4nas02 systemd[1]: zabbix-server.service: Main process exited, code=exited, status=1/FAILURE
May 21 10:12:36 hc4nas02 systemd[1]: zabbix-server.service: Failed with result 'exit-code'.
● zabbix-agent.service - Zabbix Agent
Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-05-21 10:12:36 CST; 9s ago
Docs: man:zabbix_agentd
Main PID: 300453 (zabbix_agentd)
Tasks: 6 (limit: 3462)
Memory: 2.8M
CGroup: /system.slice/zabbix-agent.service
├─300453 /usr/sbin/zabbix_agentd --foreground
├─300454 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
├─300455 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
├─300456 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
├─300458 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
└─300459 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
May 21 10:12:36 hc4nas02 systemd[1]: Started Zabbix Agent.
May 21 10:12:36 hc4nas02 zabbix_agentd[300453]: Starting Zabbix Agent [hc4nas02]. Zabbix 4.0.17 (revision a528a0a4bc).
May 21 10:12:36 hc4nas02 zabbix_agentd[300453]: Press Ctrl+C to exit.
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-05-21 10:12:36 CST; 9s ago
Docs: man:nginx(8)
Process: 300457 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 300465 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 300467 (nginx)
Tasks: 5 (limit: 3462)
Memory: 4.3M
CGroup: /system.slice/nginx.service
├─300467 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─300468 nginx: worker process
├─300469 nginx: worker process
├─300470 nginx: worker process
└─300471 nginx: worker process
May 21 10:12:36 hc4nas02 systemd[1]: Starting A high performance web server and a reverse proxy server...
May 21 10:12:36 hc4nas02 systemd[1]: Started A high performance web server and a reverse proxy server.
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-05-21 10:12:36 CST; 9s ago
Docs: man:php-fpm7.4(8)
Process: 300479 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=>
Main PID: 300464 (php-fpm7.4)
Status: "Ready to handle connections"
Tasks: 8 (limit: 3462)
Memory: 12.9M
CGroup: /system.slice/php7.4-fpm.service
├─300464 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─300472 php-fpm: pool www
├─300473 php-fpm: pool www
├─300474 php-fpm: pool zabbix
├─300475 php-fpm: pool zabbix
├─300476 php-fpm: pool zabbix
├─300477 php-fpm: pool zabbix
└─300478 php-fpm: pool zabbix
May 21 10:12:36 hc4nas02 systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
May 21 10:12:36 hc4nas02 systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
If everything goes we will connect to the frontend by http://hc4nas02.yushei.net:8088/setup.php
- Here choose Postgresql as Database type and enter our DB password
- Username: Admin, Password: zabbix