Oct 24, 2024 - MySQL 8.4 버전과 MHA 이중화

Comments

MySQL 8.4 버전과 MHA 이중화

MySQL 8.4 버전에서 Replication 명령문이 변경됩니다. Master, Slave 용어를 8.0부터 줄여가기 시작을 해서 8.4에서는 없어집니다. Master는 Source로 Slave는 Replica로 변경이 됩니다. https://dev.mysql.com/doc/relnotes/mysql/8.4/en/news-8-4-0.html

용어 변경의 이유와 관련 내용들에 대해서는 아래 웹페이지를 참고해서 자세하게 알 수 있습니다. https://www.zdnet.com/article/mysql-drops-master-slave-and-blacklist-whitelist-terminology/ https://jira.mariadb.org/browse/MDEV-18777

MariaDB는 Source가 아닌 Primary 단어로 변경을 하고 있습니다.

MHA (Master High Availability Manager and tools for MySQL) 이중화

MHA는 MySQL, MariaDB 오픈소스 데이터베이스에서 오랜기간 HA 솔루션으로 많이 사용하고 있습니다. MHA 0.58 버전의 release가 2018년 03월 23일에 나오고 더 이상 배포가 되지 않고 있습니다. https://github.com/yoshinorim/mha4mysql-manager

MySQL 8.4에서 Change Master to 명령을 더 이상 사용 할 수 없게 되면서 MHA는 정상적으로 작동하지 않게 됩니다. 오픈소스이기에 소스를 수정해서 사용 할 수는 있지만 공식적인 사용으로는 고민이 됩니다.

이에 대한 대안으로는 MariaDB는 하위버전 호환성을 위해서 change master to 명령이 사용 가능해서 MySQL 대신 MariaDB를 사용 할 수 있습니다.

Percona Orchestrator 이중화

다른 방법으로는 이중화를 Orchestrator를 사용하는 것입니다. https://github.com/openark/orchestrator

Percona에서도 MHA는 더 이상 기술지원이 어렵고 Orchestrator를 사용하는것으로 권고를 하는것으로 알고 있습니다. Orchestrator의 마지막 소스 수정이 2021년 10월 26일이지만 Percona에서는 지속적으로 관리와 배포를 하고 있습니다. https://github.com/percona/orchestrator

May 25, 2021 - WSL2 환경에서 vagrant를 이용한 테스트 환경 만들기

Comments

WSL2 환경에서 vagrant를 이용한 테스트 환경 만들기

윈도우10에서 WSL을 사용해서 linux를 사용할 수 있습니다. linux 테스트 환경을 만들기 위해서 vagrant를 이용하면 쉽게 구성을 할 수 있습니다. WSL2 환경에 vagrant를 이용해서 centos 테스트 환경을 만들어서 사용하면 쉽게 linux 관련 테스트를 할 수 있습니다.

WSL2 설치는 여러 설치 관련 문서들이 있으니 참고하시면 되고요.

vagrant 설치

WSL2에 vagrant 설치는 아래 웹페이지를 참고 하면 됩니다. https://blog.thenets.org/how-to-run-vagrant-on-wsl-2/

주요 설치 관련 명령은 아래와 같습니다.

# run inside WSL 2
# check https://www.vagrantup.com/downloads for more info
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install vagrant

# append those two lines into ~/.bashrc
echo 'export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"' >> ~/.bashrc
echo 'export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"' >> ~/.bashrc

# now reload the ~/.bashrc file
source ~/.bashrc

vagrant 설정

2대의 centos VM을 만드는 Vagrantfile은 아래와 같습니다.

# -*- mode: ruby -*-
# vi: set ft=ruby :

#Vagrant_API_Version = "2"
Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
  config.vm.box_check_update = false
  #test01
  config.vm.define:"neoclova01" do |cfg|
    cfg.vm.provider:virtualbox do |vb|
      vb.name="CentOS-neoclova01"
      vb.customize ["modifyvm", :id, "--cpus",2]
      vb.customize ["modifyvm", :id, "--memory",1024]
    end
    cfg.vm.host_name="neoclova01"
    cfg.vm.synced_folder ".", "/vagrant", disabled:true
