GNU/Linux >> Linux の 問題 >  >> Ubuntu

Ubuntu20.04にMariadb10をインストールして構成する方法

MariaDBは、OracleによるMySQLの買収に対応して、2009年にMySQLのソフトウェアフォークとして開発されました。 MariaDBは、GNU GeneralPublicLicenseの下で無料のオープンソースソフトウェアを維持する予定です。これはほとんどのクラウド製品の一部であり、ほとんどのLinuxディストリビューションのデフォルトです。

このガイドでは、Debian11にMariaDBをインストールして設定する方法を学習します。

関連記事

  • Mysql8をRockyLinux/Centos8にインストールする方法
  • Ubuntu20.04にmysql8をインストールしてセットアップする方法
  • Debian11にMariadb10をインストールして設定する方法

前提条件

フォローするには、次のことを確認してください。

  • 最新のUbuntu20.04サーバー
  • サーバーまたはSudoアクセス権を持つユーザーへのrootアクセス
  • サーバーからインターネットへのアクセス

目次

  1. システムの更新
  2. Mariadbのインストール
  3. Mariadbの構成
  4. オプション:ユーザー認証と特権の調整
  5. MariaDBのテスト

1。システムを更新する

先に進む前に、Ubuntuサーバーが最新であることを確認しましょう。最初にリポジトリを更新してから、システムアップグレードを実行して、インストールされているすべてのパッケージが最新であることを確認します。

ターミナルで、これらを入力します。 -y apt upgradeのオプション アップグレードを受け入れるためにシステムが一時停止しないようにすることです。

$ sudo apt update
$ sudo apt upgrade -y

2。 mariadbのインストール

Mariadbは、debianのデフォルトのリポジトリにあります。次のコマンドを使用して、データベースサーバーをインストールします。

sudo apt install -y mariadb-server

Mariadbはデフォルトで起動されます。

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.3.31 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-11-14 16:48:17 EAT; 43s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 50510 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 4631)
     Memory: 63.8M
     CGroup: /system.slice/mariadb.service
             └─50510 /usr/sbin/mysqld

Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Processing databases
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: information_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: mysql
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: performance_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Phase 6/7: Checking and upgrading tables
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Processing databases
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: information_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: performance_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: OK

3。 MariaDBの構成

新しいMariaDBインストールの場合、次のステップは、含まれているセキュリティスクリプトを実行することです。このスクリプトは、安全性の低いデフォルトオプションの一部を変更します。これを使用して、リモートのルートをブロックします ログインして、未使用のデータベースユーザーを削除します。

セキュリティスクリプトを実行します:

sudo mysql_secure_installation

これにより、MariaDBインストールのセキュリティオプションにいくつかの変更を加えることができる一連のプロンプトが表示されます。最初のプロンプトでは、現在のデータベースのルートを入力するように求められます パスワード。まだ設定していないので、ENTERを押します 「なし」を示します。

次のプロンプトでは、データベースのルートを設定するかどうかを尋ねられます パスワード。 Nと入力します 次に、ENTERを押します 。 Debianでは、ルート MariaDBのアカウントは自動システムメンテナンスと密接に関連しているため、そのアカウントに構成されている認証方法を変更しないでください。そうすることで、管理者アカウントへのアクセスを削除することにより、パッケージの更新によってデータベースシステムが破壊される可能性があります。後で、ソケット認証がユースケースに適していない場合に、パスワードアクセス用に追加の管理者アカウントをオプションで設定する方法について説明します。

そこから、Yを押すことができます 次に、ENTER 後続のすべての質問のデフォルトを受け入れます。これにより、一部の匿名ユーザーとテストデータベースが削除され、リモートのルートが無効になります。 ログインし、これらの新しいルールをロードして、MariaDBが行った変更をすぐに尊重するようにします。

これは私のサーバーの出力です

$ 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!

5。 MariaDBのテスト

mariadbがすべてセットアップされて実行されているので、接続を受け入れることができることを確認する必要があります。

テストするには、rootユーザーでmariadbに接続します– mysql -h 127.0.0.1 -u root -p

出力:

$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.5.12-MariaDB-0+deb11u1 Debian 11

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)]>

mariadbのバージョンを確認してください:

MariaDB [(none)]> SELECT VERSION();
+----------------------------------+
| VERSION()                        |
+----------------------------------+
| 10.3.31-MariaDB-0ubuntu0.20.04.1 |
+----------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

追加のチェックについては、mysqladminを使用してデータベースに接続してみてください。 ツール。管理コマンドを実行できるクライアントです。たとえば、このコマンドは、 rootとしてMariaDBに接続するように指示します。 Unixソケットを使用してバージョンを返します:

sudo mysqladmin version

次のような出力が表示されます:

$ sudo mysqladmin version
mysqladmin  Ver 9.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version		10.3.31-MariaDB-0ubuntu0.20.04.1
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			13 min 56 sec

Threads: 6  Questions: 488  Slow queries: 0  Opens: 175  Flush tables: 1  Open tables: 31  Queries per second avg: 0.583

結論

このガイドでは、SQLサーバーとして機能するようにMariaDBをインストールしました。インストールプロセス中に、サーバーも保護しました。


Ubuntu
  1. Ubuntu18.04にRedisをインストールして構成する方法

  2. Ubuntu18.04にRedmineをインストールして設定する方法

  3. Ubuntu18.04にSambaをインストールして設定する方法

  1. Ubuntu20.04にRedisをインストールして構成する方法

  2. Ubuntu20.04にJenkinsをインストールして構成する方法

  3. Ubuntu16.04にAskbotをインストールして構成する方法

  1. Ubuntu14.04にMongoDBをインストールして構成する方法

  2. Ubuntu16.04にSolr6をインストールして構成する方法

  3. Ubuntu16.04にGitLabをインストールして構成する方法