Docker mysql-指定的数据目录无法使用

发布于 2025-01-28 21:08:32 字数 4152 浏览 2 评论 0原文

我有一个MySQL Docker容器,该容器将其数据并将目录映射到主机路径上。

主机路径是两个独立的ZFS安装点。

当我尝试启动mySQL时,它正在报告:

[Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
[Entrypoint]: Switching to dedicated user 'mysql'
[Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
[Entrypoint]: Initializing database files
[Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
[System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 42
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
[ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/innodb-data/ is unusable. You can remove all files that the server added to it.
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28)  MySQL Community Server - GPL.

MySQL在关闭之前在主机的数据目录中创建以下文件:

ll /db/mysql-innodb-data/dir/
total 12302
drwxr-xr-x 2 systemd-coredump root                    4 May 15 12:56 ./
drwxr-xr-x 3 mysql            mysql                   3 May 15 12:37 ../
-rw-r----- 1 systemd-coredump systemd-coredump       56 May 15 12:37 auto.cnf
-rw-r----- 1 systemd-coredump systemd-coredump 12582912 May 15 12:37 ibdata1

SystemD-Coredump用户是UID 999,我猜它向容器中的MySQL用户映射。

因此,很明显,容器可以写入主机。

Mount命令显示:

db on /db type zfs (rw,xattr,noacl)
db/mysql-innodb-data on /db/mysql-innodb-data type zfs (rw,xattr,noacl)
db/mysql-innodb-logs on /db/mysql-innodb-logs type zfs (rw,xattr,noacl)

ZFS Mount命令显示:

zfs mount
db                              /db
db/mysql-innodb-data            /db/mysql-innodb-data
db/mysql-innodb-logs            /db/mysql-innodb-logs

假设MySQL不喜欢写入安装点的根;

我已经尝试将数据和记录方向登录到ZFS安装点的子DIR,将Docker-Compose映射设置为:

   volumes:
      - /db/mysql-innodb-data/dir:/var/lib/mysql/innodb-data 
      - /db/mysql-innodb-logs/dir:/var/lib/mysql/innodb-logs

但是,上述更改没有区别。

这是Docker-Compose服务部分:

mysql:
    container_name: mysql
    image: noojee/mysql-zfs:8.0
    restart: on-failure
    environment: 
      MYSQL_ROOT_PASSWORD: ${MYSQL_ADMIN_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_SCHEMA}
      TZ: ${TIME_ZONE-Australia/Melbourne}
    # https://www.percona.com/blog/mysql-zfs-performance-update/
    # --innodb_flush_log_at_trx_commit=1 # TPCC reqs.
    # --innodb_doublewrite=0 # ZFS is transactional
    command: >
                 --lower-case-table-names=1 
                 --datadir=/var/lib/mysql/innodb-data 
                 --innodb_log_group_home_dir=/var/lib/mysql/innodb-logs
                 --default-authentication-plugin=mysql_native_password
                 --max-allowed-packet=512M
                 --innodb_buffer_pool_instances=${MYSQL_INNODB_BUFFER_POOL_INSTANCES-32}
                 --innodb_buffer_pool_chunk_size=${MYSQL_INNODB_BUFFER_POOL_CHUNK_SIZE-8M}
                 --innodb_buffer_pool_size=${MYSQL_INNODB_BUFFER_POOL_SIZE-512M}
                 --table_open_cache=${MYSQL_TABLE_OPEN_CACHE-512}
                 --max_connections=${MYSQL_MAX_CONNECTIONS-98}
                 --innodb_flush_neighbors=0
                 --innodb_fast_shutdown=2
                 --innodb_flush_log_at_trx_commit=1
                 --innodb_flush_method=fsync
                 --innodb_doublewrite=0 
                 --innodb_use_native_aio=0
                 --innodb_read_io_threads=10
                 --innodb_write_io_threads=10
                 --slow_query_log_file=/tmp/mysql-slow.log --long-query-time=1
                 --slow_query_log

#    mem_limit: ${MYSQL_MEMORY}
    volumes:
      - /db/mysql-innodb-data/dir:/var/lib/mysql/innodb-data 
      - /db/mysql-innodb-logs/dir:/var/lib/mysql/innodb-logs
    network_mode: "host"
    logging:
      driver: "journals"

I have a mysql docker container that maps its data and logs directories onto a host path.

The host paths are two separate zfs mount points.

When I try to start MySQL it is reporting:

[Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
[Entrypoint]: Switching to dedicated user 'mysql'
[Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started.
[Entrypoint]: Initializing database files
[Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
[System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 42
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
[ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/innodb-data/ is unusable. You can remove all files that the server added to it.
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28)  MySQL Community Server - GPL.

Mysql creates the following files in the host's data directory before shutting down:

ll /db/mysql-innodb-data/dir/
total 12302
drwxr-xr-x 2 systemd-coredump root                    4 May 15 12:56 ./
drwxr-xr-x 3 mysql            mysql                   3 May 15 12:37 ../
-rw-r----- 1 systemd-coredump systemd-coredump       56 May 15 12:37 auto.cnf
-rw-r----- 1 systemd-coredump systemd-coredump 12582912 May 15 12:37 ibdata1

The systemd-coredump user is uid 999 which I'm guessing maps to the MySQL user in the container.

So clearly the container can write to the host.

The mount command shows:

db on /db type zfs (rw,xattr,noacl)
db/mysql-innodb-data on /db/mysql-innodb-data type zfs (rw,xattr,noacl)
db/mysql-innodb-logs on /db/mysql-innodb-logs type zfs (rw,xattr,noacl)

The zfs mount command shows:

zfs mount
db                              /db
db/mysql-innodb-data            /db/mysql-innodb-data
db/mysql-innodb-logs            /db/mysql-innodb-logs

On the assumption that MySQL doesn't like writing to the root of the mount point;

I've tried moving the data and log direction into a sub dir of the zfs mount points with the docker-compose mapping set to:

   volumes:
      - /db/mysql-innodb-data/dir:/var/lib/mysql/innodb-data 
      - /db/mysql-innodb-logs/dir:/var/lib/mysql/innodb-logs

However, the above changes made no difference.

Here is the docker-compose service section:

mysql:
    container_name: mysql
    image: noojee/mysql-zfs:8.0
    restart: on-failure
    environment: 
      MYSQL_ROOT_PASSWORD: ${MYSQL_ADMIN_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_SCHEMA}
      TZ: ${TIME_ZONE-Australia/Melbourne}
    # https://www.percona.com/blog/mysql-zfs-performance-update/
    # --innodb_flush_log_at_trx_commit=1 # TPCC reqs.
    # --innodb_doublewrite=0 # ZFS is transactional
    command: >
                 --lower-case-table-names=1 
                 --datadir=/var/lib/mysql/innodb-data 
                 --innodb_log_group_home_dir=/var/lib/mysql/innodb-logs
                 --default-authentication-plugin=mysql_native_password
                 --max-allowed-packet=512M
                 --innodb_buffer_pool_instances=${MYSQL_INNODB_BUFFER_POOL_INSTANCES-32}
                 --innodb_buffer_pool_chunk_size=${MYSQL_INNODB_BUFFER_POOL_CHUNK_SIZE-8M}
                 --innodb_buffer_pool_size=${MYSQL_INNODB_BUFFER_POOL_SIZE-512M}
                 --table_open_cache=${MYSQL_TABLE_OPEN_CACHE-512}
                 --max_connections=${MYSQL_MAX_CONNECTIONS-98}
                 --innodb_flush_neighbors=0
                 --innodb_fast_shutdown=2
                 --innodb_flush_log_at_trx_commit=1
                 --innodb_flush_method=fsync
                 --innodb_doublewrite=0 
                 --innodb_use_native_aio=0
                 --innodb_read_io_threads=10
                 --innodb_write_io_threads=10
                 --slow_query_log_file=/tmp/mysql-slow.log --long-query-time=1
                 --slow_query_log

#    mem_limit: ${MYSQL_MEMORY}
    volumes:
      - /db/mysql-innodb-data/dir:/var/lib/mysql/innodb-data 
      - /db/mysql-innodb-logs/dir:/var/lib/mysql/innodb-logs
    network_mode: "host"
    logging:
      driver: "journals"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文