[MariaDB] Rocky Linux 9.4에서 MariaDB 설치하기

설치 환경

별도의 서버 환경에서의 설치를 진행하기 위해 iwinv의 가상서버를 신청하여 진행하였습니다.

하드웨어 : CPU - 1 vCore, MEM - 1 GB, DISK - 25 GB )

운영체제 : Rocky Linux 9.4

MariaDB 버전 : MariaDB-Server 11.4

사용계정 :  gh.lee ( 일반사용자 계정으로 관리 권한을 부여하여 관리 명령을 실행할 수 있도록 설정된 계정 )

MariaDB Server Repositories 설정

1) MariaDB Download 페이지에 접속한다.

2) MariaDB Server Repositories 탭으로 이동 후 OS와 MariaDB Server version, Mirror 서버 위치를 선택해준다.
    이 때, Rocky Linux는 OS의 분류에 없으므로, CentOS 또는 RHEL에서 버전에 맞게 선택하면 된다.

3) 선택 후 하단에 나오는 쉘 스크립트를 ssh 터미널을 통하여 파일에 저장한다.

4) repository 파일 생성(수정) 후 저장

$ sudo vim /etc/yum.repos.d/MariaDB.repo

설정 내용

더보기

# MariaDB 11.4 CentOS repository list - created 2024-08-28 13:32 UTC
https://mariadb.org/download/
[mariadb]
name = MariaDB
# rphttp://m.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/11.4/centos/$releasever/$basearch
baseurl = https://download.nus.edu.sg/mirror/mariadb/yum/11.4/centos/$releasever/$basearch
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://download.nus.edu.sg/mirror/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

MariaDB 설치

1) 다음의 스크립트를 수행하여 설치한다.

$ sudo dnf install -y MariaDB-server MariaDB-client

수행 로그

더보기

<< -- 중략 -- >>

MariaDB                                                                                              121 kB/s | 524 kB     00:04    
Last metadata expiration check: 0:00:02 ago on Wed Aug 28 22:49:21 2024.
Dependencies resolved.
===================================================================================================================================== 
Package                                Architecture            Version                             Repository                  Size
=====================================================================================================================================
Installing:
 MariaDB-client                         x86_64                  11.4.3-1.el9                        mariadb                    9.5 M
 MariaDB-server                         x86_64                  11.4.3-1.el9                        mariadb                     19 M
Installing dependencies:
 MariaDB-common                         x86_64                  11.4.3-1.el9                        mariadb                     88 k
 MariaDB-shared                         x86_64                  11.4.3-1.el9                        mariadb                    133 k
 boost-program-options                  x86_64                  1.75.0-8.el9                        appstream                  106 k
 galera-4                               x86_64                  26.4.19-1.el9                       mariadb                    1.4 M
 lsof                                   x86_64                  4.94.0-3.el9                        baseos                     238 k
 perl-DBI                               x86_64                  1.643-9.el9                         appstream                  700 k
 socat                                  x86_64                  1.7.4.1-5.el9_4.2                   appstream                  299 k
Installing weak dependencies:
 MariaDB-client-compat                  noarch                  11.4.3-1.el9                        mariadb                     11 k
 MariaDB-server-compat                  noarch                  11.4.3-1.el9                        mariadb                    9.0 k

Transaction Summary
=====================================================================================================================================
Install  11 Packages

<< -- 중략 -- >>

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/


  Verifying        : MariaDB-client-11.4.3-1.el9.x86_64                                                                         1/11 
  Verifying        : MariaDB-client-compat-11.4.3-1.el9.noarch                                                                  2/11 
  Verifying        : MariaDB-common-11.4.3-1.el9.x86_64                                                                         3/11 
  Verifying        : MariaDB-server-11.4.3-1.el9.x86_64                                                                         4/11 
  Verifying        : MariaDB-server-compat-11.4.3-1.el9.noarch                                                                  5/11 
  Verifying        : MariaDB-shared-11.4.3-1.el9.x86_64                                                                         6/11 
  Verifying        : galera-4-26.4.19-1.el9.x86_64                                                                              7/11 
  Verifying        : lsof-4.94.0-3.el9.x86_64                                                                                   8/11 
  Verifying        : perl-DBI-1.643-9.el9.x86_64                                                                                9/11 
  Verifying        : socat-1.7.4.1-5.el9_4.2.x86_64                                                                            10/11 
  Verifying        : boost-program-options-1.75.0-8.el9.x86_64                                                                 11/11 

