[mysql] 記測試環境mariadb啟動失敗
阿新 • • 發佈:2021-12-08
背景
需要配置VM的硬體資訊,故重啟了VM,結果開機後mariadb啟動失敗:
# systemctl restart mariadb Authorization not available. Check if polkit service is running or see debug message for more information. Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
分析
按提示檢視服務status
執行systemctl status mariadb.service
檢視:
● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2021-12-08 09:38:23 CST; 2min 23s ago Process: 14882 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 14846 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 14881 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─14881 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─15070 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/log/mariadb/mariadb.pid --sock... Dec 08 09:38:21 vm systemd[1]: Starting MariaDB database server... Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Failed to get D-Bus connection: Permission denied Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Failed to get D-Bus connection: Permission denied Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done. Dec 08 09:38:21 vm mariadb-prepare-db-dir[14846]: If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir. Dec 08 09:38:21 vm mysqld_safe[14881]: 211208 09:38:21 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Dec 08 09:38:21 vm mysqld_safe[14881]: 211208 09:38:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Dec 08 09:38:23 vm systemd[1]: Started MariaDB database server.
檢視log檔案
大致是因為某個許可權問題,但上面看不出來,只能再檢視log檔案vi /var/log/mariadb/mariadb.log
,發現關鍵資訊:
... 211208 8:36:26 [ERROR] mysqld: Can't create/write to file '/var/run/mariadb/mariadb.pid' (Errcode: 13) 211208 8:36:26 [ERROR] Can't start server: can't create PID file: Permission denied 211208 08:36:26 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended ...
檢查許可權
以上說明檔案/var/run/mariadb/mariadb.pid無法被建立和寫入,經過一些檢查,發現其他使用者無許可權對/var/run目錄進行:
# cd /var
# ll
...
drwx------. 12 root root 256 Dec 8 09:43 run
...
一般來說,我們一般不會使用root去啟動mysql相關的服務,在部署的時候會獨立建立一些mysql的使用者和使用者組,用mysql這個使用者專職啟動mysql服務;
解決方法
#chmod -R 755 /var/run
# cd /var
#ll
...
drwxr-xr-x. 12 root root 256 Dec 8 09:43 run
...