zabbix / zabbix-docker

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

Environment variables are not working on Zabbix 5 'zabbix-server-pgsql:centos' #668

Closed andgustmp closed 4 years ago

andgustmp commented 4 years ago

I'm using Zabbix Docker 3.4.12 (zabbix/zabbix-server-pgsql:centos-3.4.12) for many years and it is woking fine. Now, I'm testing Zabbix 5, but the environment variables (DB_SERVER_HOST, POSTGRES_USER, POSTGRES_PASSWORD, DB_SERVER_SCHEMA, POSTGRES_DB) for postgresql are not working from docker compose file. I'm using the same docker-compose file. I just change d the image name. I have already tryed images zabbix-server-pgsql:centos-5.0.1 and zabbix-server-pgsql:centos-trunk. Is there any issue related?

andgustmp commented 4 years ago

Today I found that the commando to connect to the database was not working in "/usr/bin/docker-entrypoint.sh" file. The variable "ssl_opts" in the command "psql "$ssl_opts" --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet" was causing the command to fail. After removing the variable "$ssl_opts" from the psql command, it could connect to the database and everything worked fine.

dotneft commented 4 years ago

Could you attach debug log from the container?

andgustmp commented 4 years ago

Sorry for the question, but how do I get it?

dotneft commented 4 years ago

Add DEBUG_MODE = "true" to env variables and attach log from container.

rockaut commented 4 years ago

Might be related to ... https://github.com/zabbix/zabbix-docker/pull/629/commits/160a3eb2cdc6fd1aef13607331ec0a0d6a3bb7c3

Is the connection test failing or is it later?

andgustmp commented 4 years ago

Ok. Thank you. I remembered that I have done that yesterday. I changed sensitive data with ##########.


> + ENABLE_TIMESCALEDB=false
> + ZABBIX_USER_HOME_DIR=/var/lib/zabbix
> + ZABBIX_ETC_DIR=/etc/zabbix
> + '[' /usr/sbin/zabbix_server '!=' /usr/sbin/zabbix_server ']'
> + '[' /usr/sbin/zabbix_server == /usr/sbin/zabbix_server ']'
> + prepare_server
> + echo '** Preparing Zabbix server'
> + check_variables_postgresql
> + file_env POSTGRES_USER
> + local var=POSTGRES_USER
> + local fileVar=POSTGRES_USER_FILE
> + local defaultValue=
> + '[' ########## ']'
> + '[' '' ']'
> + local val=
> + '[' ########## ']'
> + val=##########
> + echo '** Using POSTGRES_USER variable from ENV'
> + export POSTGRES_USER=##########
> + POSTGRES_USER=##########
> + unset POSTGRES_USER_FILE
> + file_env POSTGRES_PASSWORD
> + local var=POSTGRES_PASSWORD
> + local fileVar=POSTGRES_PASSWORD_FILE
> + local defaultValue=
> + '[' ########## ']'
> + '[' '' ']'
> + local val=
> + '[' ########## ']'
> + val=##########
> + echo '** Using POSTGRES_PASSWORD variable from ENV'
> + export POSTGRES_PASSWORD=##########
> + POSTGRES_PASSWORD=##########
> + unset POSTGRES_PASSWORD_FILE
> + : bd-post-hom.##########
> + : 5432
> + : false
> + DB_SERVER_ROOT_USER=##########
> + DB_SERVER_ROOT_PASS=##########
> + DB_SERVER_ZBX_USER=##########
> + DB_SERVER_ZBX_PASS=##########
> + : zabbix
> + DB_SERVER_DBNAME=xpto
> + check_db_connect_postgresql
> + echo '********************'
> + echo '* DB_SERVER_HOST: bd-post-hom.##########'
> + echo '* DB_SERVER_PORT: 5432'
> + echo '* DB_SERVER_DBNAME: xpto'
> + echo '* DB_SERVER_SCHEMA: zabbix'
> + '[' true == true ']'
> + '[' '' == true ']'
> + echo '* DB_SERVER_ZBX_USER: ##########'
> + echo '* DB_SERVER_ZBX_PASS: ##########'
> + echo '********************'
> + '[' '' '!=' true ']'
> + DB_SERVER_ROOT_USER=##########
> + DB_SERVER_ROOT_PASS=##########
> + '[' -n ########## ']'
> + export PGPASSWORD=##########
> + PGPASSWORD=##########
> + WAIT_TIMEOUT=5
> + '[' -n zabbix ']'
> + PGOPTIONS=--search_path=zabbix
> + export PGOPTIONS
> + '[' -n '' ']'
> ++ psql '' --host bd-post-hom.########## --port 5432 --username ########## --list --quiet
> ** Preparing Zabbix server
> ** Using POSTGRES_USER variable from ENV
> ** Using POSTGRES_PASSWORD variable from ENV
> ********************
> * DB_SERVER_HOST: bd-post-hom.##########
> * DB_SERVER_PORT: 5432
> * DB_SERVER_DBNAME: xpto
> * DB_SERVER_SCHEMA: zabbix
> * DB_SERVER_ZBX_USER: ##########
> * DB_SERVER_ZBX_PASS: ##########
> ********************
> + '[' '!' '' ']'
> + echo '**** PostgreSQL server is not available. Waiting 5 seconds...'
> + sleep 5
> **** PostgreSQL server is not available. Waiting 5 seconds...
> ++ psql '' --host bd-post-hom.########## --port 5432 --username ########## --list --quiet
> + '[' '!' '' ']'
> + echo '**** PostgreSQL server is not available. Waiting 5 seconds...'
> + sleep 5
> **** PostgreSQL server is not available. Waiting 5 seconds...
dotneft commented 4 years ago

