1. AWS EC2에 MariaDB 설치하기

AWS의 RDS를 쓰는 것도 좋지만, EC2에 직접 설치해서 쓰는 경험으로 작업해본다.

#1. YUM 에서 설치가능한 패키지 확인하기

sudo yum list | grep mariadb
mariadb-connector-c.x86_64                                        3.1.13-1.amzn2023.0.3                       amazonlinux
mariadb-connector-c-config.noarch                                 3.1.13-1.amzn2023.0.3                       amazonlinux
mariadb-connector-c-devel.x86_64                                  3.1.13-1.amzn2023.0.3                       amazonlinux
mariadb-connector-c-test.x86_64                                   3.1.13-1.amzn2023.0.3                       amazonlinux
mariadb105.x86_64                                                 3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-backup.x86_64                                          3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-common.x86_64                                          3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-connect-engine.x86_64                                  3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-cracklib-password-check.x86_64                         3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-devel.x86_64                                           3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-errmsg.x86_64                                          3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-gssapi-server.x86_64                                   3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-oqgraph-engine.x86_64                                  3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-pam.x86_64                                             3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-rocksdb-engine.x86_64                                  3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-server.x86_64                                          3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-server-utils.x86_64                                    3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-sphinx-engine.x86_64                                   3:10.5.23-1.amzn2023.0.1                    amazonlinux
mariadb105-test.x86_64                                            3:10.5.23-1.amzn2023.0.1                    amazonlinux

설치된 버전이 꽤나 최신버전이므로 그냥 설치한다. repo 추가 스킵!

python library와 호환성이 맞지 않아 다시 설치한다.

설치 예제는 보기만하고 버전 맞춰서 까는 부분부터 따라하라

#2. 목록에 존재하는 mariadb105-server를 설치한다.

sudo yum install mariadb105-server
Last metadata expiration check: 0:36:56 ago on Mon Feb 19 00:40:05 2024.
Dependencies resolved.
============================================================================================================================================================================================================================
 Package                                                            Architecture                           Version                                                        Repository                                   Size
============================================================================================================================================================================================================================
Installing:
 mariadb105-server                                                  x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                  11 M
Installing dependencies:
 mariadb-connector-c                                                x86_64                                 3.1.13-1.amzn2023.0.3                                          amazonlinux                                 196 k
 mariadb-connector-c-config                                         noarch                                 3.1.13-1.amzn2023.0.3                                          amazonlinux                                 9.2 k
 mariadb105                                                         x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                 1.6 M
 mariadb105-common                                                  x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                  30 k
 mariadb105-errmsg                                                  x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                 214 k
 mysql-selinux                                                      noarch                                 1.0.4-2.amzn2023.0.3                                           amazonlinux                                  36 k
 perl-B                                                             x86_64                                 1.80-477.amzn2023.0.6                                          amazonlinux                                 179 k
 perl-DBD-MariaDB                                                   x86_64                                 1.22-1.amzn2023.0.4                                            amazonlinux                                 153 k
 perl-DBI                                                           x86_64                                 1.643-7.amzn2023.0.3                                           amazonlinux                                 700 k
 perl-Data-Dumper                                                   x86_64                                 2.174-460.amzn2023.0.2                                         amazonlinux                                  55 k
 perl-File-Copy                                                     noarch                                 2.34-477.amzn2023.0.6                                          amazonlinux                                  20 k
 perl-FileHandle                                                    noarch                                 2.03-477.amzn2023.0.6                                          amazonlinux                                  16 k
 perl-Math-BigInt                                                   noarch                                 1:1.9998.18-458.amzn2023.0.2                                   amazonlinux                                 189 k
 perl-Math-Complex                                                  noarch                                 1.59-477.amzn2023.0.6                                          amazonlinux                                  47 k
 perl-Sys-Hostname                                                  x86_64                                 1.23-477.amzn2023.0.6                                          amazonlinux                                  18 k
 perl-base                                                          noarch                                 2.27-477.amzn2023.0.6                                          amazonlinux                                  17 k
Installing weak dependencies:
 mariadb105-backup                                                  x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                 6.3 M
 mariadb105-cracklib-password-check                                 x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                  16 k
 mariadb105-gssapi-server                                           x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                  18 k
 mariadb105-server-utils                                            x86_64                                 3:10.5.23-1.amzn2023.0.1                                       amazonlinux                                 216 k

Transaction Summary
============================================================================================================================================================================================================================
Install  21 Packages

Total download size: 20 M
Installed size: 117 M
Is this ok [y/N]: y

#3. 설치된 MariaDB 확인

mysql --version
mysql  Ver 15.1 Distrib 10.5.23-MariaDB, for Linux (x86_64) using  EditLine wrapper

#4. 서비스 셋업

