5. 5
http://neoclova.co.kr/
1. About MariaDB
1.1 MariaDB 개요
MariaDB는 전세계적으로 가장 널리 사용되고 있는 Open Source Database System인 MySQL 과의 호
환성을 가지면서 추가적인 기능들을 개발하여 배포/판매하고 있는 데이터베이스이다. 2009년 initial r
elease를 했다.
1.2 MariaDB as a R-DBMS
관계형 데이터베이스는 데이터를 하나의 커다란 저장 공간에 저장하지 않고 서로 별개의 테이블에 나
누어서 저장을 하는 시스템이다. 이를 통해 처리 속도와 유연성이 확보된다. SQL은 “Structured Query
language”의 약자이며, SQL은 ANSI/ISO 표준에서 정의한 데이터베이스 접속을 위한 가장 일반적인
표준 언어이다. 이 매뉴얼에서 언급하는 “SQL 표준”은 각 시점에서 발표된 SQL표준을 의미하는 것이
다.
1.3 Open Source Database System
MariaDB 데이터베이스는 GPL(GNU Public License)을 준수하는 오픈 소스 데이터베이스이며, GPL을
준수해서 사용하는 모든 사용자에게 무료로 배포되고 있다.
http://mariadb.org/
http://mariadb.com/
6. 6
http://neoclova.co.kr/
2. 설치
2.1 설치 기본 정보
항목 값
OS version Ubuntu 20.04.4 LTS
OS user maria ( 초기 root OS계정 : neoclova )
MariaDB version MariaDB 10.7.3
Base directory /usr/local/mariadb
Data directory /maria_data
Log directory /maria_log
2.2 설치 준비
2.2.1 SSH 접속 설정
openssh-server 설치 (설치가 완료된 후, SSH서비스 자동시작. 상태확인)
neoclova@ubuntu:~$ sudo apt update
neoclova@ubuntu:~$ sudo apt install openssh-server
neoclova@ubuntu:~$ sudo systemctl status ssh
UFW 방화벽 시스템에서 SSH 포트 open
neoclova@ubuntu:~$ sudo ufw allow ssh
XShell등 외부에서 ssh 접속 테스트
ssh 계정명@ip주소 형태
2.2.2 OS 계정 생성
7. 7
http://neoclova.co.kr/
neoclova@ubuntu:~$ sudo groupadd dba
neoclova@ubuntu:~$ sudo useradd maria -g dba -m
neoclova@ubuntu:~$ cat /etc/group | grep dba
dba:x:1001:
neoclova@ubuntu:~$ cat /etc/passwd | grep maria
maria:x:1001:1001::/home/maria:/bin/sh
2.2.3 디렉토리 생성
neoclova@ubuntu:/$ sudo mkdir /maria_data /maria_log
2.2.4 MariaDB Download
https://mariadb.org/download/
https://archive.mariadb.org/
neoclova@ubuntu:/$ cd /usr/local
neoclova@ubuntu:/usr/local$ sudo wget https://mirror.yongbok.net/mariadb/mariadb-10.7.3/
bintar-linux-systemd-x86_64/mariadb-10.7.3-linux-systemd-x86_64.tar.gz
neoclova@ubuntu:/usr/local$ ls -lah mariadb-10.7.3-linux-systemd-x86_64.tar.gz
-rw-r--r-- 1 root root 331M Feb 11 15:48 mariadb-10.7.3-linux-systemd-x86_64.tar.gz
2.3 MariaDB 설치
2.3.1 MariaDB 엔진 설치 (tar 압축 해제 / 심볼릭 링크 / chown 설정)
neoclova@ubuntu:/usr/local$ sudo tar -zxf mariadb-10.7.3-linux-systemd-x86_64.tar.gz
neoclova@ubuntu:/usr/local$ sudo ln -s mariadb-10.7.3-linux-systemd-x86_64 mariadb
neoclova@ubuntu:/usr/local$ sudo chown -R maria.dba /maria_data
neoclova@ubuntu:/usr/local$ sudo chown -R maria.dba /maria_log
neoclova@ubuntu:/usr/local$ sudo chown -R maria.dba maria*
neoclova@ubuntu:/usr/local$ ls -lah maria*
lrwxrwxrwx 1 maria dba 35 Apr 5 20:19 mariadb -> mariadb-10.7.3-linux-systemd-x86_64
-rw-r--r-- 1 maria dba 331M Feb 11 15:48 mariadb-10.7.3-linux-systemd-x86_64.tar.gz
mariadb-10.7.3-linux-systemd-x86_64:
total 192K
8. 8
http://neoclova.co.kr/
drwxrwxr-x 11 maria dba 4.0K Feb 11 15:47 .
drwxr-xr-x 11 root root 4.0K Apr 5 20:19 ..
drwxr-xr-x 2 maria dba 4.0K Jan 18 09:31 bin
-rw-r--r-- 1 maria dba 18K Feb 10 12:33 COPYING
-rw-r--r-- 1 maria dba 2.1K Feb 10 12:33 CREDITS
drwxrwxr-x 3 maria dba 4.0K Feb 10 13:11 include
-rw-r--r-- 1 maria dba 8.6K Feb 10 12:33 INSTALL-BINARY
drwxr-xr-x 5 maria dba 4.0K Jan 18 09:31 lib
drwxrwxr-x 5 maria dba 4.0K Feb 10 13:12 man
drwxrwxr-x 9 maria dba 4.0K Feb 10 13:12 mysql-test
-rw-r--r-- 1 maria dba 2.7K Feb 10 12:33 README.md
-rw-r--r-- 1 maria dba 20K Feb 10 12:33 README-wsrep
drwxrwxr-x 2 maria dba 4.0K Feb 10 13:12 scripts
drwxrwxr-x 31 maria dba 4.0K Feb 10 13:12 share
drwxrwxr-x 4 maria dba 4.0K Feb 10 13:12 sql-bench
drwxrwxr-x 4 maria dba 4.0K Feb 10 13:12 support-files
-rw-r--r-- 1 maria dba 85K Feb 10 12:33 THIRDPARTY
2.3.2 mysql.server 파일 수정
neoclova@ubuntu:/usr/local$ sudo vi /usr/local/mariadb/support-files/mysql.server
basedir=/usr/local/mariadb
datadir=/maria_data
2.3.3 my.cnf 설정
neoclova@ubuntu:/usr/local$ sudo vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = maria
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mariadb
datadir = /maria_data
#Log file setting
log-error = /maria_log/mysql.err
slow_query_log = 1
slow_query_log_file = /maria_log/mysql-slow-query.log
long_query_time = 3
#Time-out setting
wait_timeout = 28800
interactive_timeout = 600
10. 10
http://neoclova.co.kr/
2.3.4 systemd 설정 (service 등록)
neoclova@ubuntu:/usr/local$ sudo vi /etc/systemd/system/mariadb.service
neoclova@ubuntu:~$ sudo systemctl daemon-reload
[Unit]
Description=mariadb
After=network.target
[Service]
Type=forking
User=maria
Group=dba
LimitNOFILE=infinity
ExecStart=/usr/local/mariadb/support-files/mysql.server start
ExecStop=/usr/local/mariadb/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
2.3.5 사용자 권한 부여
neoclova@ubuntu:/usr/local$ sudo vi /etc/sudoers
maria ALL=NOPASSWD:/usr/bin/systemctl start mariadb.service, /usr/bin/systemctl stop mariadb.service, /usr/b
in/systemctl start mariadb.service, /usr/bin/systemctl restart mariadb.service
2.3.6 libaio 패키지 설치
neoclova@ubuntu:/usr/local$ sudo apt-get install libaio1
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libaio1
0 upgraded, 1 newly installed, 0 to remove and 83 not upgraded.
Need to get 7,184 B of archives.
After this operation, 35.8 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libaio1 amd64 0.3.112-5 [7,184 B]
Fetched 7,184 B in 1s (5,970 B/s)
Selecting previously unselected package libaio1:amd64.
(Reading database ... 158489 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.112-5_amd64.deb ...
Unpacking libaio1:amd64 (0.3.112-5) ...
Setting up libaio1:amd64 (0.3.112-5) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
11. 11
http://neoclova.co.kr/
2.3.7 MariaDB install DB (initialize)
neoclova@ubuntu:/usr/local$ cd /usr/local/mariadb
neoclova@ubuntu:/usr/local/mariadb$ sudo ./scripts/mariadb-install-db --user=maria --def
aults-file=/etc/my.cnf --basedir=/usr/local/mariadb
Installing MariaDB/MySQL system tables in '/maria_data' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is maria@localhost, it has no password either, but
you need to be the system 'maria' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb
You can start the MariaDB daemon with:
cd '/usr/local/mariadb' ; /usr/local/mariadb/bin/mysqld_safe --datadir='/maria_data'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb/mysql-test' ; perl mysql-test-run.pl
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
2.4 MariaDB 시작 / 접속 / 종료
2.4.1 MariaDB 시작
neoclova@ubuntu:~$ sudo systemctl start mariadb
neoclova@ubuntu:~$ sudo systemctl status mariadb
● mariadb.service - mariadb
Loaded: loaded (/etc/systemd/system/mariadb.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2022-04-05 21:12:43 PDT; 1min 52s ago
Process: 4613 ExecStart=/usr/local/mariadb/support-files/mysql.server start (code=exited, status=0/SU>
Main PID: 4777 (mysqld_safe)
Tasks: 11 (limit: 4588)
Memory: 115.6M
CGroup: /system.slice/mariadb.service
├─4777 /bin/sh /usr/local/mariadb/bin/mysqld_safe --datadir=/maria_data --pid-file=/maria_da>
└─5021 /usr/local/mariadb/bin/mariadbd --basedir=/usr/local/mariadb --datadir=/maria_data -->
12. 12
http://neoclova.co.kr/
Apr 05 21:12:42 ubuntu systemd[1]: Starting mariadb...
Apr 05 21:12:42 ubuntu mysql.server[4613]: Starting MariaDB
Apr 05 21:12:42 ubuntu mysql.server[4613]: .
Apr 05 21:12:42 ubuntu mysql.server[4777]: 220405 21:12:42 mysqld_safe Logging to '/maria_log/mysql.err'.
Apr 05 21:12:42 ubuntu mysql.server[4777]: 220405 21:12:42 mysqld_safe Starting mariadbd daemon with data>
Apr 05 21:12:43 ubuntu mysql.server[4613]: *
Apr 05 21:12:43 ubuntu systemd[1]: Started mariadb.
2.4.2 Secure installation
neoclova@ubuntu:/$ cd /usr/local/mariadb/bin/
neoclova@ubuntu:/usr/local/mariadb/bin$ sudo ./mariadb-secure-installation --basedir=/us
r/local/mariadb
● 에러 발생시 해결 후 재시도
/usr/local/mariadb/bin/mariadb: error while loading shared libraries: libncurses
.so.5: cannot open shared object file: No such file or directory
sudo find / -name "libncurses.so.*"
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.2 /usr/lib/x86_64-linux-gnu/l
ibtinfo.so.5
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6.2 /usr/lib/x86_64-linux-gnu
/libncurses.so.5
print: /usr/local/mariadb/bin/my_print_defaults
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'.
13. 13
http://neoclova.co.kr/
Switch to unix_socket authentication [Y/n] y
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...
14. 14
http://neoclova.co.kr/
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
2.4.3 Bash Shell 설정 / MariaDB 접속
neoclova@ubuntu:/usr/local/mariadb$ sudo passwd maria
New password:
Retype new password:
passwd: password updated successfully
$
쉘변경
$ chsh -s /bin/bash
계정 재로그인
neoclova@ubuntu:~$ su – maria
maria@ubuntu:~$
bash shell 설정
maria@ubuntu:~$ vi .bash_profile
maria@ubuntu:~$ . .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mariadb/bin
maria@ubuntu:~$ sudo systemctl status mariadb
MariaDB [(none)]> status
--------------
mysql Ver 15.1 Distrib 10.7.3-MariaDB, for linux-systemd (x86_64) using readline 5.1
Connection id: 14
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.7.3-MariaDB-log MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
15. 15
http://neoclova.co.kr/
Server characterset: utf8mb3
Db characterset: utf8mb3
Client characterset: utf8mb3
Conn. characterset: utf8mb3
UNIX socket: /tmp/mysql.sock
Uptime: 2 hours 10 min 8 sec
Threads: 1 Questions: 26 Slow queries: 0 Opens: 21 Open tables: 14 Queries per seco
nd avg: 0.003
----------------------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> select user, host, authentication_string from mysql.user;
+-------------+-----------+-------------------------------------------+
| User | Host | authentication_string |
+-------------+-----------+-------------------------------------------+
| mariadb.sys | localhost | |
| root | localhost | *4557CF5E70B04EE24CCCF4E13EFCB290BE17E57E |
| maria | localhost | invalid |
+-------------+-----------+-------------------------------------------+
3 rows in set (0.003 sec)
MariaDB [(none)]> exit
Bye
2.5 추가 설정
2.5.1 Linux limit 설정
https://mariadb.com/kb/en/configuring-linux-for-mariadb/
neoclova@ubuntu:~$ sudo vi /etc/security/limits.conf
maria soft nofile 65536
maria hard nofile 65536