【问题标题】:Why MariaDB loads setting for about 5-8 minutes?为什么 MariaDB 加载设置大约需要 5-8 分钟?
【发布时间】:2020-01-30 14:00:22
【问题描述】:

我想使用 docker-compose 创建两个图像: 1. 我的 Spring Boot 应用 2. MariaDB 作为应用程序的数据库

MariaDB 的 dockerfile:

FROM mariadb:latest

ADD my.cnf /etc/mysql/my.cnf
ENV MYSQL_USER test
ENV MYSQL_PASSWORD Test123456
ENV MYSQL_ROOT_PASSWORD lsagvcbjkz<kcnz
EXPOSE 3306

和 docker.compose:

version: '2.1'

services:
  db:
    image: mariadb
    container_name: mariaDB
    environment:
      MYSQL_DATABASE: testdb
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
    networks:
      - backend

  app:
    image: app
    container_name: APP
    restart: on-failure
    ports:
      - 8080:8080
    depends_on:
       db:
        condition: service_healthy
    networks:
      - backend

networks:
  backend:
    driver: bridge

MariaDB 日志:

Initializing database


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h  password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

Database initialized
MySQL init process in progress...
2019-10-01  9:08:58 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 108 ...
2019-10-01  9:08:58 0 [Note] InnoDB: Using Linux native AIO
2019-10-01  9:08:59 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-01  9:08:59 0 [Note] InnoDB: Uses event mutexes
2019-10-01  9:08:59 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-10-01  9:08:59 0 [Note] InnoDB: Number of pools: 1
2019-10-01  9:08:59 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-10-01  9:08:59 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-10-01  9:08:59 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2019-10-01  9:08:59 0 [Note] InnoDB: Completed initialization of buffer pool
2019-10-01  9:08:59 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-10-01  9:08:59 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-10-01  9:08:59 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-10-01  9:08:59 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-10-01  9:08:59 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-10-01  9:08:59 0 [Note] InnoDB: 10.4.8 started; log sequence number 139836; transaction id 21
2019-10-01  9:08:59 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-10-01  9:08:59 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-10-01  9:08:59 0 [Warning] 'user' entry 'root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Warning] 'user' entry '@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:08:59 0 [Note] InnoDB: Buffer pool(s) load completed at 191001  9:08:59
2019-10-01  9:08:59 0 [Note] Reading of all Master_info entries succeeded
2019-10-01  9:08:59 0 [Note] Added new Master_info '' to hash table
2019-10-01  9:08:59 0 [Note] mysqld: ready for connections.
Version: '10.4.8-MariaDB-1:10.4.8+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
2019-10-01  9:16:52 25 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.

如您所见,MariaDB 不加载 my.cnf 文件:“端口:0” 几分钟后 MariaDB 重置:

2019-10-01  9:16:52 0 [Note] mysqld (initiated by: unknown): Normal shutdown
2019-10-01  9:16:52 0 [Note] Event Scheduler: Purging the queue. 0 events
2019-10-01  9:16:52 0 [Note] InnoDB: FTS optimize thread exiting.
2019-10-01  9:16:52 0 [Note] InnoDB: Starting shutdown...
2019-10-01  9:16:52 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-10-01  9:16:52 0 [Note] InnoDB: Buffer pool(s) dump completed at 191001  9:16:52
2019-10-01  9:16:54 0 [Note] InnoDB: Shutdown completed; log sequence number 20431569; transaction id 14896
2019-10-01  9:16:54 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-10-01  9:16:54 0 [Note] mysqld: Shutdown complete


MySQL init process done. Ready for start up.

2019-10-01  9:16:54 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 1 ...
2019-10-01  9:16:54 0 [Note] InnoDB: Using Linux native AIO
2019-10-01  9:16:54 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-01  9:16:54 0 [Note] InnoDB: Uses event mutexes
2019-10-01  9:16:54 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-10-01  9:16:54 0 [Note] InnoDB: Number of pools: 1
2019-10-01  9:16:54 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-10-01  9:16:54 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-10-01  9:16:54 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2019-10-01  9:16:54 0 [Note] InnoDB: Completed initialization of buffer pool
2019-10-01  9:16:54 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-10-01  9:16:54 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-10-01  9:16:54 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-10-01  9:16:54 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-10-01  9:16:54 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-10-01  9:16:54 0 [Note] InnoDB: Waiting for purge to start
2019-10-01  9:16:54 0 [Note] InnoDB: 10.4.8 started; log sequence number 20431569; transaction id 14896
2019-10-01  9:16:54 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-10-01  9:16:54 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-10-01  9:16:54 0 [Note] Server socket created on IP: '0.0.0.0'.
2019-10-01  9:16:54 0 [Warning] 'proxies_priv' entry '@% root@c147913c7f5c' ignored in --skip-name-resolve mode.
2019-10-01  9:16:54 0 [Note] Reading of all Master_info entries succeeded
2019-10-01  9:16:54 0 [Note] Added new Master_info '' to hash table
2019-10-01  9:16:54 0 [Note] mysqld: ready for connections.
Version: '10.4.8-MariaDB-1:10.4.8+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2019-10-01  9:16:54 0 [Note] InnoDB: Buffer pool(s) load completed at 191001  9:16:54

从这一刻起,我的应用程序最终可以连接到数据库。 “端口:3306”

我的问题是: MariaDB 应该加载这么长时间吗? MariaDB 是否应该在加载 my.cnf 设置几分钟后重启?

【问题讨论】:

  • 我没有看到任何命令来构建你的镜像,你的 docker-compose 中没有 db 服务的构建部分,没有任何证据表明这个镜像是实际构建和使用的。据我所知,您正在使用股票 mariadb:latest 图片。
  • docker-compose 正在使用 MariaDB 的 dockerfile 来构建 MariaDB。是的,我使用的是最新版本的 MariaDB。

标签: java spring-boot docker docker-compose mariadb


【解决方案1】:

mariadb docker 镜像的入口点运行脚本 docker-entrypoint.sh。此脚本将时区信息加载到运行命令的数据库中:

mysql_tzinfo_to_sql /usr/share/zoneinfo

在测试期间,我发现运行此命令的时间可能非常长。设置环境变量MYSQL_INITDB_SKIP_TZINFO=1 可以跳过这一步,加快你的数据库初始化。

【讨论】:

    【解决方案2】:

    我有同样的问题。加载时区信息(有时)似乎占用了大量时间(+6 分钟)。

    您可以通过禁用它来检查它:

      db:
        image: mariadb
        environment:
          - MYSQL_INITDB_SKIP_TZINFO=1
    

    现在不到 30 秒就开始了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多