#    cfg.vm.network "public_network", ip: "1.1.1.1"
    cfg.vm.network "private_network", ip: "192.168.200.101"
#    cfg.vm.network "forwarded_port", guest: 22, host:39211, auto_correct: false, id: "ssh"
#    cfg.vm.provision "shell", inline: <<-SHELL
#       echo "hello"
#       date
#    SHELL
  end
  #test02
  config.vm.define:"neoclova02" do |cfg|
    cfg.vm.provider:virtualbox do |vb|
      vb.name="CentOS-neoclova02"
      vb.customize ["modifyvm", :id, "--cpus",2]
      vb.customize ["modifyvm", :id, "--memory",1024]
    end
    cfg.vm.host_name="neoclova02"
    cfg.vm.synced_folder ".", "/vagrant", disabled:true
#    cfg.vm.network "public_network", ip: "8.8.8.8"
    cfg.vm.network "private_network", ip: "192.168.200.102"
#    cfg.vm.network "forwarded_port", guest: 22, host:39212, auto_correct: false, id: "ssh"
  end
end

vagrant 실행

WSL2에서 vagrant ssh를 사용하기 위해서는 WSL2 플러그인을 설치해야 합니다.

vagrant plugin install virtualbox_WSL2

vagrant up

Sep 11, 2020 - MariaDB Connect Storage Engine - MSSQL ODBC link

Comments

MariaDB Connect Storage Engine - MSSQL ODBC 연결

MariaDB의 Connect 스토리지 엔진을 이용해서 MSSQL 서버에 ODBC 연결을 할 수 있습니다. 먼저 ODBC를 설치하고 ODBC 설정을 합니다. Linux는 CentOS7입니다.

# yum install epel-release
# yum install freetds
# yum install unixODBC

# cat /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS Driver
Driver = /usr/lib64/libtdsodbc.so.0
Setup = /usr/lib64/libtdsS.so.2
FileUsage = 1
CPTimeout = 5
CRReuse = 5

# cat /etc/odbc.ini
[NEOCLOVA]
driver=FreeTDS
server=127.0.0.1
port=1433
database=ssauravy
client_charset = UTF-8
tds_version = 8.0

MariaDB를 설치한 후에 Connect 스토리지엔진을 설치하고 MSSQL 서버의 Table에 연결을 해서 사용합니다.

> install soname 'ha_connect';

> CREATE TABLE t_test1 ENGINE=CONNECT, TABLE_TYPE=ODBC, TABNAME='dbo.test' CONNECTION='Driver=FreeTDS;Server=127.0.0.1;Database=dbtest;UID=neoclova;PWD=welcome;Port=1433';
> CREATE TABLE t_test2 ENGINE=CONNECT TABLE_TYPE=ODBC TABNAME='dbo.test' CONNECTION='DSN=NEOCLOVA;UID=neoclova;PWD=welcome';

Dec 30, 2019 - MariaDB Administrator 교육 교재

Comments

MariaDB Administrator 교육 교재

오뉴이노베이션에서 작성한 MariaDB Administrator 교육 교재입니다.

MariaDB Admin 2019

Jul 17, 2019 - MariaDB 10.4 GA - command

Comments

MariaDB 10.4 GA - command

2019년 6월 18일에 MariaDB 10.4 GA 버전이 배포 됐습니다.
https://mariadb.com/resources/blog/now-ga-mariadb-community-server-10-4/

주요 기능은 아래와 같다고 합니다.

  • Temporal data processing has been enhanced with the support of application time period tables.
  • Instant DDL operations for InnoDB allow non-blocking schema changes on the fly.
  • Security and stability improvements in the authentication system and user password management. SSL certificates can be reloaded.
  • Optimizer improvements, including the implementation of an optimizer trace and improved defaults as well as active histograms and storage engine independent statistics.
  • Performance improvements for Unicode collations, plus faster server startup, shutdown and purge; and faster checks for bigger user and privilege tables.
  • MariaDB Cluster is now based on Galera 4 and delivers better performance and large transactions.

