오늘도 나의 기억을 위해 끄적거린다.
Maria DB나 Mysql DB나 크게 설치면에서는 차이가 없다.
실제 내가 사용하는 범위 내에서는 더더욱 차이가 없다. 하지만 웹개발자(php) 의 말로는 조금 차이가 있다고 하는데 그부분이 어느 부분인지는 모르겠다.
일단 설치 방법에 대해서 끄적거린다.
환경
- OS : Centos 7.7.1908 (3.10.0-1062.9.1.el7.x86_64)
- System : VM ware
- CPU : 8core
- RAM : 8192MB
maria DB는 아래 사이트에서 해당 버전 및 OS별로 다운로드 할 수 있다.
https://downloads.mariadb.org/
본 설치 환경의 설치 파일을 아래와 같다.
CMD ) wget -O mariadb-10.3.22-linux-systemd-x86_64.tar.gz https://downloads.mariadb.org/interstitial/mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.liquidtelecom.com/
[root@TEST-DB src]# wget -O mariadb-10.3.22-linux-systemd-x86_64.tar.gz https://downloads.mariadb.org/interstitial/mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.liquidtelecom.com/
--2020-01-29 09:47:43-- https://downloads.mariadb.org/interstitial/mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.liquidtelecom.com/
Resolving downloads.mariadb.org (downloads.mariadb.org)... 116.203.207.31, 2a01:4f8:c2c:b04e::1
Connecting to downloads.mariadb.org (downloads.mariadb.org)|116.203.207.31|:443... connected.
HTTP request sent, awaiting response... 302 FOUND
Location: https://downloads.mariadb.org/f/mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.liquidtelecom.com/?serve [following]
--2020-01-29 09:47:44-- https://downloads.mariadb.org/f/mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.liquidtelecom.com/?serve
Reusing existing connection to downloads.mariadb.org:443.
HTTP request sent, awaiting response... 302 FOUND
Location: http://mariadb.mirror.liquidtelecom.com//mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz [following]
--2020-01-29 09:47:44-- http://mariadb.mirror.liquidtelecom.com//mariadb-10.3.22/bintar-linux-systemd-x86_64/mariadb-10.3.22-linux-systemd-x86_64.tar.gz
Resolving mariadb.mirror.liquidtelecom.com (mariadb.mirror.liquidtelecom.com)... 197.155.77.1, 2c0f:fe40:8001:10::1
Connecting to mariadb.mirror.liquidtelecom.com (mariadb.mirror.liquidtelecom.com)|197.155.77.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 930888246 (888M) [application/x-gzip]
Saving to: ‘mariadb-10.3.22-linux-systemd-x86_64.tar.gz’
100%[===========================================================>] 930,888,246 3.70MB/s in 3m 49s
2020-01-29 09:51:34 (3.87 MB/s) - ‘mariadb-10.3.22-linux-systemd-x86_64.tar.gz’ saved [930888246/930888246]
wget 명령어 사용시 "-O"옵션을 사용하지 않을 경우 "index.html"파일로 다운로드 되며, index.html 파일로 되어 있어도 mv명령어를 통해 파일명을 변경하면 된다.
[root@TEST-DB src]# ls -al
합계 1211404
drwxr-xr-x. 2 root root 4096 1월 29 10:25 .
drwxr-xr-x. 12 root root 4096 1월 8 16:30 ..
-rw-r--r-- 1 root root 930888246 1월 28 04:05 mariadb-10.3.22-linux-systemd-x86_64.tar.gz
다운로드 된 압축 파일을 해제 한다.
[root@TEST-DB src]# tar xvfz mariadb-10.3.22-linux-systemd-x86_64.tar.gz -C /usr/local/
압축 해제를 확인하고 소프트 링크를 설정한다.
[root@TEST-DB src]# cd /usr/local/
[root@TEST-DB local]# ls -al
합계 52
drwxr-xr-x. 13 root root 4096 1월 29 10:40 .
drwxr-xr-x. 13 root root 4096 1월 8 16:30 ..
drwxr-xr-x. 2 root root 4096 4월 11 2018 bin
drwxr-xr-x. 2 root root 4096 4월 11 2018 etc
drwxr-xr-x. 2 root root 4096 4월 11 2018 games
drwxr-xr-x. 2 root root 4096 4월 11 2018 include
drwxr-xr-x. 2 root root 4096 4월 11 2018 lib
drwxr-xr-x. 2 root root 4096 4월 11 2018 lib64
drwxr-xr-x. 2 root root 4096 4월 11 2018 libexec
drwxrwxr-x 13 root root 4096 1월 28 04:02 mariadb-10.3.22-linux-systemd-x86_64
drwxr-xr-x. 2 root root 4096 4월 11 2018 sbin
drwxr-xr-x. 5 root root 4096 1월 8 16:30 share
drwxr-xr-x. 2 root root 4096 1월 29 10:39 src
[root@TEST-DB local]#
[root@TEST-DB local]# ln -s mariadb-10.3.22-linux-systemd-x86_64 mysql
[root@TEST-DB local]# ls -al
합계 52
drwxr-xr-x. 13 root root 4096 1월 29 10:43 .
drwxr-xr-x. 13 root root 4096 1월 8 16:30 ..
drwxr-xr-x. 2 root root 4096 4월 11 2018 bin
drwxr-xr-x. 2 root root 4096 4월 11 2018 etc
drwxr-xr-x. 2 root root 4096 4월 11 2018 games
drwxr-xr-x. 2 root root 4096 4월 11 2018 include
drwxr-xr-x. 2 root root 4096 4월 11 2018 lib
drwxr-xr-x. 2 root root 4096 4월 11 2018 lib64
drwxr-xr-x. 2 root root 4096 4월 11 2018 libexec
drwxrwxr-x 13 root root 4096 1월 28 04:02 mariadb-10.3.22-linux-systemd-x86_64
lrwxrwxrwx 1 root root 36 1월 29 10:43 mysql -> mariadb-10.3.22-linux-systemd-x86_64
drwxr-xr-x. 2 root root 4096 4월 11 2018 sbin
drwxr-xr-x. 5 root root 4096 1월 8 16:30 share
drwxr-xr-x. 2 root root 4096 1월 29 10:39 src
my.cnf설정을 한다. (여기서는 config 파일의 위치만 변경하고 추후 다른 페이지를 통해 config내 필드에 대해 설명하고자 한다. )
## 주석과 공백 라인을 제거하고 필요한 부분만 출력!!!
[root@TEST-DB bin]# cat /usr/local/mysql/my.cnf | grep -Ev "^#|^$" |sed -e "s/\[/\n\[/g"
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
datadir=/db/data
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8
collation-server = utf8_general_ci
performance_schema
innodb_file_per_table = 1
innodb_purge_threads = 1
event_scheduler
innodb_read_io_threads = 8
innodb_file_format = barracuda
thread_handling = pool-of-threads
thread_pool_size = 8
thread_pool_max_threads = 1024
thread_pool_idle_timeout = 10
symbolic-links=0
back_log = 50
max_connections = 5000
max_connect_errors = 100
table_open_cache = 2048
max_allowed_packet = 200M
binlog_cache_size = 1M
max_heap_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = INNODB
thread_stack = 240K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
binlog_format=mixed
slow_query_log
long_query_time = 2
server-id = 1
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
[mysqldump]
quick
max_allowed_packet = 700M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
log-error=/db/log/mariadb.log
pid-file=/db/log/mariadb.pid
!includedir /etc/my.cnf.d
** /etc/my.cnf가 있는데 필자는 한곳에서 관리를 하고자 /etc/my.cnf는 삭제 또는 이동하여 Mysql이 설치 되어 있는 /usr/local/mysql 하위에 위치하도록 하였고 /etc/my.cnf는 소프트 링크를 걸어 설정하였다.
[root@TEST-DB local]# mv /etc/my.cnf /usr/local/mysql/
[root@TEST-DB local]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf
[root@TEST-DB local]# cd mysql
[root@TEST-DB mysql]# cksum my.cnf /etc/my.cnf
2714336979 20144 my.cnf
2714336979 20144 /etc/my.cnf
[root@TEST-DB mysql]# ls -al /etc/my.cnf
lrwxrwxrwx 1 root root 23 1월 29 11:11 /etc/my.cnf -> /usr/local/mysql/my.cnf
[root@TEST-DB mysql]#
mysql유저를 생성하고 퍼미션을 변경한다. ( 필요하지 않을 경우 변경하지 않아도 된다.)
[root@TEST-DB local]# groupadd -g 501 mysql
[root@TEST-DB local]# useradd -g501 -u501 -d /home/mysql/ -m -s /bin/bash -c "Mysql USER" mysql
[root@TEST-DB local]# passwd mysql
mysql 사용자의 비밀 번호 변경 중
새 암호:
새 암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[root@TEST-DB local]# cd /usr/local
##그룹 퍼미션만 앞서 만든 계정으로 변경
[root@TEST-DB local]# chgrp -R mysql mariadb-10.3.22-linux-systemd-x86_64
MariaDB를 시작하기에 앞서 DATABASE 생성하고 기본적인 설정을 한다.
basedir, datadir 등 사용하고자 하는 환경에 맞게 변경할 수 있다.
실제 DATABASE와 LOG가 저장 되는 위치는 필자는 아래와 같이 변경하였다.
[root@TEST-DB ~]# mkdir -p /db/data /db/log
[root@TEST-DB ~]# cd /db
[root@TEST-DB db]# ls -al
합계 32
drwxr-xr-x 5 root root 4096 1월 29 11:27 .
dr-xr-xr-x. 20 root root 4096 1월 10 16:14 ..
drwxr-xr-x 2 root root 4096 1월 29 11:10 data
drwxr-xr-x 2 root root 4096 1월 29 11:27 log
[root@TEST-DB db]# chown -R mysql.mysql data log
[root@TEST-DB db]# ls -al
합계 32
drwxr-xr-x 5 root root 4096 1월 29 11:27 .
dr-xr-xr-x. 20 root root 4096 1월 10 16:14 ..
drwxr-xr-x 2 mysql mysql 4096 1월 29 11:10 data
drwxr-xr-x 2 mysql mysql 4096 1월 29 11:27 log
[root@TEST-DB data]# cd /usr/local/mysql
[root@TEST-DB mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/db/data --defaults-file=/usr/local/mysql/my.cnf --user=mysql
Installing MariaDB/MySQL system tables in '/db/data' ...
2020-01-29 11:43:24 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2020-01-29 11:43:24 0 [Warning] You need to use --log-bin to make --binlog-format work.
2020-01-29 11:43:24 0 [Warning] The parameter innodb_file_format is deprecated and has no effect. It may be removed in future releases. See https://mariadb.com/kb/en/library/xtradbinnodb-file-format/
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/local/mysql/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql/bin/mysqladmin' -u root -h localhost password 'new-password'
Alternatively you can run:
'/usr/local/mysql/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr/local/mysql' ; /usr/local/mysql/bin/mysqld_safe --datadir='/db/data'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql/mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
[root@TEST-DB mysql]# ls -al /db/data
합계 862252
drwxr-xr-x 5 mysql mysql 4096 1월 29 11:43 .
drwxr-xr-x 5 root root 4096 1월 29 11:27 ..
-rw-rw---- 1 mysql mysql 16384 1월 29 11:43 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 1월 29 11:43 aria_log_control
-rw-rw---- 1 mysql mysql 972 1월 29 11:43 ib_buffer_pool
-rw-rw---- 1 mysql mysql 268435456 1월 29 11:43 ib_logfile0
-rw-rw---- 1 mysql mysql 268435456 1월 29 11:43 ib_logfile1
-rw-rw---- 1 mysql mysql 268435456 1월 29 11:43 ib_logfile2
-rw-rw---- 1 mysql mysql 77594624 1월 29 11:43 ibdata1
drwx------ 2 mysql mysql 4096 1월 29 11:43 mysql
drwx------ 2 mysql mysql 4096 1월 29 11:43 performance_schema
drwx------ 2 mysql mysql 4096 1월 29 11:43 test
[root@TEST-DB mysql]#
DB를 실행하고 제공해주는 "mysql_secure_installation" tool을 이용하여 root password와 기본설정을 진행한다.
[root@TEST-DB ~]# cd /usr/local/mysql/bin
[root@TEST-DB bin]# ./mysqld_safe --user=mysql &
[1] 9833
[root@TEST-DB bin]# 200130 09:09:42 mysqld_safe Logging to '/db/log/mariadb.log'.
200130 09:09:43 mysqld_safe Starting mysqld daemon with databases from /db/data
[root@TEST-DB bin]# ps -elf | grep mysql
4 S root 9833 9782 0 80 0 - 28330 do_wai 09:09 pts/0 00:00:00 /bin/sh ./mysqld_safe --user=mysql
4 S mysql 10266 9833 15 80 0 - 1424098 poll_s 09:09 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/db/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/db/log/mariadb.log --open-files-limit=8192 --pid-file=/db/log/mariadb.pid --socket=/tmp/mysql.sock --port=3306
0 R root 10309 9782 0 80 0 - 29219 - 09:09 pts/0 00:00:00 grep --color=auto mysql
[root@TEST-DB bin]# ./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 ##root password 설정 여부 Y
New password: ## 설정할 root password
Re-enter new password: ## root 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] n ## root계정 remote접속 허용
... 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] y ## TEST Database 삭제 여부
- 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!
정상적으로 DB 에 접속이 되는지 확인한다.
[root@TEST-DB bin]# ./mysql -uroot -pROOT_PASSWD
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.3.22-MariaDB-log 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 [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]>
기타 추가 설정 관련
2019/10/31 - [DB/Mysql] - [MariaDB] Database root 계정 이름 변경
2019/10/31 - [DB/Mysql] - [Mysql/Maria DB] root password 변경 방법
'DB > Mysql' 카테고리의 다른 글
[Mysql/MariaDB] "mysql: [Warning] Using a password on the command line interface can be insecure." 발생 시 (0) | 2020.09.11 |
---|---|
[Mysql/MariaDb ] innodb frm파일에서 table schema 복구 (0) | 2020.07.23 |
[MariaDB] audit log 설정 (0) | 2020.01.30 |
[Mysql/Maria DB] root password 변경 방법 (0) | 2019.10.31 |
[MariaDB] Database root 계정 이름 변경 (0) | 2019.10.31 |