sudo systemctl start mariadb
sudo systemctl status mariadb
 mariadb.service - MariaDB 10.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; preset: disabled)
     Active: active (running) since Mon 2024-02-19 01:27:27 UTC; 22s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 27633 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS)
    Process: 27667 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
    Process: 27793 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS)
   Main PID: 27780 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 1114)
     Memory: 66.1M
        CPU: 469ms
     CGroup: /system.slice/mariadb.service
             └─27780 /usr/libexec/mariadbd --basedir=/usr

Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: The second is mysql@localhost, it has no password either, but
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: you need to be the system 'mysql' user to connect.
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: After connecting you can set the password, if you would need to be
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: able to connect as any of these users with a password and without sudo
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: See the MariaDB Knowledgebase at https://mariadb.com/kb
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: Please report any problems at https://mariadb.org/jira
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: The latest information about MariaDB is available at https://mariadb.org/.
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: Consider joining MariaDB's strong and vibrant community:
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal mariadb-prepare-db-dir[27738]: https://mariadb.org/get-involved/
Feb 19 01:27:27 ip-10-0-140-229.ap-northeast-2.compute.internal systemd[1]: Started mariadb.service - MariaDB 10.5 database server.

재부팅시 서비스 재시작을 위해서 서비스 enable

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

#5. 계정 및 비밀번호 설정

sudo mysqladmin -u root -p password
sudo mariadb-admin -u root -p password
Enter password:
New password:
Confirm new password:

#6. 접속 테스트

root 권한은 target host에서 직접 붙어서 localhost로만 이용하자. 보안 강화를 위해서.

mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.5.23-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.

유저 정보 확인

SELECT host, user, password FROM mysql.user;

Host tab에 있는 정보가 접근 가능 정보이다.

    -> ;
+-----------+-------------+-------------------------------------------+
| Host      | User        | Password                                  |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys |                                           |
| localhost | root        | *ㅁㄷㅁㄹㅁㄹㄷㅁㄹㄷㅁㄹㅁㄷㄹㄷㅁㄹㅁㄷㄹㅁㄷㄹㅁㄷㄹ  |
| localhost | mysql       | invalid                                   |
+-----------+-------------+-------------------------------------------+
3 rows in set (0.001 sec)

외부 접근권한을 주기 위해서 다음의 쿼리를 실행

grant all privileges on *.* to 'root'@'%' identified by '니 비밀번호';
MariaDB [(none)]> SELECT host, user, password FROM mysql.user
    -> ;
+-----------+-------------+-------------------------------------------+
| Host      | User        | Password                                  |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys |                                           |
| localhost | root        | *ㄴㄹㄷㄴㄹㄷㄴㄹㄴㄷㄹㄴㄷㄹㄴㄷㄹㄴㄷㄹㄴㅍㄴㄷㄹ     |
| localhost | mysql       | invalid                                   |
| %         | root        | *ㄹㄷㄴㄹㄴㄷㄹㅍㄴㄷㅍㄷㄴㄹㅋㄷㄹㄴㄷㄹㄴㄷㄹㄴㄷ     |
+-----------+-------------+-------------------------------------------+
4 rows in set (0.001 sec)

%이 모든 것이라는 의미.

flush privileges;

설정 반영 고고고 > flush privileges;

#7. 접속 해보자

AWS에서 Firewall을 설정하는 일은 필요 없었다. 기본적으로 Security group의 처리에 의존하고 AWS Linux에서는 처리하지 않는 것 같다.

  • YUM (YellowDog Updater, Modified, RPM 기반의 시스템을 위한 자동 업데이터 겸 패키지 설치/제거 도구)

#8. 버전을 바꿔서 다시 설치한다.

내 python 프로젝트와 호환성이 안맞아서 같은 버전의 mariadb를 설치하기 위해서
정확한 yum repository를 찾기 위해서 사이트를 방문한다.

https://mariadb.org/download/?distro=Red+Hat+EL+7+%28x86_64%29&ver=10.6&r_mirror=yongbok&t=repo-config

11.2 가 가장 stable 중에 최신이고 내 로칼과 같았다.

sudo vi /etc/yum.repos.d/MariaDB.repo

Web 에서 MariaDB.repo 파일에 속성 파일을 넣어본다.

# MariaDB 11.2 RedHatEnterpriseLinux repository list - created 2024-02-19 05:19 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.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.2/rhel/$releasever/$basearch
baseurl = https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/$releasever/$basearch
module_hotfixes = 1
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.xtom.jp/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

사이트에서 받은 원본 그대로 넣었다.

Errors during downloading metadata for repository 'mariadb':
  - Status code: 404 for https://mirror.mariadb.org/yum/11.2/rhel/2023.3.20240205/x86_64/repodata/repomd.xml (IP: 162.55.42.214)
Error: Failed to download metadata for repo 'mariadb': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Ignoring repositories: mariadb

에러가 발생했다.

# baseurl = https://rpm.mariadb.org/11.2/rhel/$releasever/$basearch
baseurl = https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/$releasever/$basearch

원본은 변수($releasever/$basearch)였다.

