ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Rocky Linux8] 5분 안에 손쉽게 MariaDB 설치 하기
    오픈소스 2023. 1. 2. 17:54

    1.  설치 환경 

    - OS : Rocky Linux release 8.6 (Green Obsidian)


    2. 설치

    dnf 명령어를 통해 간편하게 설치할 수 있습니다.

    $ sudo dnf install mariadb-server

    명령어를 실행하면 아래와 같이 필요한 패키지가 동시에 설치됩니다.

    y 를 누르고 Enter를 누르면 설치가 진행됩니다.

    $ sudo dnf install mariadb-server
    Last metadata expiration check: 3:18:46 ago on Mon 02 Jan 2023 11:31:06 AM KST.
    Dependencies resolved.
    ====================================================================================================================================================================================================================================
     Package                                                  Architecture                              Version                                                                      Repository                                    Size
    ====================================================================================================================================================================================================================================
    Installing:
     mariadb-server                                           x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                     16 M
    Installing dependencies:
     libaio                                                   x86_64                                    0.3.112-1.el8                                                                baseos                                        31 k
     mariadb                                                  x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                    6.0 M
     mariadb-common                                           x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                     63 k
     mariadb-connector-c                                      x86_64                                    3.1.11-2.el8_3                                                               appstream                                    199 k
     mariadb-errmsg                                           x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                    234 k
     perl-DBD-MySQL                                           x86_64                                    4.046-3.module+el8.6.0+904+ef468285                                          appstream                                    155 k
     perl-DBI                                                 x86_64                                    1.641-4.module+el8.6.0+891+677074cb                                          appstream                                    739 k
     perl-Math-BigInt                                         noarch                                    1:1.9998.11-7.el8                                                            baseos                                       194 k
     perl-Math-Complex                                        noarch                                    1.59-421.el8                                                                 baseos                                       108 k
    Installing weak dependencies:
     mariadb-backup                                           x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                    6.1 M
     mariadb-gssapi-server                                    x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                     51 k
     mariadb-server-utils                                     x86_64                                    3:10.3.35-1.module+el8.6.0+1005+cdf19c22                                     appstream                                    1.1 M
    Enabling module streams:
     mariadb                                                                                            10.3                                                                                                                           
     perl-DBD-MySQL                                                                                     4.046                                                                                                                          
     perl-DBI                                                                                           1.641                                                                                                                          
    
    Transaction Summary
    ====================================================================================================================================================================================================================================
    Install  13 Packages
    
    Total download size: 31 M
    Installed size: 156 M
    Is this ok [y/N]:

    3. 부팅시 시작 등록

    OS 시작시 자동적으로 시행 될 수 있도록 설정을 합니다.

    systemctl 명령어를 통해 mariadb를 활성화 합니다.

    $ sudo systemctl enable mariadb

    명령어를 실행하면 심볼릭 링크가 생성됩니다. 

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

    4. 서비스 시작

    서비스 시작을 하게 되면 기본 설정값으로 시작하게 됩니다.

    data 경로등 변경하기 위해서는 my.cnf 파일을 수정해야 합니다.

    $ sudo systemctl start mariadb

    5. 기본 설정

    1. ROOT 패스워드 설정

    - Set root password? [Y/n] y

    2. anonymous 사용자 삭제

    - Remove anonymous users? [Y/n] y

    3. ROOT 사용자 외부접속 삭제

    - Disallow root login remotely? [Y/n] y

    4. TEST DB 삭제

    - Remove test database and access to it? [Y/n] y

    5. privilege 테이블 reload

    - Reload privilege tables now? [Y/n] y

     

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

    6. 접속

    $suddo mysql -u root -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 18
    Server version: 10.3.35-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 명령어로 test 데이터베이스가 삭제된 것을 확인할 수 있습니다.

    MariaDB [(none)]> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.001 sec)

    USER 정보가 있는 테이블을 조회 해보면 root 사용자는 localhost에서 접근되게 설정되어 있습니다.

    외부에서 접근 불가능 하도록 설정되어 있습니다.

    MariaDB [(none)]> SELECT Host, User FROM mysql.user;
    +-----------+------+
    | Host      | User |
    +-----------+------+
    | 127.0.0.1 | root |
    | ::1       | root |
    | localhost | root |
    +-----------+------+
    3 rows in set (0.000 sec)

    [참고자료]

    https://docs.rockylinux.org/guides/database/database_mariadb-server/

Copyright 2020. bluewins All Rights Reserved.