GNU/Linux >> Linux の 問題 >  >> Debian

Debian11にMariadb10をインストールして設定する方法

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

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

関連記事

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

前提条件

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

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

目次

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

1。システムを更新する

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

ターミナルで、これらを入力します。 -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.5.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-11-12 07:31:38 UTC; 32s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 32218 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 32219 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 32221 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_>
    Process: 32328 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 32330 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 32296 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 4626)
     Memory: 76.9M
        CPU: 703ms
     CGroup: /system.slice/mariadb.service
             └─32296 /usr/sbin/mariadbd

Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: mysql
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: performance_schema
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: Phase 6/7: Checking and upgrading tables
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: Processing databases
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: information_schema
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: performance_schema
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32335]: OK
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32945]: Checking for insecure root accounts.
Nov 12 07:31:40 ip-10-2-40-39 /etc/mysql/debian-start[32952]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

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
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]
Enabled successfully!
Reloading privilege tables..
 ... Success!


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

Change the 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!

4。オプション:ユーザー認証と特権の調整

MariaDB 10を実行しているDebianシステムでは、ルート MariaDBユーザーは、unix_socketを使用して認証するように設定されています パスワードではなく、デフォルトでプラグイン。これにより、多くの場合、セキュリティと使いやすさが向上しますが、外部プログラム(phpMyAdminなど)の管理者権限を許可する必要がある場合は、事態が複雑になる可能性もあります。

サーバーがルートを使用しているため ログローテーションやサーバーの起動と停止などのタスクを考慮し、ルートを変更しないことをお勧めします アカウントの認証の詳細。 /etc/mysql/debian.cnfのクレデンシャルを変更する 構成ファイルは最初は機能する可能性がありますが、パッケージの更新によってこれらの変更が上書きされる可能性があります。 ルートを変更する代わりに アカウントの場合、パッケージメンテナは、パスワードベースのアクセス用に別の管理者アカウントを作成することをお勧めします。

そのために、adminという新しいアカウントを作成します ルートと同じ機能を備えています アカウントですが、パスワード認証用に構成されています。これを行うには、ターミナルからMariaDBプロンプトを開き、 rootを使用して新しいユーザーを作成します 特権とパスワードベースのアクセス。好みに合わせてユーザー名とパスワードを変更します:

$ 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 56
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)]> GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'T*[email protected]^RDibAc%puz' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

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.5.12-MariaDB-0+deb11u1 |
+---------------------------+
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.5.12-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version		10.5.12-MariaDB-0+deb11u1
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/run/mysqld/mysqld.sock
Uptime:			1 hour 38 min 27 sec

Threads: 1  Questions: 490  Slow queries: 0  Opens: 171  Open tables: 28  Queries per second avg: 0.082

パスワード認証を使用して別の管理ユーザーを構成したため、次のように入力して同じ操作を実行できます。

mysqladmin -u admin -p version

これは、MariaDBが稼働中であり、ユーザーが正常に認証できることを意味します。

結論

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


Debian
  1. Debian11にRedis6.0をインストールして設定する方法

  2. Debian11にdockerをインストールして設定する方法

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

  1. Debian11にMariaDBをインストールして保護する方法

  2. Fedora35にMariadbをインストールして設定する方法

  3. Debian11にMongoDB5をインストールして設定する方法

  1. Debian9にMariaDBをインストールする方法

  2. Debian9にVNCをインストールして設定する方法

  3. Debian11にRedis6をインストールして設定する方法