zabbix / zabbix-docker

Official Zabbix Dockerfiles
https://www.zabbix.com
GNU Affero General Public License v3.0
2.4k stars 1.38k forks source link

Zabbix Docker: Zabbix Server Unable to Connect to MySQL Server on Startup #1479

Closed 839900146 closed 3 months ago

839900146 commented 3 months ago
SUMMARY

When attempting to start Zabbix containers using the provided docker-compose files, the Zabbix server fails to connect to the MySQL server during initialization, resulting in repeated "MySQL server is not available" messages. This issue persists across multiple docker-compose files and branches.

OS / ENVIRONMENT / Used docker-compose files
CONFIGURATION

No modifications were made to the docker-compose files. The default configurations were used as provided in the repository.

STEPS TO REPRODUCE
  1. Clone the Zabbix Docker repository.
  2. Navigate to the cloned directory.
  3. Run the command docker compose -f .\docker-compose_v3_alpine_mysql_latest.yaml up (or any other docker-compose file).
EXPECTED RESULTS

All Zabbix containers should start successfully, with the Zabbix server connecting to the MySQL server without issues.

ACTUAL RESULTS

The Zabbix server container fails to connect to the MySQL server, displaying repeated "MySQL server is not available" messages in the log output. This behavior is consistent across all attempted docker-compose files and branches.

PS F:\zabbix-docker> docker compose -f .\docker-compose_v3_alpine_mysql_latest.yaml up  
[+] Running 14/14  
... (omitted for brevity)  
Attaching to db-data-mysql-1, zabbix-server-1  
db-data-mysql-1 exited with code 0  
zabbix-server-1  | ** Preparing Zabbix server  
... (omitted for brevity)  
zabbix-server-1  | **** MySQL server is not available. Waiting 5 seconds...  
(repeats multiple times)

image image

dotneft commented 3 months ago

Try to check status of MySQL container, then try to check connectivity between server and DB containers.

839900146 commented 3 months ago

Try to check status of MySQL container, then try to check connectivity between server and DB containers.

Thank you for your prompt attention to my issue. I've investigated further and have some additional details that may help diagnose the problem.

Issue with "db-data-mysql" Service:

This service starts up but immediately stops without any output logs. It seems there might be a configuration issue or missing dependency preventing it from running successfully.

Logs from "zabbix-server" Service:

The logs indicate that the Zabbix server is attempting to connect to the MySQL server but failing for an extended period. Here's a snippet of the relevant logs:

...  
2024-08-01 10:39:59 **** MySQL server is not available. Waiting 5 seconds...  
...  
(repeated attempts)  
...  
2024-08-01 10:40:29 ** Database 'zabbix' already exists. Please be careful with database COLLATE!  
...

After multiple failed attempts, the Zabbix server finally acknowledges that the 'zabbix' database exists, suggesting a delay in MySQL becoming available.

Logs from "mysql-server" Service:

The MySQL server logs show a successful initialization process, including database and user creation. However, there are some warnings regarding deprecated options and insecure configurations, along with messages indicating the server shutting down and restarting:

...  
2024-08-01 10:40:19 2024-08-01T02:40:19.445570Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.39)  MySQL Community Server - GPL.  
...  
2024-08-01 10:40:20 2024-08-01T02:40:20.257765Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.  
...  
2024-08-01 10:40:26 2024-08-01T02:40:26.423088Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.39'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

Browser Error:

When attempting to access the Zabbix interface at "http://localhost/", I encounter the following error:

Database error  
Unable to determine current Zabbix database version: the table "dbversion" was not found.

This error suggests that the Zabbix server is unable to properly access the MySQL database, likely due to the earlier connection issues.

I've also noticed that when I first execute "docker compose up" to start the services, the browser reports the following error:

Database error  
Unable to determine current Zabbix database version: the table "dbversion" was not found.

However, after executing "docker compose down" and then starting the services again for the second time, the browser displays a different error:

Database error  
Unable to select configuration.

This issue consistently appears every time I follow this sequence.

The screenshot of the related issue is attached below: image image image

If the 'zabbix-server' service is restarted, a new error will occur: image

dotneft commented 3 months ago

Looks like your instance is slow, so deployment takes a time. And during initial deployment you restarted DB or Zabbix server containers. I recommend you stop compose, then remove DB data directory, then start again and wait a bit longer time.

839900146 commented 3 months ago

Looks like your instance is slow, so deployment takes a time. And during initial deployment you restarted DB or Zabbix server containers. I recommend you stop compose, then remove DB data directory, then start again and wait a bit longer time.

Thank you. I'm not sure if the slow initialization was caused by slow instance speed. I had been trying to use the docker-compose configuration that comes with MySQL, but it never worked. I remember one time I waited for nearly an hour and it still didn't work. However, when I switched to the docker-compose configuration that comes with PostgreSQL, it was able to start normally. Although it still took a minute or two to start initially, at least it could run normally.

dotneft commented 3 months ago

Without real logs it is difficult to say what happened. But everything looks like performance issue.