https://mariadb.com/resources/blog/mariadb-named-commands/

2009년에 MariaDB 5.1.38 버전이 처음 배포된 후에 10주년이라고 합니다. MariaDB 10.4부터는 mysql 실행 명령어들이 mariadb로 아래와 같이 변경 된다고 합니다.

  • mariadb → mysql
  • mariadb-access → mysqlaccess
  • mariadb-admin → mysqladmin
  • mariadb-binlog → mysqlbinlog
  • mariadb-check → mysqlcheck
  • mariadb-convert-table-format → mysql_convert_table_format
  • mariadbd-multi → mysqld_multi
  • mariadbd-safe → mysqld_safe
  • mariadbd-safe-helper → mysqld_safe_helper
  • mariadb-dump → mysqldump
  • mariadb-dumpslow → mysqldumpslow
  • mariadb-embedded → mysql_embedded
  • mariadb-find-rows → mysql_find_rows
  • mariadb-fix-extensions → mysql_fix_extensions
  • mariadb-hotcopy → mysqlhotcopy
  • mariadb-import → mysqlimport
  • mariadb-install-db → mysql_install_db
  • mariadb-plugin → mysql_plugin
  • mariadb-secure-installation → mysql_secure_installation
  • mariadb-setpermission → mysql_setpermission
  • mariadb-show → mysqlshow
  • mariadb-slap → mysqlslap
  • mariadb-tzinfo-to-sql → mysql_tzinfo_to_sql
  • mariadb-upgrade → mysql_upgrade
  • mariadb-waitpid → mysql_waitpid

MariaDB

Jul 16, 2019 - MariaDB Korea Conference 2019

Comments

MariaDB Korea Conference 2019 - Monty in Seoul

MariaDB 한국 컨퍼런스가 열린다고 합니다.

시간 : 2019년 9월 25일 (수) 13:00 ~ 17:30
장소 : 한국과학기술회관 국제회의장 (강남역 12번 출구)
내용 : Monty Keynotes 및 MariaDB 소개

Monty Widenius

  • MySQL 데이터베이스 및 MariaDB 창시자
  • 데이터베이스의 오픈소스 운동을 주도
  • https://www.facebook.com/michael.widenius

MariaDB-Korea-Conference-2019

페이스북 MariaDB 한국사용자 모임 그룹에 MariaDB 한국 지사장님이 소식을 올려 주셨네요. https://www.facebook.com/p1oneer/posts/2482457628459799

Jul 9, 2019 - MariaDB MaxScale 2.1 GPL 전환

Comments

MariaDB MaxScale 2.1 GPL 전환

https://mariadb.com/projects-using-bsl-11/

MariaDB MaxScale 2.1 버전이 2019년 7월 1일로 BSL에서 GPL로 변경 됐습니다. 처음 BSL 나왔을때 말이 많았는데요. 시간이 지나니 어느새 GPL로 변경이 되는 날이 지났습니다. MaxScale의 최신 버전은 2.3.9-GA, 2.4.0-beta 입니다.

내년 1월에 MaxScale 2.2 버전이 GPL로 변경이 됩니다. MaxScale 2.3 버전은 2022년 1월에 BSL에서 GPL로 전환이 됩니다. https://github.com/mariadb-corporation/MaxScale/blob/2.3/LICENSE.TXT

May 28, 2019 - MariaDB Undo recovery 오래 걸릴때

Comments

MariaDB Undo recovery 오래 걸릴때

대량의 트랙잭션을 수행하던 중에 MariaDB (MySQL) 서버가 비정상 종료를 하면 InnoDB 등의 transaction 지원을 하는 storage engine 들은 재시작하면서 undo recovery를 합니다.
undo recovery가 빨리 완료가 되면 괜찮지만, 대량의 트랜잭션들은 몇일이 걸릴 수도 있습니다.
MariaDB에서는 이럴때 mysqldump 백업을 하고 해당 데이터베이스를 drop 후에 복구하라고 합니다.
https://mariadb.com/kb/en/library/innodb-recovery-modes/

