Docker数据库访问被拒绝

时间:2020-08-18 11:44:37

标签: python mysql django docker mariadb

编辑:添加了docker-compose.yml和pretix配置
大家好
我正在尝试使用此Pretix在服务器上运行docker-compose.yml。我刚刚将traefik标签更改为我的nginx环境变量,并调整了外部网络以使其与我的nginx网络匹配,但其他所有操作都是相同的。但是,当我转到自己的网站时,只看到带有内部服务器错误消息的pretix徽标。 Pretix logo with internal server error
浏览日志时,我发现pretix_app无法连接到数据库,但是我真的不明白为什么。

pretix_app | django.db.utils.OperationalError: (1045, "Access denied for user 'db'@'172.20.0.24' (using password: YES)")

完整日志:

db_1      | 2020-08-18 11:22:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.5+maria~focal started.
db_1      | 2020-08-18 11:22:37+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1      | 2020-08-18 11:22:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.5+maria~focal started.
db_1      | 2020-08-18 11:22:38 0 [Note] mysqld (mysqld 10.5.5-MariaDB-1:10.5.5+maria~focal) starting as process 1 ...
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Using Linux native AIO
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Uses event mutexes
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Number of pools: 1
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Using SSE4.2 crc32 instructions
db_1      | 2020-08-18 11:22:38 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Completed initialization of buffer pool
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: 128 rollback segments are active.
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: 10.5.5 started; log sequence number 45103; transaction id 21
db_1      | 2020-08-18 11:22:38 0 [Note] Plugin 'FEEDBACK' is disabled.
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1      | 2020-08-18 11:22:38 0 [Note] InnoDB: Buffer pool(s) load completed at 200818 11:22:38
db_1      | 2020-08-18 11:22:38 0 [Note] Server socket created on IP: '::'.
db_1      | 2020-08-18 11:22:38 0 [Warning] 'proxies_priv' entry '@% root@d86baaaf6fde' ignored in --skip-name-resolve mode.
db_1      | 2020-08-18 11:22:38 0 [Note] Reading of all Master_info entries succeeded
db_1      | 2020-08-18 11:22:38 0 [Note] Added new Master_info '' to hash table
db_1      | 2020-08-18 11:22:38 0 [Note] mysqld: ready for connections.
db_1      | Version: '10.5.5-MariaDB-1:10.5.5+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
redis_1   | 1:C 18 Aug 2020 11:22:36.618 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1   | 1:C 18 Aug 2020 11:22:36.618 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1   | 1:C 18 Aug 2020 11:22:36.618 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1   | 1:M 18 Aug 2020 11:22:36.620 * Running mode=standalone, port=6379.
redis_1   | 1:M 18 Aug 2020 11:22:36.620 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1   | 1:M 18 Aug 2020 11:22:36.620 # Server initialized
redis_1   | 1:M 18 Aug 2020 11:22:36.621 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1   | 1:M 18 Aug 2020 11:22:36.621 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1   | 1:M 18 Aug 2020 11:22:36.621 * Loading RDB produced by version 6.0.6
redis_1   | 1:M 18 Aug 2020 11:22:36.621 * RDB age 53 seconds
redis_1   | 1:M 18 Aug 2020 11:22:36.621 * RDB memory usage when created 0.77 Mb
redis_1   | 1:M 18 Aug 2020 11:22:36.621 * DB loaded from disk: 0.000 seconds
redis_1   | 1:M 18 Aug 2020 11:22:36.621 * Ready to accept connections
pretix_app | Traceback (most recent call last):
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
pretix_app |     self.connect()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 197, in connect
pretix_app |     self.connection = self.get_new_connection(conn_params)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
pretix_app |     return Database.connect(**conn_params)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 130, in Connect
pretix_app |     return Connection(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/MySQLdb/connections.py", line 185, in __init__
pretix_app |     super().__init__(*args, **kwargs2)
pretix_app | MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'db'@'172.20.0.24' (using password: YES)")
pretix_app | 
pretix_app | The above exception was the direct cause of the following exception:
pretix_app | 
pretix_app | Traceback (most recent call last):
pretix_app |   File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
pretix_app |     "__main__", mod_spec)
pretix_app |   File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
pretix_app |     exec(code, run_globals)
pretix_app |   File "/pretix/src/pretix/__main__.py", line 9, in <module>
pretix_app |     execute_from_command_line(sys.argv)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
pretix_app |     utility.execute()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
pretix_app |     self.fetch_command(subcommand).run_from_argv(self.argv)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
pretix_app |     self.execute(*args, **cmd_options)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 366, in execute
pretix_app |     self.check()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 395, in check
pretix_app |     include_deployment_checks=include_deployment_checks,
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 63, in _run_checks
pretix_app |     issues = run_checks(tags=[Tags.database])
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
pretix_app |     new_errors = check(app_configs=app_configs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
pretix_app |     issues.extend(conn.validation.check(**kwargs))
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
pretix_app |     issues.extend(self._check_sql_mode(**kwargs))
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
pretix_app |     with self.connection.cursor() as cursor:
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 260, in cursor
pretix_app |     return self._cursor()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 236, in _cursor
pretix_app |     self.ensure_connection()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
pretix_app |     self.connect()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
pretix_app |     raise dj_exc_value.with_traceback(traceback) from exc_value
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
pretix_app |     self.connect()
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 197, in connect
pretix_app |     self.connection = self.get_new_connection(conn_params)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
pretix_app |     return func(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
pretix_app |     return Database.connect(**conn_params)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 130, in Connect
pretix_app |     return Connection(*args, **kwargs)
pretix_app |   File "/usr/local/lib/python3.6/site-packages/MySQLdb/connections.py", line 185, in __init__
pretix_app |     super().__init__(*args, **kwargs2)
pretix_app | django.db.utils.OperationalError: (1045, "Access denied for user 'db'@'172.20.0.24' (using password: YES)")
pretix_app | 2020-08-18 11:22:41,955 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
pretix_app | 2020-08-18 11:22:41,955 WARN No file matches via include "/etc/supervisord-*.conf"
pretix_app | 2020-08-18 11:22:41,969 INFO RPC interface 'supervisor' initialized
pretix_app | 2020-08-18 11:22:41,969 CRIT Server 'unix_http_server' running without any HTTP authentication checking
pretix_app | 2020-08-18 11:22:41,970 INFO supervisord started with pid 13
pretix_app | 2020-08-18 11:22:42,973 INFO spawned: 'pretixweb' with pid 16
pretix_app | 2020-08-18 11:22:42,976 INFO spawned: 'pretixtask' with pid 17
pretix_app | 2020-08-18 11:22:42,979 INFO spawned: 'nginx' with pid 18
pretix_app | 2020-08-18 11:22:44,008 INFO success: pretixweb entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

Docker Compose文件

version: '3'

services:

  pretix:
    image: 'pretix/standalone:stable'
    container_name: pretix_app
    restart: always
    depends_on:
      - db
      - redis
    volumes:
      - /mnt/docker/pretix/data:/data
      - /mnt/docker/pretix/conf:/etc/pretix
    networks:
      - web
      - stack_network
    environment:
      VIRTUAL_HOST: MYURL
      LETSENCRYPT_HOST: MYURL
      LETSENCRYPT_EMAIL: MAIL
    expose:
      - 80
      - 443

  db:
    image: mariadb:10
    restart: always
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=true
      - MYSQL_DATABASE=db
      - MYSQL_USER=db
      - MYSQL_PASSWORD=db
    volumes:
      - /mnt/docker/pretix/mariadb:/var/lib/mysql
    networks:
      - stack_network

  redis:
    image: redis:latest
    restart: always
    networks:
      - stack_network

networks:
  web:
    external:
      name: nginx-proxy
  stack_network:
    external: false

Pretix配置

[pretix]
instance_name=MYURL
url=https://MYURL
currency=EUR
; DO NOT change the following value, it has to be set to the location of the
; directory *inside* the docker container
datadir=/data
registration=off

[locale]
default=en
timezone=Europe/Berlin

[database]
backend=mysql
name=db
user=db
password=db
host=db
port=3306

[mail]
from=MAIL
host=MAILSERVER
user=MAIL
password=PASSWORD
port=587
tls=on
ssl=off

[redis]
location=redis://redis/0
; Remove the following line if you are unsure about your redis'security
; to reduce impact if redis gets compromised.
sessions=true

[celery]
backend=redis://redis/1
broker=redis://redis/2

1 个答案:

答案 0 :(得分:0)

我发现了错误:我使用的数据库密码太长(128个字符),导致错误。通过使用较短的密码,一切都会按预期进行