CentOS 7-SELINUX 关闭-权限正常-无法从 /home 运行 mysql-错误 13-但在其他地方可以运行

CentOS 7-SELINUX 关闭-权限正常-无法从 /home 运行 mysql-错误 13-但在其他地方可以运行

运行 CentOS 7 并禁用 SE Linux;

# sestatus
SELinux status:                 disabled

mysql 配置文件;

[mysqld]
datadir=/home/mysql-data
socket=/home/mysql-data/mysql.sock

datadir 的权限;

 home]# ls -la
 drwxr-xr-x   3 root  root   24 Aug 10 12:22 .
 dr-xr-xr-x. 18 root  root  256 Aug 10 12:34 ..
 drwxr-xr-x   5 mysql mysql 207 Aug 10 13:32 mysql-data

在 mysql-data 中;

mysql-data]# ls -la

total 110636
drwxr-xr-x 5 mysql mysql      207 Aug 10 13:32 .
drwxr-xr-x 3 root  root        24 Aug 10 12:22 ..
-rw-rw---- 1 mysql mysql    16384 Aug 10 13:32 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Aug 10 13:32 aria_log_control
drwx------ 2 mysql mysql       20 Aug  9 09:22 db1
-rw-rw---- 1 mysql mysql 12582912 Aug 10 13:32 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Aug 10 13:32 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Aug  8 20:33 ib_logfile1
-rw-rw---- 1 mysql mysql        0 Aug  8 20:39 multi-master.info
 drwx--x--x 2 mysql mysql     4096 Aug  8 20:33 mysql
 drwx------ 2 mysql mysql       20 Aug  8 20:33 performance_schema
-rw-rw---- 1 mysql mysql    17890 Aug  8 21:24 server_audit.log

运行启动命令时出错;

#service mysql start
Starting mysql (via systemctl):  Job for mariadb.service failed because 
the control process exited with error code. See "systemctl status 
mariadb.service" and "journalctl -xe" for details.
                                                       [FAILED]

错误;

Starting MariaDB database server...
Aug 10 13:46:47 xxxxx mysqld: 2017-08-10 13:46:47 140520315873536 [Note] 
/usr/sbin/mysqld (mysqld 10.1.25-MariaDB) starting as process 5998 ...
Aug 10 13:46:47 xxxxx mysqld: 2017-08-10 13:46:47 140520315873536 
[Warning] Can't create test file /home/mysql-data/xxxxx.lower-test
**Aug 10 13:46:47 xxxxx mysqld: #007/usr/sbin/mysqld: Can't change dir to 
'/home/mysql-data/' (Errcode: 13 "Permission denied")**
Aug 10 13:46:47 xxxxx mysqld: 2017-08-10 13:46:47 140520315873536 [ERROR] 
Aborting
Aug 10 13:46:47 xxxxx systemd: mariadb.service: main process exited, 
code=exited, status=1/FAILURE
Aug 10 13:46:47 xxxxx systemd: Failed to start MariaDB database server.
Aug 10 13:46:47 xxxxx systemd: Unit mariadb.service entered failed state.
Aug 10 13:46:47 xxxxx systemd: mariadb.service failed.

每当我将其从 /home/mysql-data 移至 /data/mysql-data 之类的位置(包括套接字)时,都不会出现任何问题!由于某种原因,只有 /home 会出现此问题!

即使以 'mysql' 身份执行 sudo , /home/mysql-data 也是可写的;

sudo -u mysql touch /home/mysql-data/xxxx.lower-test

total 110636
drwxr-xr-x 5 mysql mysql      219 Aug 10 14:04 .
drwxr-xr-x 3 root  root        24 Aug 10 12:22 ..
-rw-rw---- 1 mysql mysql    16384 Aug 10 13:32 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Aug 10 13:32 aria_log_control
drwx------ 2 mysql mysql       20 Aug  9 09:22 db1
-rw-rw---- 1 mysql mysql 12582912 Aug 10 13:32 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Aug 10 13:32 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Aug  8 20:33 ib_logfile1
-rw-rw---- 1 mysql mysql        0 Aug  8 20:39 multi-master.info
drwx--x--x 2 mysql mysql     4096 Aug  8 20:33 mysql
drwx------ 2 mysql mysql       20 Aug  8 20:33 performance_schema
-rw-rw---- 1 mysql mysql    17890 Aug  8 21:24 server_audit.log
-rw-r--r-- 1 mysql mysql        0 Aug 10 14:04 test

我所看到的与 /home 的唯一区别是它有自己的挂载点;

df -mh
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   50G  2.6G   48G   6% /
devtmpfs              32G     0   32G   0% /dev
tmpfs                 32G     0   32G   0% /dev/shm
tmpfs                 32G  8.4M   32G   1% /run
tmpfs                 32G     0   32G   0% /sys/fs/cgroup
/dev/sda1           1014M  184M  831M  19% /boot
/dev/mapper/cl-home  180G  142M  180G   1% /home
tmpfs                6.3G     0  6.3G   0% /run/user/0

有人见过这个吗?

更新/编辑: 当我将 /etc/fstab 文件从

/dev/mapper/cl-home  180G  142M  180G   1% /home

/dev/mapper/cl-home  180G  142M  180G   1% /data

MySQL 运行良好。(编辑 my.cnf 以指向 /data/mysql-data 后)

Mysql 或 Centos 不喜欢 /home 的什么地方?再次,selinux 被禁用,并且在挂载时从 /home 更改为 /data 时我没有更改任何权限或结构。

以前从来没见过。

答案1

这是因为 systemctl 的 mariadb.service 有一行写着 ProtectHome=true。

相关内容