天天看點

CentOS 8 | CentOS 7系統安裝MariaDB 10.5詳細過程

在本文中将簡單介紹如何在CentOS 8 | CentOS 7系統中安裝MariaDB 10.5。

MariaDB是具有巨大社群支援的MySQL關系資料庫管理系統的社群分支。MariaDB 10.5的穩定版本已于2020年6月釋出,并且将受支援直到2025年6月。

如果您要從另一個版本(如10.4)進行更新,請檢視官方更新指南,并注意兩個版本的MariaDB之間的差異。這對于已使用自定義變量調整資料庫并確定交易效率的生産用例非常重要。

MariaDB團隊為維護的存儲庫提供了針對各種Linux版本的最新軟體包。對于CentOS,我們将使用YUM存儲庫。下面簡單說說CentOS 8 | CentOS 7系統安裝MariaDB 10.5詳細過程。

步驟1:添加MariaDB YUM存儲庫

運作以下指令以将MariaDB提供的存儲庫添加到CentOS伺服器。

将存儲庫添加到CentOS 8系統:

sudo tee /etc/yum.repos.d/mariadb.repo<[mariadb]

name = MariaDB

baseurl =

http://yum.mariadb.org/10.5/centos8-amd64

module_hotfixes=1

gpgkey=

https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

EOF

将存儲庫添加到CentOS 7系統:

http://yum.mariadb.org/10.5/centos7-amd64

通過更新緩存來确認存儲庫正在工作。

sudo yum makecache

列出可用的存儲庫:

$ sudo yum repolist

repo id repo name

AppStream CentOS-8 - AppStream

BaseOS CentOS-8 - Base

extras CentOS-8 - Extras

mariadb MariaDB

步驟2:CentOS 8 | CentOS 7系統安裝MariaDB 10.5

添加存儲庫并确認其正常運作後,可以繼續在CentOS 8 / CentOS 7 Linux伺服器上安裝MariaDB 10.5。

sudo yum install MariaDB-server MariaDB-client

運作以上指令可以檢查要安裝的軟體包清單,并同意是否可以安裝。

.....

Installing weak dependencies:

perl-IO-Socket-IP noarch 0.39-5.el8 AppStream 47 k

perl-IO-Socket-SSL noarch 2.066-4.el8 AppStream 297 k

perl-Mozilla-CA noarch 20160104-7.el8 AppStream 15 k

Enabling module streams:

perl 5.26

perl-DBI 1.641

================================================================================================================================================================

Install 54 Packages

Total download size: 67 M

Installed size: 298 M

Is this ok [y/N]: y

在出現提示時,還需同意導入GPG密鑰。

Importing GPG key 0x1BB943DB:

Userid : "MariaDB Package Signing Key

[email protected]

"

Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB

From :

RPM軟體包詳細資訊如下:

$ rpm -qi MariaDB-server

Name : MariaDB-server

Version : 10.5.4

Release : 1.el8

Architecture: x86_64

Install Date: Sun 28 Jun 2020 07:21:20 PM CEST

Group : Applications/Databases

Size : 132807324

License : GPLv2

Signature : DSA/SHA1, Tue 23 Jun 2020 11:03:04 PM CEST, Key ID cbcb082a1bb943db

Source RPM : MariaDB-server-10.5.4-1.el8.src.rpm

Build Date : Tue 23 Jun 2020 06:59:51 PM CEST

Build Host : rhel8-amd64

Relocations : (not relocatable)

Vendor : MariaDB Foundation

URL :

http://mariadb.org

....

步驟3:在CentOS 8 | CentOS 7系統中啟動MariaDB服務

CentOS 8和CentOS 7均使用Systemd初始化系統。我們可以使用systemctl指令啟動服務,如下指令。

sudo systemctl start mariadb

要使伺服器重新啟動時能夠啟動服務,請使用以下指令:

$ sudo systemctl enable mariadb

Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

使用systemctl status指令檢查服務狀态:

$ systemctl status mariadb

● mariadb.service - MariaDB 10.5.4 database server

Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)

Drop-In: /etc/systemd/system/mariadb.service.d

└─migrated-from-my.cnf-settings.conf           

Active: active (running) since Sun 2020-06-28 19:34:56 CEST; 1min 35s ago

Docs: man:mariadbd(8)
       https://mariadb.com/kb/en/library/systemd/           

Main PID: 4328 (mariadbd)

Status: "Taking your SQL requests now..."

Tasks: 9 (limit: 24392)           

Memory: 67.7M

CGroup: /system.slice/mariadb.service

└─4328 /usr/sbin/mariadbd
           

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Plugin 'FEEDBACK' is disabled.

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: Buffer pool(s) load completed at 200628 19:34:56

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Server socket created on IP: '::'.

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Reading of all Master_info entries succeeded

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Added new Master_info '' to hash table

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] /usr/sbin/mariadbd: ready for connections.

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: Version: '10.5.4-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server

Jun 28 19:34:56 centos.computingforgeeks.com systemd[1]: Started MariaDB 10.5.4 database server.

...

如果您需要網絡中的其他系統通路資料庫伺服器,請允許端口3306:

sudo firewall-cmd --add-service=mysql --permanent

sudo firewall-cmd --reload

為了使遠端連接配接正常工作,該服務應偵聽IP位址,而不是localhost環回接口。

bind-address=172.21.200.12

bind-address=0.0.0.0

步驟4:在CentOS 8 | CentOS 7系統上保護MariaDB資料庫的安全

MariaDB提供了用于強化資料庫伺服器的腳本。該腳本可提高安全,主要包括:

設定root密碼

删除匿名資料庫使用者

禁止以root使用者身份登入遠端資料庫

删除測試資料庫

要啟動資料庫強化過程,請運作以下指令。

$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
           

In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody

can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y

Enabled successfully!

Reloading privilege tables..

... Success!

Change the root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

  1. This is intended only for testing, and to make the installation
  2. a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

By default, MariaDB comes with a database named 'test' that anyone can

  1. This is also intended only for testing, and should be removed
  2. moving into a production environment.

Remove test database and access to it? [Y/n] y

  • Dropping test database...

    ... Success!

  • Removing privileges on test database...

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

最後以root使用者身份(不輸入密碼)測試登入名:

$ mysql -u root

這時會出現拒絕通路錯誤:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

現在以root使用者身份嘗試并提供密碼:

$ mysql -u root -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 24

Server version: 10.5.4-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> SELECT VERSION();
VERSION()
10.5.4-MariaDB

1 row in set (0.001 sec)

MariaDB [(none)]> QUIT

Bye

至此,MariaDB 10.5服務現在可以使用了。當然,可能需要的唯一其他設定是根據您的應用程式要求和用例将其調整為最佳性能。本文就不贅述了。

以上安裝過程僅供參考,文章來源惠主機www.idccoupon.com ,有任何問題歡迎交流填了。