데이터가 수백기가를 넘을때는 mysqldump 백업/복원 시간도 올래 걸립니다. 이럴때 ALTER TABLE … DISCARD (IMPORT) TABLESPACE 명령을 이용해서 좀 더 빠르게 복구를 할 수 있습니다.

undo recovery 하지 않고 테이블 복구 절차

  • force recovery 모드로 MariaDB 시작
  • mysqldump -d 데이터베이스 스키마 백업
  • MariaDB 중지
  • 데이터베이스 디렉토리의 ibd 파일 복사
  • force recovery 모드로 MariaDB 시작
  • drop database
  • MariaDB 정상적으로 재시작
  • create database
  • 데이터베이스 스키마 복원
  • alter table … discard tablespace
  • 복사했던 ibd 파일을 데이터베이스 디렉토리로 이동
  • alter table … import tablespace

alter table 명령 만들기

테이블이 많을때 information schema 이용해서 alter table 명령을 만들 수 있습니다.

select concat('alter table ', table_schema, '.', table_name, ' import tablespace;') as sql_alter
from information_schema.tables
where table_schema = 'ohnew';

May 27, 2019 - Redis Sentinel : Docker

Comments

Docker 환경에서 Redis Sentinel replication 구성하기

Redis Sentinel 구성을 위해서 4개의 container를 사용합니다.

  • redis-snt-1 : redis master
  • redis-snt-2,3,4 : redis slave, sentinel

sentinel 구성을 위해서 아래 파일들을 사용합니다.

  • redis.conf : redis 환경 설정 파일
  • sentinel.conf : sentinel 환경 설정 파일
  • redis-start.sh : docker 실행 스크립트

redis.conf

일반적인 redis.conf 파일을 사용합니다.

# port 7901

dir "/data"
logfile "redis.log"

maxclients 1128
maxmemory 1000000000
maxmemory-policy volatile-lru

appendonly yes
appendfsync everysec
repl-backlog-size 50mb

sentinel.conf

port 8179
sentinel monitor rsmaster redis-snt-1 6379 1
sentinel down-after-milliseconds rsmaster 3000

bind 0.0.0.0
protected-mode yes
dir "/data/sentinel"
logfile "sentinel.log"
daemonize yes

redis-start.sh

#!/bin/sh
set -e

[ -d /data/sentinel ] || mkdir -p /data/sentinel && chown -R redis:redis /data

gosu redis redis-sentinel /usr/local/etc/redis/sentinel.conf
gosu redis redis-server /usr/local/etc/redis/redis.conf --slaveof redis-snt-1 6379

redis sentinel 구성

현재 디렉토리 밑으로 docker 별로 사용할 conf, sh 파일을 복사합니다.
redis master로 사용할 서버에 대한 설정을 변경합니다.
docker run을 실행하면서 sentinel을 같이 실행하기 위해서 start.sh 실행으로 시작합니다.

for ind in `seq 1 4`; do \
 mkdir -p $PWD/data/conf/node$ind
 cp redis-master.conf data/conf/node$ind/redis.conf
 cp sentinel.conf data/conf/node$ind/sentinel.conf
 cp redis-start.sh data/conf/node$ind/start.sh
done

# chown 999:999 data/conf/node*/*.conf
# sed -e 's/gosu redis redis-sentinel/#gosu redis redis-sentinel/' redis-start.sh > data/conf/node1/start.sh
# sed -e 's/--slaveof redis-snt-1 6379//' redis-start.sh > data/conf/node1/start.sh

### docker run
for ind in `seq 1 4`; do \
 docker run -d \
 -v $PWD/data/conf/node$ind:/usr/local/etc/redis \
 -v $PWD/data/node$ind:/data \
 --name redis-snt-$ind --net redis-cluster \
 redis /usr/local/etc/redis/start.sh
