centos7 安裝mysql 資料庫路徑改變後selinux問題導致不能啟動mysqld
想請教是我少修改什麼地方還是設定方式有問什麼問題
環境:
3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
CentOS Linux release 7.7.1908 (Core)
安裝方法
curl -L -O https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -i mysql80-community-release-el7-3.noarch.rpm
sudo yum install mysql-community-server
mv /var/lib/mysql /db/mysql
chcon -R -t mysqld_db_t /db/mysql
ls -ZL /db | grep "my"
#check selinux
vim /etc/my.cnf
#changepath
systemctl start mysqld
錯誤後再做ls -Z發現回變回default
[root@DB01 db]# ll -Z
drwxrwx---. mysql mysql unconfined_u:object_r:default_t:s0 mysql
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 mysql80-community-release-el7-3.noarch.rpm
[root@DB01 db]#
[root@DB01 db]# chcon -R -t mysqld_db_t /db/mysql
[root@DB01 db]# ll -Z
drwxrwx---. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 mysql
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 mysql80-community-release-el7-3.noarch.rpm
[root@DB01 db]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@DB01 db]# ll -Z
drwxrwx---. mysql mysql unconfined_u:object_r:default_t:s0 mysql
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 mysql80-community-release-el7-3.noarch.rpm
[root@DB01 db]#
已測試關閉selinux後能正常啟動mysqld
你的最後一行 ll -Z 明顯可以看到: mysql 啟動之後, 他把你原本設定的 mysqld_db_t 又改回 default_t 了...這是因為你沒有用 semanage 去定義的關係, chcon 只能做臨時性的變更, 檔案被重置之後就恢復預設的定義值; 只有定義在 semanage 裡面才會是永久的:
semanage fcontext -a -t mysqld_db_t "/db/mysql(/.*)?"
restorecon -Rv /db/mysql
fixfiles restore