我是在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
root0:
daemon1:
bin2:
sys3:
adm4:
tty5:
disk6:
lp7:
mail8:
news9:
uucp10:
man12:
proxy13:
kmem15:
dialout20:
fax21:
voice22:
cdrom24:
floppy25:
tape26:
sudo27:
audio29:
dip30:
www-data33:
backup34:
operator37:
list38:
irc39:
src40:
gnats41:
shadow42:
utmp43:
video44:
sasl45:
plugdev46:
staff50:
games60:
users
nogroup65534:
mysql999:
容器中查询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服务无法启动。
求助如何解决,谢谢!