【问题标题】:Mysql cannot write to a persistent volume that minikube createsMysql 无法写入 minikube 创建的持久卷
【发布时间】:2017-10-07 02:28:59
【问题描述】:

我正在尝试使用 hostPath 将具有持久卷的 minikube mysql pod 部署到 Mac 主机上的 /data 或 /Users 目录。但是,创建的目录总是具有错误的权限,mysql 无法访问或写入该目录。如果我运行minikube ssh 并运行chmod -R 777 /data/db/,那么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

【问题讨论】:

    标签: mysql macos-sierra minikube


    【解决方案1】:

    解决方案 1。 将主机上的权限更改为例如777.

    解决方案 2。(更好) 通过容器启动将卷所有者更改为 mysql 用户。对于 docker(Dockerfile):

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

    解决方案 3. 以 root 用户启动 mysql ;)

    【讨论】:

    • 1. & 2. 主机是 minikube VM,所以我无法更改权限 3. 可能不是安全的最佳解决方案
    • 你使用 docker 还是其他容器引擎?
    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2020-11-10
    • 2018-09-18
    相关资源
    最近更新 更多