done

docker에서 redis cluster 이용하는게 좋겠으나 특정 서비스에서 sentinel 사용을 요구할때 최소의 container로 sentinel 구성을 어떻게 하면 좋을까 고민하다가 하나의 container에 redis 서버와 sentinel을 같이 실행할 수 있겠다 싶었습니다.

May 27, 2019 - MariaDB replication : Docker

Comments

Docker 환경에서 MariaDB replication 구성하기

MariaDB(MySQL) replication 구성을 하려면 my.cnf 설정을 서버별로 맞춰줘야 합니다.
성능이나 관리를 위해서 데이터 디렉토리, 로그 디렉토리들을 기본 설정이 아닌 원하는 디렉토리로 해야 할 필요도 있습니다.
docker 환경에서 MariaDB Replication 구성을 좀 더 쉽게 하기 위한 my.cnf와 shell 스크립트를 만들어 봤습니다.

my.cnf

데이터는 /MariaDB/data 디렉토리를 사용하고 로그는 /MariaDB/log 디렉토리를 사용합니다.
replication을 위해서 binlog와 relaylog 디렉토리들은 /MariaDB/log 디렉토리 하위로 사용합니다.

####
#### Ohnew Innovation
#### MariaDB my.cnf
####

[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0
# syslog
#skip_log_error
#syslog

[mysqld]
# basic setting
#user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /MariaDB/data
tmpdir		= /tmp
lc_messages_dir	= /usr/share/mysql
lc_messages	= en_US
skip-external-locking
bind-address=0.0.0.0

skip-host-cache
skip-name-resolve

#server-id=2179

#query_cache setting
query_cache_type    = 0
query_cache_size    = 0
query_cache_limit   = 0

# Log file setting
log-error           = /MariaDB/log/mariadb.err
slow_query_log      = 1
slow_query_log_file = /MariaDB/log/slow-query.log
long_query_time     = 3
#log-queries-not-using-indexes
#log_slow_admin_statements

log-bin             = /MariaDB/log/binary/mariadb-bin
binlog_cache_size   = 2M
max_binlog_size     = 100M
expire_logs_days    = 10
sync_binlog		    = 1
binlog_format       =row

# slaves
relay_log           = /MariaDB/log/binary/relay-bin
#log_slave_updates
#read_only

# Time-out setting
wait_timeout         = 600
interactive_timeout  = 3600
connect_timeout		 = 5

# transaction isolation setting
transaction_isolation = READ-COMMITTED

# etc setting
back_log            = 1024
max_connections     = 1024
max_connect_errors  = 1024
table_open_cache    = 2048
max_allowed_packet  = 1024M
max_heap_table_size = 1024M
sort_buffer_size    = 8M
join_buffer_size    = 8M
thread_cache_size   = 128
#thread_concurrency = 36
tmp_table_size      = 1024M

# character set setting
#init_connect = "SET collation_connection = utf8_general_ci"
#init_connect = "SET NAMES utf8"
character-set-server = utf8mb4
#collation-server     = utf8mb4_general_ci 
#character_set_server = utf8mb4 
#collation_server     = utf8mb4_general_ci

# innodb setting
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 512M
innodb_log_buffer_size         = 16M
innodb_lock_wait_timeout       = 50
innodb_thread_sleep_delay      = 0
innodb_commit_concurrency      = 36
innodb_doublewrite             = 0
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency      = 36
#innodb_log_files_in_group      = 3
innodb_flush_method	           = O_DIRECT
innodb_log_file_size           = 256M
#innodb_data_file_path    = ibdata1:1024M;ibdata2:1024M;ibdata3:10M:autoextend

# use MyISAM
key_buffer_size          = 128M
read_buffer_size         = 2M
read_rnd_buffer_size     = 16M
bulk_insert_buffer_size  = 64M
myisam_sort_buffer_size  = 512M
myisam_max_sort_file_size= 512M
myisam_repair_threads    = 1
myisam_recover

# Galera
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#wsrep_slave_threads=1

[mysqldump]
max_allowed_packet	= 1024M
quick
#quote-names

[mysqld_safe]
open_files_limit = 8192

maria-create.sh

각 container 들의 cnt, data, log 디렉토리를 생성하고 my.cnf에서 server-id 설정을 변경합니다.
4개의 docker container를 생성합니다. (maria1 ~ maria4)
maria3 서버를 replication master 서버로 사용합니다.
master 서버에 slave 서버들이 replication slave로 사용할 repl 계정을 만듭니다.
GTID 사용해서 replication 연결을 하기 위한 master position을 GTIDpos 변수에 설정합니다.
master 서버 이외의 container들을 change master 명령으로 slave 서버 설정을 합니다.

#!/bin/bash
####
#### Ohnew Innovation
#### MariaDB Replication : Docker
####


Nodes=4 
NodeMaster=3
MyPass="ohnew21&("

for i in `seq 1 $Nodes`; do 
    mkdir -p $PWD/conf/node$i $PWD/data/node$i $PWD/log/node$i/binary
    cp my.cnf $PWD/conf/node$i
    sed -i "s/#server-id=2179/server-id=$i/g" conf/node$i/my.cnf
done

chown -R 999:999 ./data/*
chown -R 999:999 ./log/*

for i in `seq 1 $Nodes`; do 
    docker run -d -it \
    --network=maria --name=maria$i --memory-swappiness=1 \
    --mount type=bind,src=$PWD/conf/node$i,dst=/etc/mysql \
    --mount type=bind,src=$PWD/data/node$i,dst=/MariaDB/data \
    --mount type=bind,src=$PWD/log/node$i,dst=/MariaDB/log \
    -e MYSQL_ROOT_PASSWORD="$MyPass" \
    mariadb
done

echo -ne "maria$NodeMaster "
while true; do
  chkPing=`docker container exec maria$NodeMaster mysqladmin -s -p"$MyPass" ping > chk.ping`
  if grep "mysqld is alive" chk.ping ; then
    break
  fi
  echo -ne "."
  sleep 1
done

docker container exec maria$NodeMaster \
    mysql -p"$MyPass" -e \
      "CREATE USER 'repl'@'%' IDENTIFIED BY '$MyPass'; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';"

GTIDpos=`docker container exec maria$NodeMaster mysql -s -p"ohnew21&(" -e "select @@global.gtid_binlog_pos"`

for i in `seq 1 $Nodes`; do 
  if [ "$i" -eq "$NodeMaster" ] ; then
    echo -ne ""
  else

    echo -ne "maria$i "
    while true; do
      chkPing=`docker container exec maria$i mysqladmin -s -p"$MyPass" ping > chk.ping`
      if grep "mysqld is alive" chk.ping ; then
        break
      fi
      echo -ne "."
      sleep 1
    done

    docker container exec maria$i \
      mysql -hmaria$i -p"$MyPass" -e \
      "SET GLOBAL read_only = 1; SET GLOBAL gtid_slave_pos = '$GTIDpos'; CHANGE MASTER TO MASTER_HOST='maria$NodeMaster', MASTER_USER='repl', MASTER_PASSWORD='$MyPass', MASTER_USE_GTID = current_pos; START SLAVE;"
    
    NodeSlave=$i

  fi
done

docker container exec maria$NodeSlave mysql -s -p"ohnew21&(" -e "show slave status\G" | grep Running:

스크립트 실행

my.cnf와 maria-create.sh 파일을 동일한 디렉토리에 만들고 maria-create.sh 파일을 실행하면 4개의 container가 만들어지고, 해당 디렉토리 밑으로 conf, data, log 디렉토리들에 node1, node2, node3, node4 서버별로 관련 파일들이 생깁니다.

docker에서는 galera cluster를 사용하는게 replication 설정보다 구성하기가 좋을거 같습니다. MaxScale이나 ProxySQL같은 DB Proxy를 어떻게 사용할것인지에 따라서 장단점은 있겠습니다.