通过swarm模式,容器可以部署在任何连接的节点中。我在host1上创建了一个共享的nfs文件夹作为mysql数据文件夹。Mysql容器无法将数据挂载到nfs文件夹
mkdir -p /nfs/data-volume
在另一个host2中,它将挂载到此共享文件夹。并增加了必要的许可。我通过读取和写入一些文本文件来尝试这个nfs共享文件夹。它工作得很好。 (没有权限错误) 在这些nfs配置之后,我定义了像这样的容器卷;
mysqldb-read:
image: demo/db-slave
ports:
- "3308:3306"
volumes:
- /nfs/data-volume:/var/lib/mysql
结果是: 如果主机1 mysql的容器运行,工作非常好。 如果mysql容器在host2上运行,它不会启动。但容器不退出,线程停留在那里,看起来像等待一些东西。 通过运行检查日志命令:
docker logs -f mymysql
这表明日志是这样的:
2017-06-07T02:40:13.627195Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-07T02:40:13.632313Z 0 [Note] mysqld (mysqld 5.7.18-log) starting as process 52 ...
2017-06-07T02:40:13.648010Z 0 [Note] InnoDB: PUNCH HOLE support available
2017-06-07T02:40:13.648054Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-06-07T02:40:13.648059Z 0 [Note] InnoDB: Uses event mutexes
2017-06-07T02:40:13.648062Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2017-06-07T02:40:13.648066Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-06-07T02:40:13.648069Z 0 [Note] InnoDB: Using Linux native AIO
2017-06-07T02:40:13.648326Z 0 [Note] InnoDB: Number of pools: 1
2017-06-07T02:40:13.648770Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-06-07T02:40:13.651011Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-06-07T02:40:13.760444Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-06-07T02:40:13.829981Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
不过在此日志,它将停止在这条线。 我试图登录到容器中,并输入命令
mysqld -uroot -proot
放映日志是完全一样的。
我觉得这是由nfs引起的。但是我搜索了一下,发现几乎所有的材料都建议使用nfs来共享数据。有没有人成功完成这项工作?或者对我有什么建议?
感谢
只是添加一些信息。你的'mysqld -uroot -proot'不正确。你应该执行'mysql'(客户端)而不是'mysqld'(服务器) – Robert