if you connect to the container and execute psql '' --host bd-post-hom.########## --port 5432 --username ########## --list successful? What is output? What output from: psql --host bd-post-hom.########## --port 5432 --username ########## --list

andgustmp commented 4 years ago

The output for the first option says that the database does not exist. It trys to connect to a 'zabbixuser' database. But this is not the name of the database.

Here is the output.

bash-4.2$ psql '' --host bd-post-hom.########## --port 5432 --username zabbixuser --list Password for user zabbixuser: psql: FATAL: banco de dados "zabbixuser " não existe

bash-4.2$ psql --host bd-post-hom.########## --port 5432 --username zabbixuser --list Password for user zabbixuser: List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges --------------+------------------------+-----------+------------+------------+------------------------------------------------------ ########## | ########## | UTF8 | pt_BR.utf8 | pt_BR.utf8 | ########## | ########## | SQL_ASCII | C | pt_BR.utf8 | ########## | ########## | UTF8 | pt_BR.utf8 | pt_BR.utf8 |

dotneft commented 4 years ago

I see. What image do you use? CentOS right?

andgustmp commented 4 years ago

Yes. I use CentOS.

andrazjelenc commented 4 years ago

If you use image from docker hub be aware of time of the last build. I had problem with this because some bug wasn't fixed in last image that was build a month ago. See: https://github.com/zabbix/zabbix-docker/issues/667

andgustmp commented 4 years ago

If you use image from docker hub be aware of time of the last build. I had problem with this because some bug wasn't fixed in last image that was build a month ago. See: #667

This happened also with Zabbix 5.0.1, image zabbix/zabbix-server-pgsql:centos-5.0.1

dotneft commented 4 years ago

In my case everything works fine. CentOS image with latest changes:

++ psql '' --host postgres-server --port 5432 --username zabbix --list --quiet
+ '[' '!' '                              List of databases
   Name    | Owner  | Encoding |  Collate   |   Ctype    | Access privileges 
-----------+--------+----------+------------+------------+-------------------
 postgres  | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | =c/zabbix        +
           |        |          |            |            | zabbix=CTc/zabbix
 template1 | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | =c/zabbix        +
           |        |          |            |            | zabbix=CTc/zabbix
 zabbix    | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | 
(4 rows)' ']'

