通過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