CentOS 8.2에서 MariaDB 10.5.3 데이터베이스 서비스 구축하기

MariaDB 서버란?

MariaDB는 무료 오픈 소스 RDBMS(관계형 데이터베이스 관리 시스템)입니다. MySQL 데이터베이스의 포크 버전이며, MySQL 프로젝트의 일부 원본 개발자가 유지보수합니다. 전신과 마찬가지로 MariaDB는 주로 PHP 기반 서버의 백엔드 데이터베이스로 사용됩니다. 또한 많은 FOSS(자유 및 오픈 소스 소프트웨어) 유틸리티는 데이터 저장소로 MariaDB를 활용합니다.

MariaDB 서버는 확장성이 뛰어나 단독 실행 환경 또는 Galera 기반 MariaDB 클러스터 환경으로 사용할 수 있습니다.

MariaDB Server 10.5의 새로운 기능

MariaDB Server 10.5.3은 2020년 5월 12일에 출시되었으며, 여러 새로운 기능과 몇 가지 주요 변경 사항이 포함되어 있습니다. 이 글을 작성하는 시점에서 최신 버전입니다. 주요 변경 사항 및 기능은 다음과 같습니다.

  • 바이너리 및 심볼릭 링크 변경: 이전에 mysql로 시작하는 모든 바이너리 파일이 mariadb로 시작하게 되었으며, 기존 mysql 명령어에 대한 심볼릭 링크가 제공됩니다.
  • S3 스토리지 엔진: MariaDB 테이블을 Amazon S3 또는 S3 API를 구현하는 타사 퍼블릭 또는 프라이빗 클라우드에 아카이브할 수 있습니다.
  • S3 테이블 및 파티션 검색 가능: S3 테이블과 파티션 S3 테이블을 다른 서버에서 직접 검색하고 사용할 수 있습니다.
  • 세분화된 권한: SUPER 권한을 분할하여 사용자별로 더 세밀하게 권한을 조정할 수 있습니다.
  • 성능 향상: 바이너리 로깅 코드 속도 향상 및 최대 25%의 연결 속도 향상이 이루어졌습니다.

MariaDB 10.5.3의 전체 새로운 기능 목록은 MariaDB 공식 웹사이트에서 확인할 수 있습니다.

환경 사양

  • CPU: 3.4 GHz (2코어)
  • 메모리: 2 GB
  • 스토리지: 20 GB
  • 운영체제: CentOS 8.2
  • 호스트명: mariadb.example.com
  • IP 주소: 192.168.1.100/24

1단계: CentOS 8 패키지 업데이트

root 사용자로 SSH를 통해 서버에 접속합니다. 최신 Linux 패키지를 사용하는 것이 권장됩니다.

[root@couchdb ~]# hostnamectl set-hostname mariadb.example.com

[root@mariadb ~]# dnf update -y
Dependencies resolved.
Nothing to do.
Complete!

2단계: MariaDB Yum 저장소 설치

MariaDB Server 10.5.3은 최신 버전이므로 CentOS 8 기본 저장소에서 제공되지 않습니다. MariaDB 공식 Yum 저장소를 사용하여 설치합니다.

  1. Yum 저장소 설정 파일을 생성합니다.

    [root@mariadb ~]# cat > /etc/yum.repos.d/MariaDB.repo << 'EOF'
    # MariaDB 10.5 CentOS repository list
    # http://downloads.mariadb.org/mariadb/repositories/
    [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
    
  2. 캐시를 초기화하고 새로 빌드합니다.

    [root@mariadb ~]# dnf clean all
    44 files removed
    [root@mariadb ~]# dnf makecache
    ...
    Metadata cache created.
    

3단계: MariaDB Server 10.5 설치

  1. dnf 명령어를 사용하여 MariaDB 서버를 설치합니다.

    [root@mariadb ~]# dnf install -y MariaDB-server
    ...
    Complete!
    

    설치 중 네트워크 문제로 패키지 다운로드가 실패할 경우, 수동으로 RPM 파일을 다운로드 후 설치할 수 있습니다.

    [root@mariadb tdops]# dnf -y install galera-4-26.4.6-1.el8.x86_64.rpm MariaDB-server-10.5.8-1.el8.x86_64.rpm MariaDB-client-10.5.8-1.el8.x86_64.rpm
    ...
    Complete!
    
  2. MariaDB 서비스를 활성화하고 시작합니다.

    [root@mariadb ~]# systemctl enable --now mariadb.service
    Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
    
  3. 서비스 상태와 리스닝 포트를 확인합니다.

    [root@mariadb ~]# systemctl status mariadb.service
    ● mariadb.service - MariaDB 10.5.3 database server
       Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
       Active: active (running) since Fri 2020-12-26 22:00:00 KST; 10s ago
         Docs: man:mysqld(8)
               https://mariadb.com/kb/en/library/systemd/
     Main PID: 12345 (mysqld)
       Status: "Taking your SQL requests now..."
        Tasks: 11 (limit: 5916)
       Memory: 75.8M
       CGroup: /system.slice/mariadb.service
               └─12345 /usr/sbin/mysqld
    
    [root@mariadb ~]# ss -tlnp | grep 3306
    LISTEN   0        80                     *:3306               *:*        users:(("mariadbd",pid=12345,fd=21))
    

4단계: MariaDB 데이터베이스 사용자 암호 설정

  • Linux root 사용자는 MariaDB root 사용자로 별도 암호 없이 접속 가능합니다.
  • Linux mysql 사용자는 MariaDB mysql 사용자로 별도 암호 없이 접속 가능합니다.

다른 Linux 사용자가 로그인할 수 있도록 데이터베이스 사용자에게 암호를 설정해야 합니다.

  1. mariadb 명령어를 사용하여 서버에 연결합니다.

    [root@mariadb ~]# mariadb -u root
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 3
    Server version: 10.5.8-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)]> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    4 rows in set (0.001 sec)
    
  2. rootmysql 사용자에 대해 강력한 암호를 설정합니다.

    MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'StrongPassword123!';
    Query OK, 0 rows affected (0.001 sec)
    
    MariaDB [(none)]> ALTER USER 'mysql'@'localhost' IDENTIFIED BY 'StrongPassword123!';
    Query OK, 0 rows affected (0.001 sec)
    
  3. 권한 테이블을 다시 로드합니다.

    MariaDB [(none)]> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.001 sec)
    
  4. MariaDB 쉘을 종료합니다.

    MariaDB [(none)]> EXIT
    Bye
    

5단계: 데이터베이스 보안 구성

테스트 데이터베이스 제거 및 루트 사용자의 원격 로그인 제한을 위해 mariadb-secure-installation 스크립트를 실행합니다.

[root@mariadb ~]# 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): # 이전에 설정한 암호 입력
OK, successfully used password, moving on...

Switch to unix_socket authentication [Y/n] n
 ... skipping.

Change the root password? [Y/n] n
 ... skipping.

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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!

CentOS 8.2에 MariaDB Server 10.5를 성공적으로 설치하고 관리자 사용자 설정 및 데이터베이스 보안 구성을 완료했습니다.

태그: MariaDB CentOS 8 데이터베이스 설치 Yum 저장소 서버 보안

6월 16일 17:55에 게시됨