manual:

$ psql -V
psql (PostgreSQL) 9.2.24
$ psql '' --host postgres-server --port 5432 --username zabbix --list --quiet
Password for user zabbix: 
                              List of databases
   Name    | Owner  | Encoding |  Collate   |   Ctype    | Access privileges 
-----------+--------+----------+------------+------------+-------------------
 postgres  | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | =c/zabbix        +
           |        |          |            |            | zabbix=CTc/zabbix
 template1 | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | =c/zabbix        +
           |        |          |            |            | zabbix=CTc/zabbix
 zabbix    | zabbix | UTF8     | en_US.utf8 | en_US.utf8 | 
(4 rows)

Where from do you use images?

andgustmp commented 4 years ago

I did not changed the default registry. So the system shows "https://index.docker.io/v1/"

Images:

[root@zbx50 /]# docker pull zabbix/zabbix-server-pgsql:centos-5.0-latest
centos-5.0-latest: Pulling from zabbix/zabbix-server-pgsql
Digest: sha256:e0da2b264d2a9efa2fac0145d986df6d42ecf34a8544bc39b3f254d16f297d8a
Status: Image is up to date for zabbix/zabbix-server-pgsql:centos-5.0-latest
docker.io/zabbix/zabbix-server-pgsql:centos-5.0-latest

[root@zbx50 /]# docker pull zabbix/zabbix-server-pgsql:centos-5.0.1
centos-5.0.1: Pulling from zabbix/zabbix-server-pgsql
Digest: sha256:5a5b7857c9e7c7e9be8c55ac02f90bbb8d7a7bb9cedf2ffa08c395fd0a5b9568
Status: Image is up to date for zabbix/zabbix-server-pgsql:centos-5.0.1
docker.io/zabbix/zabbix-server-pgsql:centos-5.0.1

[root@zbx50 /]# docker pull zabbix/zabbix-server-pgsql:centos-trunk
centos-trunk: Pulling from zabbix/zabbix-server-pgsql
Digest: sha256:3508c882b486e4989d679dc07778bb70f07476ae6a4fe9d50fb8602bc19ce141
Status: Image is up to date for zabbix/zabbix-server-pgsql:centos-trunk
docker.io/zabbix/zabbix-server-pgsql:centos-trunk

docker system info

Client:
 Debug Mode: false

Server:
 Containers: 5
  Running: 5
  Paused: 0
  Stopped: 0
 Images: 20
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.4.96-1.el7.elrepo.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 3.859GiB
 Name: zbx50
 ID: 2O4L:PIVC:YDS2:IMKV:R7LA:4MKM:HM2M:RHCR:6US4:PNLF:RTYH:YBJ7
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

psql -V psql (PostgreSQL) 9.2.24

dotneft commented 4 years ago

what postgresql version do you use?

andgustmp commented 4 years ago

My postgresql server version:

-bash-4.2$ psql -V
psql (PostgreSQL) 9.5.9
dotneft commented 4 years ago

I completely can not reproduce the issue. Maybe issue related to lang pt_BR.utf8 :-)

andgustmp commented 4 years ago

Hehehehe.....if that were the problem, it would be easy to solve. ;-)

I will setup a new machine and install docker.

andgustmp commented 4 years ago

Now I setup a new machine and did some tests. It seams that 'docker-entrypoint.sh' uses different command to test connection to the database.

Now the database name variable is specified and the conection can be established.

psql "$ssl_opts" -h ${DB_SERVER_HOST} -p ${DB_SERVER_PORT} -U ${DB_SERVER_ROOT_USER} -d ${DB_SERVER_DBNAME} -l -q

Am I getting crazy?

dotneft commented 4 years ago

try to use directly centos-5.0.1 or centos-latest

dotneft commented 4 years ago

Maybe you faced #672 ?

andgustmp commented 4 years ago

Yes, maybe.

andgustmp commented 4 years ago

You said there that your team will fix it soon. Should I close this issue?

dotneft commented 4 years ago

Fixed!