我正在尝试在 Raspberry Pi 上运行 MariaDB 容器。该容器是通过 docker-compose 创建的,为了保存数据,我想使用 NAS。要将目录从 NAS 挂载到容器,我想使用 NFS。
容器可以启动,但 MariaDB 无法正确启动,提示无法锁定 aria 控制文件。当我启动没有 NFS 挂载的容器时(因此在容器内定义了存储),它可以正常工作。
从 mariadb 容器记录日志:
2022-03-26 16:46:57+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.1+maria~focal started.
2022-03-26 16:46:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-03-26 16:46:58+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.1+maria~focal started.
2022-03-26 16:46:59+00:00 [Note] [Entrypoint]: Initializing database files
2022-03-26 16:50:40 0 [ERROR] mariadbd: Got error 'Could not get an exclusive lock; file is probably in use by another process' when trying to use aria control file '/var/lib/mysql/aria_log_control'
2022-03-26 16:47:05 0 [ERROR] mariadbd: Can't lock aria control file '/var/lib/mysql/aria_log_control' for exclusive use, error: 37. Will retry for 30 seconds
2022-03-26 16:50:40 0 [ERROR] Plugin 'Aria' init function returned error.
2022-03-26 16:50:40 0 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
2022-03-26 16:50:40 0 [ERROR] InnoDB: The data file './ibdata1' must be writable
2022-03-26 16:50:40 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2022-03-26 16:50:40 0 [ERROR] Plugin 'InnoDB' init function returned error.
2022-03-26 16:50:40 0 [ERROR] Failed to initialize plugins.
2022-03-26 16:50:40 0 [ERROR] Aborting
这是我的docker撰写文件:
version: "3.8"
services:
mariadb:
image: arm64v8/mariadb:10.7
container_name: mariadbtemp
restart: unless-stopped
security_opt:
- seccomp:unconfined
- apparmor:unconfined
command: mysqld --skip-grant-tables --innodb-buffer-pool-size=128M --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=120
volumes: # Don't remove permanent storage for index database files!
- mariadbtemp:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: <password>
MYSQL_DATABASE: photoprism
MYSQL_USER: photoprism
MYSQL_PASSWORD: <password>
volumes:
mariadbtemp:
driver_opts:
type: nfs
o: addr=<ip-adress>,rw,noatime,rsize=8192,wsize=8192,tcp,timeo=14
device: :/DataVolume/databases
cat /etc/exports
来自 NAS 的输出:
/nfs *(rw,sync,no_subtree_check,all_squash,insecure,anonuid=500,anongid=1000)
/DataVolume/databases <ip-adress of dockerhost>(rw,sync,no_subtree_check,insecure)
ls -aln /DataVolume/databases
NAS 上的输出:
total 320
drwxr-xr-x 2 999 999 65536 Mar 26 16:20 .
drwxr-xr-x 8 0 0 65536 Feb 7 14:21 ..
-rw-rw---- 1 999 999 16384 Mar 10 19:32 aria_log.00000001
-rw-rw---- 1 999 999 52 Mar 10 19:32 aria_log_control
-rw-rw---- 1 999 999 9 Mar 26 16:20 ddl_recovery.log
---------- 1 999 999 0 Mar 10 19:20 ibdata1
我尝试将 NFS 共享直接挂载到容器,将 NFS 共享定义为外部并通过 docker 对其进行配置,还将 NFS 共享挂载到 docker 主机并尝试这样做。但都不起作用。有人对如何继续有什么建议吗?
答案1
该错误看起来像是权限问题。您确定 mariadb mysqld 进程正在使用相同的 UID/相同的用户运行吗?您可以测试以该用户身份写入该卷吗?
由于多种原因,NFS 并不是 innodb 保存数据的最佳选择: https://dev.mysql.com/doc/refman/5.6/en/disk-issues.html#disk-issues-nfs
根据我的经验,越接近更快的存储硬件,mariadb 的性能就越好。根据您的使用情况,在与访问数据库的服务不同的位置上运行数据库可能会获得更好的结果。