본문 바로가기

개발

[CentOS 7/Linux]리눅스 MariaDB 바이너리 파일로 설치하기(yum없이 tar.gz이용)

yum 사용이 가능한 곳이면 참 편하겠지만 운영환경에서는 보안적인 부분 때문에 대부분은 사용이 불가능 한 곳입니다.

 

mariadDB 바이너리 파일을 이용하여 직접 다운로드하는 방식을 알아보겠습니다.

 

1. mariaDB 설치파일 다운로드

mariadb.com/downloads/

 

MariaDB Products & Tools Downloads | MariaDB

Find MariaDB downloads, connectors, and tools including Community Server, Enterprise Server, ColumnStore, MaxScale and Xpand.

mariadb.com

 

위 링크로 이동하여 본인 운영체제에 맞게 선택하여 파일을 다운로드합니다.

 

 

가운데에 노랗게 색칠한 부분 Show All Files를 클릭해서 버전별로 확인할 수 있습니다.

 

 

 

 

/bintar-linux-systemd-x86_64/mariadb-10.11.2-linux-systemd-x86_64.tar.gz 를 다운로드합니다.

 

 

 

 

 

2.  유저 생성 및 사전 준비

 mysql user 생성 후 패스워드를 입력하여 줍니다.

[root@localhost ~]# adduser mysql
[root@localhost ~]# passwd mysql

 

이후, data 및 로그 저장 폴더 or 파일을 생성합니다.

 

[root@localhost ~]# mkdir /home/mysql/log
[root@localhost ~]# chown -R mysql.mysql /home/mysql/log
[root@localhost ~]#
[root@localhost ~]# mkdir -p /data/mariadb/master
[root@localhost ~]# mkdir -p /data/mariadb/ibdata
[root@localhost ~]# mkdir -p /data/mariadb/iblog
[root@localhost ~]# mkdir -p /data/mariadb/log-bin
[root@localhost ~]# chown -R mysql.mysql /data/mariadb

 

 

mysqld.log 파일을 현재 시간으로 생성하고 권한 설정을 해줍니다.

 

[root@localhost ~]# touch /var/log/mysqld.log
[root@localhost ~]# chmod 644 /var/log/mysqld.log
[root@localhost ~]# chown mysql.mysql /var/log/mysqld.log

 

 

 

 

3. 설치파일 업로드 및 압축해제

 

다운로드한 mariaDB 바이너리 파일을 /root 경로로 업로드해 줍니다.

 

[root@localhost ~]# ll
total 343788
-rw-------.  1 root root      2757 Mar 29 21:55 anaconda-ks.cfg
-rw-rw-r--.  1 mhs  mhs  352027274 Mar 29 22:53 mariadb-10.11.2-linux-systemd-x86_64.tar.gz
-rw-------.  1 root root      2037 Mar 29 21:55 original-ks.cfg

 

압축을 해제해 줍니다.

 

[root@localhost ~]# tar -xvzf mariadb-10.11.2-linux-systemd-x86_64.tar.gz

 

압축 해제한 폴더를 /usr/local로 이동한 뒤 심볼릭 링크를 설정해 줍니다.

 

[root@localhost ~]# mv mariadb-10.11.2-linux-systemd-x86_64 /usr/local
[root@localhost ~]# cd /usr/local
[root@localhost ~]# ln -s mariadb-10.11.2-linux-systemd-x86_64/ mysql

 

설정파일들을 복사 및 변경합니다.

 

[root@localhost init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost init.d]# vi /etc/init.d/mysqld

 

mysqld 파일 변경

 

# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MariaDB
# Description: MariaDB is a very fast and reliable SQL database engine.
### END INIT INFO

# have to do one of the following things for this script to work:
#
# - Run this script from within the MariaDB installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MariaDB variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MariaDB configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MariaDB configuration files.

basedir=/usr/local/mysql
datadir=/data/mariadb/master

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overridden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for Red Hat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

 

28, 29번째 줄에 basedir, datadir 부분을 위와 같이 입력해 줍니다.

(실제 파일에서는 45, 46 번째 줄에 있습니다.)

 

 

.bash_profile 변경

 

[root@localhost init.d]# vi ~/.bash_profile

 

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

#PATH=$PATH:$HOME/bin

#export PATH

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts

 

기존에 있었던 PATH 값을 주석처리하고 14번째 줄처럼 입력해 줍니다.

 

이후, 적용합니다.

 

source ~/.bash_profile

 

이제 my.cnf 설정 파일을 수정해 줍니다. 이 파일은 /etc 경로에 있습니다.

 

백업 후 새로 만들어서 작업합니다.

[root@localhost /]# cd /etc
[root@localhost etc]# mv my.cnf my.cnf_bak
[root@localhost etc]# vi my.cnf

 

아래처럼 입력합니다.

 

# Mariadb
[server]

# mysqld standalone daemon
[mysqld]
port                            = 3306
datadir                         = /data/mariadb/master
socket                          = /tmp/mysql.sock

# Character set (utf8mb4)
character_set-client-handshake  = FALSE
character-set-server            = utf8mb4
collation_server                = utf8mb4_general_ci
init_connect                    = set collation_connection=utf8mb4_general_ci
init_connect                    = set names utf8mb4

# Common
table_open_cache                = 2048
max_allowed_packet              = 32M
binlog_cache_size               = 1M
max_heap_table_size             = 64M
read_buffer_size                = 64M
read_rnd_buffer_size            = 16M
sort_buffer_size                = 8M
join_buffer_size                = 8M
ft_min_word_len                 = 4
lower_case_table_names          = 1
default-storage-engine          = innodb
thread_stack                    = 240K
transaction_isolation           = READ-COMMITTED
tmp_table_size                  = 32M

# Connection
max_connections                 = 200
max_connect_errors              = 50
back_log                        = 100
thread_cache_size               = 100

# Query Cache
query_cache_size                = 32M
query_cache_limit               = 2M

log-bin                         = /data/mariadb/log-bin/mysql-bin
binlog_format                   = mixed
max_binlog_size                 = 128M
expire_logs_days                = 7

slow_query_log                  = 1
long_query_time                 = 5
log_output                      = FILE,TABLE
log_error                       = /var/log/mysqld.log
slow_query_log_file             = /home/mysql/log/mysql_slow_query.log
general_log_file                = /home/mysql/log/mysql_general.log

key_buffer_size                 = 32M
bulk_insert_buffer_size         = 32M
myisam_sort_buffer_size         = 64M
myisam_max_sort_file_size       = 256M
myisam_repair_threads           = 1

# Innodb
innodb_buffer_pool_size         = 1G   # 현재 서버 사양의 70~80%를 설정한다.
innodb_file_per_table           = 1
innodb_data_home_dir            = /data/mariadb/ibdata
innodb_data_file_path           = ibdata1:1000M;ibdata2:1000M;ibdata3:1000M;ibdata4:1000M:autoextend:max:2000M
innodb_write_io_threads         = 8
innodb_read_io_threads          = 8
innodb_thread_concurrency       = 16
innodb_flush_log_at_trx_commit  = 1
innodb_log_group_home_dir       = /data/mariadb/iblog
innodb_log_buffer_size          = 32M
innodb_log_file_size            = 128M
innodb_log_files_in_group       = 10
innodb_max_dirty_pages_pct      = 90
innodb_lock_wait_timeout        = 120

 

이 설정파일에 대한 부분은 다음에 다루도록 하겠습니다.

 

여러분들은 꼭 dba분과 함께 상의해서 작업하세요.

 

 

 

4. DB install 및 서비스 시작

 

이제 사전 작업은 모두 끝마쳤습니다. 설치하면 됩니다. 아래와 같은 명령어를 입력하여 설치를 수행합니다.

 

[root@localhost etc]# mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mariadb/master --defaults-file=/etc/my.cnf

Installing MariaDB/MySQL system tables in '/data/mariadb/master' ...
OK

To start mariadbd at boot time you have to copy
support-files/mariadb.service 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 mysql@localhost, it has no password either, but
you need to be the system 'mysql' 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/mysql' ; /usr/local/mysql/bin/mariadb-safe --datadir='/data/mariadb/master'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql/mysql-test' ; perl mariadb-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/

 위와 같이 뜬다면 성공입니다.

 

 

이제 서비스를 시작해 줍니다.

 

 

[root@localhost etc]# service mysqld start
Reloading systemd:                                         [  OK  ]
Starting mysqld (via systemctl):                           [  OK  ]​

 

서비스가 잘 떴는지 명령어를 이용해 확인해 봅시다.

 

[root@localhost etc]# systemctl status mysqld
● mysqld.service - LSB: start and stop MariaDB
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Wed 2023-03-29 23:30:48 PDT; 1min 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 53622 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    Tasks: 12
   CGroup: /system.slice/mysqld.service
           ├─53813 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mariadb/master --pid-file=/data/...
           └─54076 /usr/local/mysql/bin/mariadbd --basedir=/usr/local/mysql --datadir=/data/mariadb/master -...

Mar 29 23:30:47 localhost.localdomain systemd[1]: Starting LSB: start and stop MariaDB...
Mar 29 23:30:47 localhost.localdomain mysqld[53622]: Starting MariaDB.230329 23:30:47 mysqld_safe Logging...g'.
Mar 29 23:30:47 localhost.localdomain mysqld[53622]: 230329 23:30:47 mysqld_safe Starting mariadbd daemon...ter
Mar 29 23:30:48 localhost.localdomain mysqld[53622]: /etc/rc.d/init.d/mysqld: line 262: log_success_msg: ...und
Mar 29 23:30:48 localhost.localdomain systemd[1]: Started LSB: start and stop MariaDB.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost etc]#

 

잘 떠있네요.

 

꼭 서비스를 잘 실행시켜주어야 합니다.

 

이제 mysql에 접속해서 버전을 확인해 봅시다.

 

[root@localhost etc]# mysql -D mysql -e 'select version();'
+---------------------+
| version()           |
+---------------------+
| 10.11.2-MariaDB-log |
+---------------------+
[root@localhost etc]#

 

 

아주 잘 되네요. 이제 root 계정의 초기 설정을 해줍니다.

 

5. DB 초기설정

 

우선 mysql을 접속합니다.

 

[root@localhost etc]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.11.2-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)]>

 

데이터베이스를 확인해서 mysql 데이터베이스로 접속합니다.

 

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
6 rows in set (0.000 sec)

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]>

 

아래 명령어로 user 테이블에서 사용자 목록을 조회할 수 있습니다.

 

MariaDB [mysql]> select host, user, password from user;
+-----------------------+-------------+-------------------------------------------+
| Host                  | User        | Password                                  |
+-----------------------+-------------+-------------------------------------------+
| localhost             | mariadb.sys |                                           |
| localhost             | root        | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost             | mysql       | invalid                                   |
|                       | PUBLIC      |                                           |
| localhost             |             |                                           |
| localhost.localdomain |             |                                           |
+-----------------------+-------------+-------------------------------------------+
6 rows in set (0.001 sec)

MariaDB [mysql]>

 

원래는 root 계정에 Password 컬럼에 invalid 값이 들어가 있지만 저는 이미 비밀번호 설정을 해둔 상태입니다.

비밀번호는 다음과 같이 변경할 수 있습니다.

 

> set password for 'root'@'localhost'=password('비밀번호')

# 변경사항 반영
> flush privileges;

 

이제 root 계정으로 방금 설정한 password를 입력해 접속해 봅시다.

 

[root@localhost etc]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.11.2-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)]>

 

-끝-