Installed:
  MariaDB-client-11.4.3-1.el9.x86_64            MariaDB-client-compat-11.4.3-1.el9.noarch     MariaDB-common-11.4.3-1.el9.x86_64    
  MariaDB-server-11.4.3-1.el9.x86_64            MariaDB-server-compat-11.4.3-1.el9.noarch     MariaDB-shared-11.4.3-1.el9.x86_64    
  boost-program-options-1.75.0-8.el9.x86_64     galera-4-26.4.19-1.el9.x86_64                 lsof-4.94.0-3.el9.x86_64              
  perl-DBI-1.643-9.el9.x86_64                   socat-1.7.4.1-5.el9_4.2.x86_64               

Complete!

2) 설치가 완료되고 실제로 설정한 버전이 설치되었는 지 다음의 명령어를 입력하여 확인한다.

 

$ sudo dnf info MariaDB-server
$ sudo dnf info MariaDB-server
Last metadata expiration check: 0:05:49 ago on Wed Aug 28 22:49:21 2024.
Installed Packages
Name         : MariaDB-server
Version      : 11.4.3
Release      : 1.el9
Architecture : x86_64
Size         : 135 M
Source       : MariaDB-server-11.4.3-1.el9.src.rpm
Repository   : @System
From repo    : mariadb
Summary      : MariaDB database server binaries
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

MariaDB 실행 및 자동 실행 설정

1) 초기화에 앞서 설치한 MariaDB 서비스를 실행시켜준다.

$ sudo systemctl start mariadb

2) 서비스가 정상적으로 실행이 되었는 지 확인한다.

$ sudo systemctl status mariadb

아래와 같이 "Active: active (running)"으로 나오면 정상적으로 실행이 된 것이다.

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 11.4.3 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; preset: disabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Wed 2024-08-28 23:10:19 KST; 9s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 48386 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 48387 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0>    Process: 48408 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 48396 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 5533)
     Memory: 135.6M
        CPU: 976ms
     CGroup: /system.slice/mariadb.service
             └─48396 /usr/sbin/mariadbd

Aug 28 23:10:17 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:17 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 28 23:10:17 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:17 0 [Note] Plugin 'wsrep-provider' is disabled.
Aug 28 23:10:17 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:17 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buf>Aug 28 23:10:17 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:17 0 [Note] InnoDB: Buffer pool(s) load completed at 240828 23:10:17
Aug 28 23:10:19 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:19 0 [Note] Server socket created on IP: '0.0.0.0'.
Aug 28 23:10:19 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:19 0 [Note] Server socket created on IP: '::'.
Aug 28 23:10:19 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:19 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
Aug 28 23:10:19 gwanghwa.net mariadbd[48396]: 2024-08-28 23:10:19 0 [Note] /usr/sbin/mariadbd: ready for connections.
Aug 28 23:10:19 gwanghwa.net mariadbd[48396]: Version: '11.4.3-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Se>Aug 28 23:10:19 gwanghwa.net systemd[1]: Started MariaDB 11.4.3 database server.

3) 부팅 시 자동 시작되도록 설정하지 않는다면, 매번 부팅 시 수동으로 실행 시켜줘야하는 번거로움이 있다.
    이를 해소하기 위해 아래의 명령어를 통하여 자동 실행이 가능하도록 설정해준다.

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

MariaDB 초기화

$ sudo mariadb-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): # 현재 설정된 root 비밀번호가 없으므로, Enter를 누른다.
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] n # 소켓 인증을 통한 패스워드 인증 사용 여부 설정 "n"
 ... skipping.

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

Change the root password? [Y/n] # root 비밀번호 변경 여부 "Y"
New password:                   # 비밀번호 입력
Re-enter new password:          # 비밀번호 2차 입력
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 # anonymous 계정 삭제 여부 "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] n # 원격에서 root 계정 비활성화 여부 "Y" (여기선 학습 목적이므로 "n")
 ... skipping.

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] n # test Database 삭제 여부 "Y" (여기선 학습 목적이므로 "n")
 ... skipping.

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!

MariaDB 로컬 접속

$ mysql -u root -p # "enter" 입력
Enter password: # 앞에서 설정한 root 계정 비밀번호 입력
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 11.4.3-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)]>

MariaDB 버전 확인 하기

MariaDB [(none)]> select version();
+----------------+
| version()      |
+----------------+
| 11.4.3-MariaDB |
+----------------+
1 row in set (0.000 sec)

- 위와 같이 "select version();" 쿼리를 통하여 설치한 버전의 정보를 확인할 수 있다.