mysqld 的 AppArmor 解析器错误

mysqld 的 AppArmor 解析器错误

我尝试将 MySQL 数据目录更改为新位置。

因此我修改了 MySQL 配置文件

/etc/mysql/mysql.conf.d/mysqld.cnf

和 apparmor 文件

/etc/apparmor.d/usr.sbin.mysqld

不幸的是它没有起作用并且我收到以下错误:

mysqld: Can't change dir to '/new/dir/mysql/' (Errcode: 13 - Permission denied)

我重新安装了 mysql 和 apparmor。从那时起,apparmor 就不再起作用了。我收到以下消息:

错误信息:

root@Server:~# systemctl status apparmor.service
● apparmor.service - LSB: AppArmor initialization
   Loaded: loaded (/etc/init.d/apparmor; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2018-08-24 09:24:24 CEST; 1min 41s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 19955 ExecStart=/etc/init.d/apparmor start (code=exited, status=123)

Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.dict in /etc/apparmor.d/abstractions/nameservice at line 16: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.lib.snapd.snap-confine.real in /etc/apparmor.d/usr.lib.snapd.snap-confine.real at line 11: Could not open '/var/lib/snapd/apparmor/snap-confine'
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.sbin.dovecot in /etc/apparmor.d/abstractions/nameservice at line 16: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in /etc/apparmor.d/abstractions/winbind at line 13: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]:    ...fail!
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Control process exited, code=exited status=123
Aug 24 09:24:24 Server systemd[1]: Failed to start LSB: AppArmor initialization.
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Unit entered failed state.
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Failed with result 'exit-code'.

我已经尝试修复这些错误几个小时了。但现在我完全没有头绪了。有什么建议可以解决该问题吗?

编辑:usr.sbin.mysqld 文件的内容

cat /etc/apparmor.d/usr.sbin.mysqld

# vim:syntax=apparmor
# Last Modified: Tue Feb 09 15:28:30 2016
#include <tunables/global>

/usr/sbin/mysqld flags=(complain) {
  #include <abstractions/base>
  #include <abstractions/nameservice>
  #include <abstractions/user-tmp>
  #include <abstractions/mysql>
  #include <abstractions/winbind>

# Allow system resource access
  /sys/devices/system/cpu/ r,
  capability sys_resource,
  capability dac_override,
  capability setuid,
  capability setgid,

# Allow network access
  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

# Allow config access
  /etc/mysql/** r,

# Allow pid, socket, socket lock file access
  /var/run/mysqld/mysqld.pid rw,
  /var/run/mysqld/mysqld.sock rw,
  /var/run/mysqld/mysqld.sock.lock rw,
  /run/mysqld/mysqld.pid rw,
  /run/mysqld/mysqld.sock rw,
  /run/mysqld/mysqld.sock.lock rw,

# Allow execution of server binary
  /usr/sbin/mysqld mr,
  /usr/sbin/mysqld-debug mr,

# Allow plugin access
  /usr/lib/mysql/plugin/ r,
  /usr/lib/mysql/plugin/*.so* mr,

# Allow error msg and charset access
  /usr/share/mysql/ r,
  /usr/share/mysql/** r,

# Allow data dir access
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,

# Allow data files dir access
  /var/lib/mysql-files/ r,
  /var/lib/mysql-files/** rwk,

# Allow keyring dir access
  /var/lib/mysql-keyring/ r,
  /var/lib/mysql-keyring/** rwk,

# Allow log file access
  /var/log/mysql.err rw,
  /var/log/mysql.log rw,
  /var/log/mysql/ r,
  /var/log/mysql/** rw,

  # Site-specific additions and overrides. See local/README for details.
  #include <local/usr.sbin.mysqld>
}

答案1

彻底删除所有与 mysql 相关的数据是我让 Apparmor 重新工作的解决方案。

除了删除 mysql 之外,

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

我删除了以下文件夹/文件:

rm -rf /etc/apparmor.d/abstractions/mysql 
rm -rf /etc/apparmor.d/cache/usr.sbin.mysqld 
rm -rf /etc/mysql 
rm -rf /var/lib/mysql 
rm -rf /var/log/mysql* 
rm -rf /var/log/upstart/mysql.log* 
rm -rf /var/run/mysqld 
rm -rf ~/.mysql_history

这提示我出现以下错误:

    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.auth in /etc/apparmor.d/usr.lib.dovecot.auth at line 18: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.dict in /etc/apparmor.d/usr.lib.dovecot.dict at line 16: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.sbin.dovecot in /etc/apparmor.d/usr.sbin.dovecot at line 19: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14488]: AppArmor parser error for /etc/apparmor.d/sbin.syslog-ng in /etc/apparmor.d/sbin.syslog-ng at line 22: Could not open 'abstractions/mysql'

在删除<abstractions/mysql>相应文件中的#include 后,我可以重新启动 Apparmor。

答案2

我删除了 apparmor,并且与 snap 相关的许多其他东西也被卸载了......然而解决我的问题的只是两个简单的命令。

sudo dpkg-reconfigure mysql-server-5.7

这将为您提供一些可遵循的输出,但是在清除任何内容之前,如果您的问题是登录 mysql,请尝试下一个命令。

mysql -u root -p

-p[在命令中添加mysql -u root结束了我的悲伤我希望我没有清除 apparmor]

相关内容