docker安装pro 7,出现数据库无法启动的问题


#1

我是在windows上vmware装了ubuntu,然后ubuntu docker 安装seafile,挂载windows提供的nfs共享文件夹。

windows提供了三个nfs共享文件夹,分别创建了docker volume:volume-mysql、volume-esdata、volume-seafiledata。
三个volume分别在docker-compose.yml中映射到了三个服务的目录,例如mariadb容器的如下:
volumes:
- volume-mysql:/var/lib/mysql

为解决nfs挂在之后uid不一致的权限问题,我将db服务用的volume-mysql 对应的Nfs共享的owner设为了 999:999 。(999是seafile-mysql容器中用户mysql的id)。

执行 docker-compose up -d 后,查看mysql服务的用户是999

root@ubuntu:/mnt/seafile# ps aux | grep mysql
999 57005 0.0 0.0 18504 3232 ? Ss 10:35 0:00 /bin/bash /usr/local/bin/docker-entrypoint.sh mysqld
999 57109 0.0 0.0 4624 1608 ? S 10:35 0:00 /bin/sh /usr/bin/mysql_install_db --datadir=/var/lib/mysql/ --rpm --auth-root-authentication-method=normal
999 57135 0.0 0.0 4624 116 ? S 10:35 0:00 /bin/sh /usr/bin/mysql_install_db --datadir=/var/lib/mysql/ --rpm --auth-root-authentication-method=normal
999 57137 0.2 1.8 691176 75220 ? Dl 10:35 0:03 /usr/sbin/mysqld --lc-messages-dir=/usr/share/mysql/english/… --bootstrap --basedir=/usr --datadir=/var/lib/mysql/ --log-warnings=0 --enforce-storage-engine= --max_allowed_packet=8M --net_buffer_length=16K
root 57246 0.0 0.0 21532 1088 pts/0 S+ 10:55 0:00 grep --color=auto mysql

volume-mysql 的挂载点为 /var/lib/docker/volumes/volume-mysql/_data ,此路径的权限、owner信息如下:
root@ubuntu:/mnt/seafile# ls -la /var/lib/docker/volumes/volume-mysql
总用量 16
drwxrwsrwx 3 999 999 4096 4月 16 17:28 .
drwxrw-rw- 5 root root 4096 4月 19 23:34 …
drwxr-xr-x 3 999 999 4096 4月 22 10:35 _data
-rwxrwxrwx 1 999 999 80 4月 16 17:28 opts.json

/var/lib/docker/volumes/volume-mysql 的owner是999,权限也是可写的。

运行 docker exec -it seafile-mysql bash 进入容器,查询对应的var/lib/mysql 的权限、owner如下:
root@82ca14d49519:/# ls -la /var/lib/mysql
total 9
drwxr-xr-x 3 mysql mysql 4096 Apr 22 03:06 .
drwxr-xr-x 2 mysql mysql 4096 Apr 16 08:57 _data
-rw-r–r-- 1 mysql mysql 52 Apr 21 08:06 aria_log_control
-rw-r–r-- 1 mysql mysql 0 Apr 21 07:40 ibdata1

var/lib/mysql 的owner是mysql,也有读写权限。

mysql用户的id如下,为999:
root@82ca14d49519:/# cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:
floppy:x:25:
tape:x:26:
sudo:x:27:
audio:x:29:
dip:x:30:
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:
sasl:x:45:
plugdev:x:46:
staff:x:50:
games:x:60:
users:x::100:
nogroup:x:65534:
mysql:x:999:

容器中查询mysql服务对应的用户也是mysql,与上面在宿主机上查询mysql服务对应的999是一致的:
root@82ca14d49519:/# ps -ef|grep mysql
mysql 1 0 0 03:06 ? 00:00:00 /bin/bash /usr/local/bin/docker-entrypoint.sh mysqld
mysql 60 1 0 03:06 ? 00:00:00 /bin/sh /usr/bin/mysql_install_db --datadir=/var/lib/mysql/ --rpm --auth-root-authentication-method=normal
mysql 86 60 0 03:06 ? 00:00:00 /bin/sh /usr/bin/mysql_install_db --datadir=/var/lib/mysql/ --rpm --auth-root-authentication-method=normal
mysql 87 86 0 03:06 ? 00:00:00 /usr/sbin/mysqld --lc-messages-dir=/usr/share/mysql/english/… --bootstrap --basedir=/usr --datadir=/var/lib/mysql/ --log-warnings=0 --enforce-storage-engine= --max_allowed_packet=8M --net_buffer_length=16K
root 102 90 0 03:10 pts/0 00:00:00 grep --color=auto mysql

因此volume 对应的挂载点的目录在宿主机上的owner为999,有读写权限;volume 映射的 容器中的/var/lib/mysql 路径的owner为mysql,有读写权限,而mysql用户的id为999。因此容器中的mysql用户对宿主机上的volume路径应该也是有读写权限的。

但是执行 docker-compose up -d 后,再执行 docker logs -f seafile-mysql 查看日志如下:
2020-04-22 02:12:24+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.1.44+maria-1~bionic started.
2020-04-22 02:12:25+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
2020-04-22 02:12:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.1.44+maria-1~bionic started.
2020-04-22 02:12:27+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-22 2:12:27 140703069804544 [Note] /usr/sbin/mysqld (mysqld 10.1.44-MariaDB-1~bionic) starting as process 86 …
2020-04-22 2:12:40 140703069804544 [ERROR] mysqld: Can’t lock aria control file ‘/var/lib/mysql/aria_log_control’ for exclusive use, error: 5. Will retry for 30 seconds
2020-04-22 2:19:44 140703069804544 [ERROR] mysqld: 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’
2020-04-22 2:19:44 140703069804544 [ERROR] Plugin ‘Aria’ init function returned error.
2020-04-22 2:19:44 140703069804544 [ERROR] Plugin ‘Aria’ registration as a STORAGE ENGINE failed.
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Using Linux native AIO
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Using generic crc32 instructions
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Initializing buffer pool, size = 256.0M
2020-04-22 2:19:44 140703069804544 [Note] InnoDB: Completed initialization of buffer pool
2020-04-22 2:19:56 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:19:56 140703069804544 [Note] InnoDB: Retrying to lock the first data file
2020-04-22 2:20:10 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:20:23 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:20:36 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:20:50 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:21:03 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:21:16 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:21:29 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:21:43 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5
2020-04-22 2:21:56 140703069804544 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 5

mysql服务无法启动。

求助如何解决,谢谢!


#2

为何无人回复。。。求解 Orz