LoginSignup
0
1

KubernetesでMySQLがInnoDB: Creating or opening ./ibdata1 failed!エラーになる

Last updated at Posted at 2023-05-18

はじめに

KubernetesでDBを立てる際にうまく動かなかったのでいくつかの解決方法をまとめます
この解決にかなりの時間を使ってしまったので、役立ったら幸いです

問題

minikube(Kubernetes)でポッドを起動しようとしたところ以下のエラーが発生しました

      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Warning] Can't create test file /usr/data/test-db-1111111111-rt4hc.lower-test
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Warning] Can't create test file /usr/data/test-db-1111111111-rt4hc.lower-test
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Using atomics to ref count buffer pool pages
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: The InnoDB memory heap is disabled
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Memory barrier is not used
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Compressed tables use zlib 1.2.11
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Using Linux native AIO
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Using CPU crc32 instructions
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Initializing buffer pool, size = 1.0G
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] InnoDB: Completed initialization of buffer pool
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 7f2c47dfe040  InnoDB: Operating system error number 13 in a file operation.
      > [test-db-1111111111-rt4hc test] InnoDB: The error means mysqld does not have the access rights to
      > [test-db-1111111111-rt4hc test] InnoDB: the directory.
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 7f2c47dfe040  InnoDB: Operating system error number 13 in a file operation.
      > [test-db-1111111111-rt4hc test] InnoDB: The error means mysqld does not have the access rights to
      > [test-db-1111111111-rt4hc test] InnoDB: the directory.
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [ERROR] InnoDB: Creating or opening ./ibdata1 failed!
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [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!
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [ERROR] Plugin 'InnoDB' init function returned error.
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [ERROR] Unknown/unsupported storage engine: InnoDB
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [ERROR] Aborting
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] Binlog end
      > [test-db-1111111111-rt4hc test] 2023-05-18 07:31:16 52 [Note] /usr/sbin/mysqld: Shutdown complete

MySQLのイメージを使って直接起動もしてみたのですがうまくいったので、なぜ起動できないのかがわかりませんでした

解決方法 1

minikubeでKubernetes環境を用意していましたが、minikubeだとうまくクラスタでポッドの起動ができないようでした

そこでk3dに変更したところ動くようになる人もおりました

(私はうまくいかず)

解決方法 2

minikube startのさいにDriverをkvmを渡してうまくいる人もいました
Ubuntuの方は以下を参考にminikubeのクラスターを作ります

(私はうまくいかず)

解決方法 3

私はこの方法でうまくいきました

AppRmorが書き込みをブロックしていたので無効にするように設定しました

$ sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
$ sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld

AppArmor は、Linux カーネルのセキュリティモジュールであり、アプリケーションの実行時にその動作を制限するために使用されます

/etc/apparmor.d/disable/ディレクトリに作成することで、指定された AppArmor プロファイル(ここでは usr.sbin.mysqld)が無効になり、MySQL デーモン(mysqld)に対する AppArmor の制限が解除されるようです

(ChatGPTによると)

おわりに

社内でときどき起きていた問題でしたが、ネットには情報がなかったので記事にまとめてみました
解決方法3つはどれも解決できている人が社内にいたようですが、私は3つ目で解決しました

困った方は試してみるとよいかもしれません

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1