简体   繁体   English

Mysql容器无法将数据装载到nfs文件夹

[英]Mysql container can not mount data to a nfs folder

By swarm mode, containers may deploy in any joined nodes. 通过群集模式,容器可以部署在任何连接的节点中。 I created a shared nfs folder as mysql data folder on host1. 我在host1上创建了一个共享的nfs文件夹作为mysql数据文件夹。

mkdir -p /nfs/data-volume

In another host2, it mounts to this shared folder. 在另一个host2中,它安装到此共享文件夹。 And added necessary permission. 并添加了必要的许可。 I tried this nfs share folder by reading and writing some text file in it. 我通过读取和写入一些文本文件来尝试这个nfs共享文件夹。 It worked very well. 它工作得很好。 (There was no permission error) After these nfs configuration , I defined my container volume like this; (没有权限错误)在这些nfs配置之后,我像这样定义了我的容器卷;

mysqldb-read:
    image: demo/db-slave
    ports:
     - "3308:3306"
    volumes:
     - /nfs/data-volume:/var/lib/mysql

The result is: If mysql container run on host1, works very good. 结果是:如果mysql容器在host1上运行,效果非常好。 If mysql container run on host2, it doesn't startup. 如果mysql容器在host2上运行,则它不会启动。 But the container doesn't exit, the thread stay there and looks like wait something. 但是容器没有退出,线程停留在那里看起来像是在等待。 By running check log command: 通过运行check log命令:

docker logs -f mymysql

It shows logs like this: 它显示如下日志:

   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().

Nothing more on this log, it stops on this line. 此日志上没有更多内容,它在此行停止。 I tried to login into container, and input command 我试着登录容器,然后输入命令

mysqld -uroot -proot

The showing log is totally same. 显示日志完全相同。

I feel this is caused by nfs. 我觉得这是由nfs引起的。 But I googled and found almost all materials suggested to use nfs to share data. 但我用Google搜索并发现几乎所有材料都建议使用nfs来共享数据。 Is there anyone who successfully make this work? 是否有人成功完成这项工作? Or any suggestion to me? 或者对我有什么建议?

Thanks 谢谢

Q1: Is there anyone who successfully make this work ? Q1:有没有人成功完成这项工作?

My experience is... No . 我的经历是...... I tried NFS, MySQL and Docker Swarm (v1.12) some months ago and I also did fail with that. 几个月前我尝试过NFS,MySQL和Docker Swarm(v1.12),但我也确实失败了。

They are pretty clear with that indeed, from MySQL documentation : MySQL文档来看,它们非常清楚:

Using NFS with MySQL 使用NFS与MySQL

Caution is advised when considering using NFS with MySQL. 在考虑将NFS与MySQL一起使用时,建议小心。 Potential issues, which vary by operating system and NFS version, include: 潜在问题因操作系统和NFS版本而异,包括:

  • MySQL data and log files placed on NFS volumes becoming locked and unavailable for use... 放置在NFS卷上的MySQL数据和日志文件变为锁定且无法使用...
  • Data inconsistencies... 数据不一致......
  • Maximum file size limitations 最大文件大小限制

I also experienced file locks , slow queries and slow writes... 我也经历过文件锁 ,慢查询和慢写...

Q2: Or any suggestion to me? Q2:或者对我有什么建议?

One of docker-swarm tricky part is indeed with the data, especially with databases. docker-swarm棘手的一部分确实是数据,尤其是数据库。 You don't know on witch host the mysql container will be run. 你不知道在女主机上将运行mysql容器。 I've used two alternatives so overcome this: 我使用了两种替代品,所以克服了这个:

1. Swarm mode service creation --constraint option 1. Swarm模式服务创建--constraint选项

This option will instruct docker to deploy your MySQL container always on the same host, for instance: 此选项将指示docker始终在同一主机上部署MySQL容器,例如:

mysqldb-read:
  image: demo/db-slave
  ports:
    - "3308:3306"
  volumes:
    - /nfs/data-volume:/var/lib/mysql
  deploy:
    placement:
      constraints: [node.hostname == host1]

If docker swarm service mysqldb-read restarts, this will always be on host1 node. 如果mysqldb-read swarm service mysqldb-read重新启动,则它将始终位于host1节点上。

2. Docker volumes 2. Docker卷

Another option is to dynamically attach a shared docker volume to the MySQL service before startup. 另一种选择是在启动之前将共享docker volume动态连接到MySQL服务。 The documentation states : 文件说明

If you want your data to persist, use a named volume and a volume driver that is multi-host aware, so that the data is accessible from any node... 如果您希望数据保持不变,请使用可识别多主机的命名卷和卷驱动程序,以便可以从任何节点访问数据...

There are some docker volume plugins that allow you to do that. 有一些docker volume插件可以让你这样做。 I personally tried rancher's convoy in an AWS environment, but I also have other issues with volume deletion, sync, etc... 我亲自在AWS环境中尝试过牧场主的车队 ,但是我还有其他卷删除,同步等问题......

You can also have a look at this popular SO thread about swarm and docker volumes . 您还可以查看有关swarm和docker卷的这个流行的SO线程

PS: About NFS PS:关于NFS

I'm not saying that you should give up NFS for other docker services, I still use it for read-only configuration files (Apache Tomcat and Nginx configuration, etc...), but for MySQL it's a no go. 我不是说你应该放弃NFS用于其他docker服务,我仍然将它用于read-only配置文件(Apache Tomcat和Nginx配置等等),但是对于MySQL来说它是不行的。

Hope my experience will help! 希望我的经验会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM