본문 바로가기
IT/리눅스

마리아디비(MariaDB) 리눅스(Linux)에 설치하기

by 라떼야가자 2024. 7. 26.

MariaDB 설치

 

기존 설치 확인 후 삭제

yum list installed MariaDB*
yum remove MariaDB*

 

 

설치파일 다운로드

Download MariaDB Server - MariaDB.org

 

Download MariaDB Server - MariaDB.org

REST API Release Schedule Reporting Bugs … Continue reading "Download MariaDB Server"

mariadb.org

 

설치파일을 서버에 업로드

scp, ftp 등을 이용하여 설치할 대상 서버로 업로드

 

설치

adduser mysql
passwd mysql
tar xfz mariadb-10.11.8-linux-systemd-x86_64.tar.gz
mv mariadb-10.11.8-linux-systemd-x86_64 /mariadb
chown -R mysql:mysql /mariadb
ln -s /mariadb /usr/local/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysql/mysqladmin

 

MariaDB 설정

/etc/my.cnf 생성 (또는 수정)

# my.cnf

[mysql]
default-character-set=utf8

[mariadb]
bind-address=0.0.0.0
port=3306
basedir=/usr/local/mysql
datadir=/mysql/mariadb/data
user=mysql
skip-name-resolve=ON
max_user_connections=300
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
default-time-zone='+9:00'

log_error=/data/mariadb/log/mariadb-err.log
general_log
general_log_file=/data/mariadb/log/mariadb.log
slow_query_log
slow_query_log_file=/data/mariadb/log/mariadb-slow.log
long_query_time=3

log-bin=/data/mariadb/binlog/mariadb-bin
expire_logs_days=7
binlog_cache_size=2M
max_binlog_size=1G

plugin_load_add=server_audit
server_audit_logging=ON
server_audit_events=CONNECT,QUERY,TABLE
server_audit_file_path=/data/mariadb/log/server_audit.log

#innodb_buffer_pool_size=89G # 70% of avaliable RAM
#innodb_log_file_size=22G
innodb_buffer_pool_size=5G # 70% of avaliable RAM
innodb_log_file_size=1G # 25% of innodb_buffer_pool_size

wait_timeout=600
local_infile=OFF

 

데이터 경로 생성

cd /mariadb
./scripts/mariadb-install-db --datadir=/data/mariadb/data --basedir=. --defaults-file=/etc/my.cnf

 

설치 후 기동 테스트

/mariadb/bin/mariadbd

셸을 추가로 접속해서 mysql 명령어로 접속 여부 확인한다.

접속이 정상이면, kill -9 로 종료한다.

 

OS 설정

SWAP

swappiness 설정 확인

sysctl -e vm.swappiness

 

swappiness 설정

sysctl vm.swappiness=1

 

위 설정을 /etc/sysctl.conf 에도 동일하게 넣는다.

 

LIMIT

오픈파일개수 설정

ulimit -Hn 65535
ulimit -Sn 65535

 

vi /etc/security/limits.conf
mysql		soft		65535
mysql		hard		65535

 

서비스 등록

cp /mariadb/support-files/systemd/mariadb.service /usr/lib/systemd/system/mariadb.service
systemctl enable mariadb

 

 

로그로테이션 설정

cp /mariadb/support-files/mariadb.logrotate /etc/logrotate.d/mariadb.logrotate
logrotate -f /etc/logrotate.d/mariadb.logrotate

 

 

보안을 위해 권한 설정 추가

systemctl edit mariadb

 

위의 명령어로 서비스 편집 화면으로 들어간 후, 아래 내용 입력하면 앞으로 로그 파일의 권한이 640으로 생성된다.

[Service]

Environment="UMASK=0640"
Environment="UMASK_DIR=0750"

 

 

MariaDB 실행

systemctl 명령어

#시작
systemctl start mariadb

#종료
systemctl stop mariadb

#상태 확인
systemctl status mariadb