如何在CentOS 8/RHEL 8上安装MariaDB 10.4
时间:2020-02-23 14:40:56 来源:igfitidea点击:
如何在CentOS 8/RHEL 8 Linux机器上安装MariaDB 10.4? MariaDB是从MySQL关系数据库管理系统派生的多用户,多线程SQL数据库服务器。它被设计为快速,可靠的,具有更高级的功能,适用于激进的数据库操作。
我们不会讨论MariaDB 10.4数据库系统的酷功能,我们可以查看发行说明以了解详细的功能集。这只是在CentOS 8/RHEL 8 Linux机器上拥有可正常运行的MariaDB 10.4数据库服务器所需的仅有步骤。
在CentOS 8/RHEL 8上安装MariaDB 10.4
这些是在CentOS 8/RHEL 8 Linux服务器上安装MariaDB 10.4时需要经过的理想步骤。
更新系统
如果服务器上的生产中没有运行任何关键服务,请在开始在CentOS 8/RHEL 8上安装MariaDB 10.4之前更新系统。
sudo dnf -y upgrade
将MariaDB 10.4存储库添加到CentOS 8/RHEL 8
现在,我们需要为我们的CPU体系结构添加MariaDB yum存储库。本教程将介绍为x86_64 CPU计算机添加存储库。
CentOS 8:
sudo tee /etc/yum.repos.d/MariaDB.repo<<EOF [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos8-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 EOF
RHEL 8:
sudo tee /etc/yum.repos.d/MariaDB.repo<<EOF [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/rhel8-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 EOF
将MariaDB 10.4存储库安装到CentOS 8/RHEL 8
添加Yum存储库后,我们可以立即将MariaDB 10.4存储库安装到CentOS 8/RHEL 8.
CentOS 8:
sudo dnf install boost-program-options sudo dnf install MariaDB-server MariaDB-client --disablerepo=AppStream sudo systemctl enable --now mariadb
RHEL 8:
sudo dnf install boost-program-options sudo dnf install MariaDB-server MariaDB-client --disablerepo=rhel-8-for-x86_64-appstream-rpms sudo systemctl enable --now mariadb
出现提示时,按y接受安装:
MariaDB 186 kB/s | 489 kB 00:02 Last metadata expiration check: 0:00:01 ago on Sat 04 Jan 2017 08:37:41 PM EAT. Dependencies resolved. ======================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================== Installing: MariaDB-client x86_64 10.4.11-1.el8 mariadb 12 M MariaDB-server x86_64 10.4.11-1.el8 mariadb 26 M Installing dependencies: MariaDB-common x86_64 10.4.11-1.el8 mariadb 87 k galera-4 x86_64 26.4.3-1.rhel8.0.el8 mariadb 13 M Transaction Summary ======================================================================================================================================================== Install 4 Packages Total download size: 51 M Installed size: 196 M Is this ok [y/N]: y
可以使用以下查询有关已安装软件包的更多详细信息:
$rpm -qi MariaDB-server Name : MariaDB-server Version : 10.4.11 Release : 1.el8 Architecture: x86_64 Install Date: Sat 04 Jan 2017 08:38:56 PM EAT Group : Applications/Databases Size : 129705129 License : GPLv2 Signature : DSA/SHA1, Wed 11 Dec 2019 02:08:56 AM EAT, Key ID cbcb082a1bb943db Source RPM : MariaDB-server-10.4.11-1.el8.src.rpm Build Date : Tue 10 Dec 2019 06:19:51 PM EAT Build Host : rhel8-amd64 Relocations : (not relocatable) Vendor : MariaDB Foundation URL : http://mariadb.org Summary : MariaDB: a very fast and robust SQL database server 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
启动并启用MariaDB服务
sudo systemctl enable --now mariadb
状态应显示为正在运行:
$systemctl status mariadb ● mariadb.service - MariaDB 10.4.11 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 Sat 2017-01-04 20:40:50 EAT; 15s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 31317 (mysqld) Status: "Taking your SQL requests now..." Tasks: 30 (limit: 11512) Memory: 73.4M CGroup: /system.slice/mariadb.service └─31317 /usr/sbin/mysqld Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] InnoDB: 10.4.11 started; log sequence number 60972; transaction id 21 Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] InnoDB: Buffer pool(s) load completed at 200104 20:40:50 Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] Plugin 'FEEDBACK' is disabled. Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] Server socket created on IP: '::'. Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] Reading of all Master_info entries succeeded Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] Added new Master_info '' to hash table Jan 04 20:40:50 centos8.novalocal mysqld[31317]: 2017-01-04 20:40:50 0 [Note] /usr/sbin/mysqld: ready for connections. Jan 04 20:40:50 centos8.novalocal mysqld[31317]: Version: '10.4.11-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server Jan 04 20:40:50 centos8.novalocal systemd[1]: Started MariaDB 10.4.11 database server.
保护MariaDB数据库服务器
现在,在CentOS 8/RHEL 8上安装了MariaDB 10.4,可以通过运行mysql_secure_installation对其进行保护。
$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 you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! 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 ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
测试对数据库shell的访问:
$mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 19 Server version: 10.4.11-MariaDB MariaDB Server Copyright (c) 2000, 2016, 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.4.11-MariaDB | +-----------------+ 1 row in set (0.000 sec) MariaDB [(none)]> QUIT Bye