RAMDisk 上的 MySQL 未启动

RAMDisk 上的 MySQL 未启动

我正在尝试将 mysql 程序的所有执行(所有表数据、索引等)移至 RAM 磁盘上,以进行性能实验,从我的常规 SSD 中排除文件 IO。

我首先像平常一样安装 mysql:sudo apt install mysql-server。程序mysqld开始,我可以正常创建数据库。

我还按照此站点上列出的说明创建了一个 RAMDisk:在 Ubuntu 上创建 RAMDisk在该位置/mnt/ramdisk并使用大小25G(我有64G可用的 RAM)。我可以写入该位置并观察到我的 RAM 开始按预期填满。

现在,我使用以下命令将 mysql 库目录复制到此 RAMDisk:

cp -rp /var/lib/mysql /mnt/ramdisk

并符号链接到它,这样我就不必更改文件datadir中的参数/etc/mysql/mysql.conf.d/mysqld.cnf

mv mysql _mysql    
ln -s /mnt/ramdisk/mysql mysql

我还更改了权限,以便 MySQL“应该”能够访问 RAMDisk:

root@HOSTNAME:/var/lib# ls -l | grep mysql
lrwxrwxrwx  1 mysql         mysql           19 Feb 14 16:45 mysql -> /mnt/ramdisk/mysql/
drwx------  6 mysql         mysql         4096 Feb 14 17:06 _mysql
drwx------  2 mysql         mysql         4096 Feb 14 12:14 mysql-files
drwx------  2 mysql         mysql         4096 Feb 12 17:14 mysql-keyring
drwxr-xr-x  2 root          root          4096 Jan 21 06:10 mysql-upgrade

root@HOSTNAME:/mnt# ls -l
total 0
drwxrwxrwt 3 mysql mysql 60 Feb 14 17:24 ramdisk

root@HOSTNAME:/mnt/ramdisk# ls -l
total 0
drwx------ 5 mysql mysql 380 Feb 14 16:41 mysql

但是,当我现在尝试重新启动该mysqld程序时,遇到以下错误:

USER@HOSTNAME:/$ sudo /etc/init.d/mysql restart
[sudo] password for USER: 
[....] Restarting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!

研究两者systemctl status mysql.servicejournalctl -xe不能更深入地了解问题:

USER@HOSTNAME:/$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2020-02-14 17:30:55 PST; 1min 0s ago
  Process: 19794 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
  Process: 19785 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 17945 (code=exited, status=0/SUCCESS)

Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Feb 14 17:30:55 HOSTNAME systemd[1]: Stopped MySQL Community Server.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Start request repeated too quickly.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 14 17:30:55 HOSTNAME systemd[1]: Failed to start MySQL Community Server.

对于journalctl -xe

-- Unit mysql.service has begun starting up.
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/ibdata1" pid=19796 comm="mysqld" requested_mask="wr" denied_mask="wr" fsuid=125 ouid=125
Feb 14 17:30:55 HOSTNAME mysqld[19794]: Initialization of mysqld failed: 0
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Control process exited, code=exited status=1
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 14 17:30:55 HOSTNAME systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mysql.service has failed.

答案1

事实证明,问题就在输出中摆在我面前journalctl -xe

Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

更具体地说,apparmor=“已拒绝”部分。来自 AskUbuntu 上的这个答案:mysql文件夹重定位后Apparmor错误我能够解决我的问题。我将在下面添加相关详细信息:


编辑/etc/apparmor.d/usr.sbin.mysqld文件。删除/var/lib/mysql并添加新的 datadir 位置。就我而言是

 # Allow data dir access
 /mnt/ramdisk/mysql/ r,
 /mnt/ramdisk/mysql/** rwk,

重新启动apparmor:service systemctl restart apparmor

重启mysql服务:service mysql start

相关内容