Centos7

CentOS 7 MariaDB 錯誤“無法啟動 mariadb.service:未找到單元。”

  • March 14, 2017

我對 Linux 有點陌生,在 Windows 上的 Virtualbox 中測試各種 LAMP 設置。目前我有一個 Centos 7 VM,我正在嘗試在其上安裝 MariaDB。我在這裡遵循說明:http ://www.tecmint.com/install-lamp-in-centos-7

我跑了

# yum install mariadb-server mariadb

根據終端輸出安裝成功,但是當我執行時:

# systemctl start mariadb

我明白了

Failed to start mariadb.service: Unit not found.

我花了幾個小時在Google上搜尋這個,但似乎沒有什麼能解決我的問題,包括這個(在 mariadb-server 安裝後沒有 mysqld 或 mysql.server)和許多其他文章。

任何幫助是極大的讚賞。

更新 01

我解除安裝了 mariadb:

[root@centos7 admin]# yum remove mysql
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.0.30-1.el7.centos will be erased
--> Processing Dependency: MariaDB-client for package: MariaDB-server-10.0.30-1.el7.centos.x86_64
--> Running transaction check
---> Package MariaDB-server.x86_64 0:10.0.30-1.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
Package              Arch         Version                    Repository      Size
===================================================================================
Removing:
MariaDB-client       x86_64       10.0.30-1.el7.centos       @mariadb        49 M
Removing for dependencies:
MariaDB-server       x86_64       10.0.30-1.el7.centos       @mariadb       237 M

Transaction Summary
===================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 286 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Erasing    : MariaDB-server-10.0.30-1.el7.centos.x86_64                      1/2
 Erasing    : MariaDB-client-10.0.30-1.el7.centos.x86_64                      2/2
 Verifying  : MariaDB-client-10.0.30-1.el7.centos.x86_64                      1/2
 Verifying  : MariaDB-server-10.0.30-1.el7.centos.x86_64                      2/2

Removed:
 MariaDB-client.x86_64 0:10.0.30-1.el7.centos

Dependency Removed:
 MariaDB-server.x86_64 0:10.0.30-1.el7.centos

Complete!

yum clean allyum update

重新安裝mariadb:

# yum install mariadb-server mariadb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Webmin: download.webmin.com
* base: anorien.csc.warwick.ac.uk
* extras: centos.mirrors.nublue.co.uk
* updates: centos.serverspace.co.uk
Package mariadb-server is obsoleted by MariaDB-server, trying to install MariaDB-server-10.0.30-1.el7.centos.x86_64 instead
Package mariadb is obsoleted by MariaDB-client, trying to install MariaDB-client-10.0.30-1.el7.centos.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.0.30-1.el7.centos will be installed
---> Package MariaDB-server.x86_64 0:10.0.30-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
Package              Arch         Version                     Repository     Size
===================================================================================
Installing:
MariaDB-client       x86_64       10.0.30-1.el7.centos        mariadb        10 M
MariaDB-server       x86_64       10.0.30-1.el7.centos        mariadb        55 M

Transaction Summary
===================================================================================
Install  2 Packages

Total download size: 65 M
Installed size: 65 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): MariaDB-10.0.30-centos7-x86_64-client.rpm            |  10 MB  00:00:22
(2/2): MariaDB-10.0.30-centos7-x86_64-server.rpm            |  55 MB  00:01:15
-----------------------------------------------------------------------------------
Total                                                 876 kB/s |  65 MB  01:15
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : MariaDB-client-10.0.30-1.el7.centos.x86_64                      1/2
 Installing : MariaDB-server-10.0.30-1.el7.centos.x86_64                      2/2
libsemanage.map_file: Unable to open /usr/share/mysql/SELinux/mariadb.pp
(No such file or directory).
libsemanage.semanage_direct_install_file: Unable to read file /usr/share/mysql/SELinux/mariadb.pp
(No such file or directory).
/usr/sbin/semodule:  Failed on /usr/share/mysql/SELinux/mariadb.pp!
 Verifying  : MariaDB-client-10.0.30-1.el7.centos.x86_64                      1/2
 Verifying  : MariaDB-server-10.0.30-1.el7.centos.x86_64                      2/2

Installed:
 MariaDB-client.x86_64 0:10.0.30-1.el7.centos
 MariaDB-server.x86_64 0:10.0.30-1.el7.centos

Complete!

還是不行,什麼給?

# systemctl start mariadb.service
Failed to start mariadb.service: Unit not found.

更新 02

包版本和大小寫可能有些問題,我使用 mariaDB repos 而不是 centos 進行安裝,所以它選擇了 10.0.30 版本:

]# yum info mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* Webmin: download.webmin.com
* base: anorien.csc.warwick.ac.uk
* extras: centos.mirrors.nublue.co.uk
* updates: centos.serverspace.co.uk
Installed Packages
Name        : MariaDB-server
Arch        : x86_64
Version     : 10.0.30
Release     : 1.el7.centos
Size        : 237 M
Repo        : installed
From repo   : mariadb
Summary     : MariaDB: a very fast and robust SQL database server
URL         : http://mariadb.org
License     : GPLv2
Description : MariaDB: a very fast and robust SQL database server
           :
           : It is GPL v2 licensed, which means you can use the it free of charge
           : under the conditions of the GNU General Public License Version 2
           : (http://www.gnu.org/licenses/).
           :
           : MariaDB documentation can be found at https://mariadb.com/kb
           : MariaDB bug reports should be submitted through
           : https://jira.mariadb.org

Available Packages
Name        : mariadb-server
Arch        : x86_64
Epoch       : 1
Version     : 5.5.52
Release     : 1.el7
Size        : 11 M
Repo        : base/7/x86_64
Summary     : The MariaDB server and related files
URL         : http://mariadb.org
License     : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a multi-user, multi-threaded SQL database server. It is a
           : client/server implementation consisting of a server daemon (mysqld)
           : and many different client programs and libraries. This package
           : contains the MariaDB server and some accompanying files and
           : directories. MariaDB is a community developed branch of MySQL.

進一步的研究表明,在 MariaDB repo (v 10.0.30) 中呼叫服務mysql而不是 centos repo (v5.5) mariadb,所以這是一個混淆/問題。

參考問題:Centos7上的MariaDB,服務還是叫MySql

執行# service mysql start返回ERROR

錯誤檢查

grep: journalctl -xe|grep 'mysqld.*errno'

顯示:

/usr/bin/mysqld_safe_helper: Cannot change uid/gid (errno: 1)

關注這篇文章似乎已經解決了這個問題,這與 MariaDB 10.0.XX 版本和 SELinux 有關:

https://www.penguinprompt.com/mariadb-10-0-29-update-failure-selinux/

我能夠啟動mysql服務並配置它mysql_secure_installation

引用自:https://serverfault.com/questions/837914