2017-05-08 92 views
0

我試圖將具有持久性卷的minikube mysql pod使用hostPath部署到Mac主機上的/ data或/ Users目錄。但是,創建的目錄總是具有錯誤的權限,並且mysql無法訪問或寫入目錄。如果我運行minikube ssh並運行chmod -R 777 /data/db/,那麼mysql運行良好。有沒有辦法讓minikube設置正確的權限?Mysql無法寫入minikube創建的持久性卷

我得到的錯誤是

2017-05-08 23:22:45 23 [Note] InnoDB: Using atomics to ref count buffer pool pages 
2017-05-08 23:22:45 23 [Note] InnoDB: The InnoDB memory heap is disabled 
2017-05-08 23:22:45 23 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 
2017-05-08 23:22:45 23 [Note] InnoDB: Memory barrier is not used 
2017-05-08 23:22:45 23 [Note] InnoDB: Compressed tables use zlib 1.2.8 
2017-05-08 23:22:45 23 [Note] InnoDB: Using Linux native AIO 
2017-05-08 23:22:45 23 [Note] InnoDB: Using CPU crc32 instructions 
2017-05-08 23:22:45 23 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2017-05-08 23:22:45 23 [Note] InnoDB: Completed initialization of buffer pool 
2017-05-08 23:22:45 7fb9598ee740 InnoDB: Operating system error number 13 in a file operation. 
InnoDB: The error means mysqld does not have the access rights to 
InnoDB: the directory. 
2017-05-08 23:22:45 7fb9598ee740 InnoDB: Operating system error number 13 in a file operation. 
InnoDB: The error means mysqld does not have the access rights to 
InnoDB: the directory. 
2017-05-08 23:22:45 23 [ERROR] InnoDB: Creating or opening ./ibdata1 failed! 
2017-05-08 23:22:45 23 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data! 
2017-05-08 23:22:45 23 [ERROR] Plugin 'InnoDB' init function returned error. 
2017-05-08 23:22:45 23 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 
2017-05-08 23:22:45 23 [ERROR] Unknown/unsupported storage engine: InnoDB 
2017-05-08 23:22:45 23 [ERROR] Aborting 

我的容器定義是

spec: { 
     containers: [ 
     { 
      name: 'percona', 
      image: 'percona:5.6', 
      env: [ 
      { 
       name: 'MYSQL_ROOT_PASSWORD', 
       value: secrets['system-mysql-root-password'], 
      }, 
      { 
       name: 'MYSQL_OPS_USER', 
       value: variables['system-mysql-ops-user'], 
      }, 
      { 
       name: 'MYSQL_OPS_PASSWORD', 
       value: secrets['system-mysql-ops-password'], 
      }, 
      { 
       name: 'MYSQL_APP_USER', 
       value: variables['system-mysql-app-user'], 
      }, 
      { 
       name: 'MYSQL_APP_PASSWORD', 
       value: secrets['system-mysql-app-password'], 
      }, 
      ], 
      ports: [ 
      { 
       containerPort: 3306, 
       protocol: 'TCP', 
      }, 
      ], 
      volumeMounts: [ 
      { name: 'data', mountPath: '/var/lib/mysql' }, 
      { name: 'conf', mountPath: '/etc/mysql/conf.d' }, 
      ], 
     }, 
     ], 
     volumes: [ 
     { name: 'data', hostPath: { path: '/data/db/database' } }, 
     { name: 'conf', hostPath: { path: '/data/db/database-conf' } }, 
     ], 
    }, 

和minikube

drwxr-xr-x 2 root root 4096 May 8 23:22 database 
drwxr-xr-x 2 root root 4096 May 8 23:22 database-conf 

回答

0

解決方法1. 更改創建目錄的默認權限對主機的許可,例如777.

解決方案2.(更好) 通過容器啓動將卷所有者更改爲mysql用戶。對於搬運工(Dockerfile):

... 
CMD chown mysql:mysql -R /data/db/ 

溶液3啓動MySQL與根用戶)

+0

1.&2.主機是minikube VM,所以我不能改變權限3.可能不是最好的解決方案爲了安全 – ryanmc

+0

你使用docker還是其他容器引擎? – Mark