이렇게 돌려보면 에러가 표시된다. centos7, rhel 7 돌아가면서 해보다보니 repodata 폴더를 매칭하는게 중요한 것이 보였다.

Errors during downloading metadata for repository 'mariadb':
  - Status code: 404 for https://mirrors.xtom.jp/mariadb/yum/11.2/centos/2023.3.20240205/x86_64/repodata/repomd.xml (IP: 45.14.106.5)
Error: Failed to download metadata for repo 'mariadb': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Ignoring repositories: mariadb

#9. 실제 파일이 있나 보러 간다.

그래서 실제 타깃 링크로 이동했다.
https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/$releasever/$basearch

404 Not found.

변수를 제거해본다.
https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/

7server/x86_64/로 이동하면 보인다 repodata/

https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/7Server/x86_64/

#10. repo 파일을 변경한다.

sudo vi /etc/yum.repos.d/MariaDB.repo

경로 정보를 맞춰본다.

baseurl = https://rpm.mariadb.org/11.2/rhel/7Server/x86_64/

저 변수 부분을 내가 원하는 것으로 정확하게 조절해야 레포가 정확하게 매칭된다. 저 변수 처리에 대해서 공부할 시간이 없어서 넘어간다.

"/etc/yum.repos.d/MariaDB.repo" 12L, 569B                                                                                       12,0-1        All
# MariaDB 11.2 RedHatEnterpriseLinux repository list - created 2024-02-19 05:19 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.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.2/rhel/7Server/x86_64/
# baseurl = https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/$releasever/$basearch
module_hotfixes = 1
gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
# gpgkey = https://mirrors.xtom.jp/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

#11. 이젠 될 줄 알았다.

Complete!
[ec2-user@ip-10-0-140-229 .ssh]$ sudo yum install MariaDB-server
Last metadata expiration check: 0:00:10 ago on Mon Feb 19 05:49:20 2024.
Error:
 Problem: conflicting requests
  - nothing provides libcrypto.so.10()(64bit) needed by MariaDB-server-11.2.1-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(libcrypto.so.10)(64bit) needed by MariaDB-server-11.2.1-1.el7.centos.x86_64
  - nothing provides libssl.so.10()(64bit) needed by MariaDB-server-11.2.1-1.el7.centos.x86_64
  - nothing provides libssl.so.10(libssl.so.10)(64bit) needed by MariaDB-server-11.2.1-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(OPENSSL_1.0.2)(64bit) needed by MariaDB-server-11.2.1-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10()(64bit) needed by MariaDB-server-11.2.2-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(libcrypto.so.10)(64bit) needed by MariaDB-server-11.2.2-1.el7.centos.x86_64
  - nothing provides libssl.so.10()(64bit) needed by MariaDB-server-11.2.2-1.el7.centos.x86_64
  - nothing provides libssl.so.10(libssl.so.10)(64bit) needed by MariaDB-server-11.2.2-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(OPENSSL_1.0.2)(64bit) needed by MariaDB-server-11.2.2-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10()(64bit) needed by MariaDB-server-11.2.3-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(libcrypto.so.10)(64bit) needed by MariaDB-server-11.2.3-1.el7.centos.x86_64
  - nothing provides libssl.so.10()(64bit) needed by MariaDB-server-11.2.3-1.el7.centos.x86_64
  - nothing provides libssl.so.10(libssl.so.10)(64bit) needed by MariaDB-server-11.2.3-1.el7.centos.x86_64
  - nothing provides libcrypto.so.10(OPENSSL_1.0.2)(64bit) needed by MariaDB-server-11.2.3-1.el7.centos.x86_64
(try to add '--skip-broken' to skip uninstallable packages)

관련 파일의 호환성 문제가 발생했다.

버전 문제라는 것을 기반으로 여러가지 돌려봤는데 7Server를 9Server로 바꾸니까 되기 시작했다.

최종 파일이다. Red Hat Enterprise Linux여야 한다던데, 걔든 누구든 CentOS7 베이스를 부르는 듯하다. 그래서 CentOS9레포로 받으니 깔렸다.

확인하기 위해 RHEL9으로 바꿔본다.

# MariaDB 11.2 RedHatEnterpriseLinux repository list - created 2024-02-19 05:54 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.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.2/rhel/$releasever/$basearch
baseurl = https://mirrors.xtom.jp/mariadb/yum/11.2/rhel/9Server/x86_64
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.xtom.jp/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

둘 다 잘된다. CentOS9, RHEL9 둘다 잘깔림.

#11. 이제 잘 된다.

이제 다시 python pip install 을 수행해보자
AWS Linux 2 에서 pip install for MariaDB 수행할 때 버그 해결

이제 EC2에 그냥 디비를 깐다.

sudo yum install MariaDB-server

잘 깔린다.

전체 과정 블로그 /aws-ec2-mariadb-환경-설정

참고자료 링크

프리티어 생성 예제 블로그 링크