본문 바로가기

카테고리 없음

MariaDB Galera Cluster Installtion v1.0

MariaDB Galera Cluster 5.5 Installation v 1.0

 

Date

Ver

Etc.

13.07.09

1.0

 

 

 

 

 

 

 

 

 

1.    MariaDB Galera Cluster

Synchronous Multi-Master Replication 이다.

 

위 단어가 말하듯이 기존 Replication 과 차별화 되는 부분으로

l  Multi-Master 구조 (읽기, 쓰기가 가능한)

l  Synchronous ( Nodes 간에 Replication Gap 이 없는)

 

다만 Cluster 라고 하기엔 애매한 부분으로 (MySQL NDB Cluster 와 다른점)

l  데이터 분산이 되지 않는다. (모든 노드가 동일 데이터를 보유)

 

2.    MariaDB Galera Cluster Installation (Prepare)

 

l  galera-23.2.4-1.rhel5.x86_64.rpm

l  mariadb-galera-5.5.29-linux-x86_64.tar

l  percona-xtrabackup-2.1.3-608.rhel5.x86_64.rpm

 

Galera Cluster 구성에 위와 같이 필요하다.

 

Galera Cluster 구성에 필요한 부분이고, MariaDB Galera Cluster

포함되어 있진 않다.

 

Percona xtrabackup variables setting 에 따라 필요할수도 필요하지 않을수도 있다.

여기서는 사용하지 않는 방향으로 진행했다.

 

3.    MariaDB Galera Cluster Installtion (Outline)

A.     Installation of Galera

B.     Configuration for MariaDB Galera Cluster

C.     Initial Start-Up

D.     Adding Cluster nodes

 

4.    MariaDB Galera Cluster Installation (Detail)

A.     Installation of Galera

rpm 을 설치한다.

#rpm -Uvh galera-23.2.4-1.rhel5.x86_64.rpm

B.     Configuration for MariaDB Galera Cluster

Galera Cluster Binary 설치파일을 압축해제한다.

#gunzip mariadb-galera-5.5.29-linux-x86_64.tar.gz

#tar xvf mariadb-galera-5.5.29-linux-x86_64.tar

# cd mariadb-galera-5.5.29-linux-x86_64

# mv * ../

# mkdir ibdata

# mkdir conf

# vi ./conf/my.cnf

 

My.cnf 내용

[client]

port            = 3307

socket          = /tmp/galera.sock

default-character-set=utf8

 

[mysqld]

port            = 3307 # modified from 3306

socket          = /tmp/galera.sock

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 128M # modified from 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 240K

 

server-id       = 10

 

log-bin=galera1

 

binlog_format=row

character_set_server = utf8

collation_server = utf8_bin

default-storage-engine = InnoDB

 

# InnoDB Settings

 

innodb_data_home_dir = /data/galera/ibdata

innodb_data_file_path = ibdata1:10000M

innodb_log_group_home_dir = /data/galera/ibdata

innodb_buffer_pool_size = 256M

innodb_doublewrite = 1

innodb_additional_mem_pool_size = 2M

innodb_log_file_size = 250M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 2 # AskMonty said

innodb_lock_wait_timeout = 50

innodb_autoinc_lock_mode=2

innodb_locks_unsafe_for_binlog=1

 

query_cache_size=0

query_cache_type=0

 

bind-address=172.18.174.161

 

open-files-limit = 65535

 

##

## WSREP options

##

 

wsrep_cluster_address='gcomm://'

#wsrep_cluster_address='gcomm://172.18.174.161'

wsrep_provider = /usr/lib64/galera/libgalera_smm.so

#wsrep_set_mothod=rsync

wsrep_cluster_name="gallera_test"

wsrep_slave_threads=1

wsrep_certify_nonPK=1

wsrep_max_ws_rows=131072

wsrep_max_ws_size=1073741824

wsrep_debug=0

wsrep_convert_LOCK_to_trx=0

wsrep_retry_autocommit=1

wsrep_auto_increment_control=1

wsrep_drupal_282555_workaround=0

wsrep_causal_reads=0

wsrep_notify_cmd=

 

##

## WSREP State Transfer options

##

 

# State Snapshot Transfer method

#wsrep_sst_method=xtrabackup

wsrep_sst_method=mysqldump

wsrep_sst_receive_address=172.18.174.161

wsrep_sst_auth=root:galera

 

[mysqldump]

quick

max_allowed_packet = 16M

 

[mysql]

no-auto-rehash

default-character-set=utf8

 

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

 

[mysqlhotcopy]

interactive-timeout

 

색으로 표시 한 부분은 똑같은 디렉토리 구조에 동일한 서비스 포트를 사용한다고 가정할 때

클러스터에 노드 추가 시 변경되어야 하는 부분이다.

 

색깔로 표시한 부분을 간략히 설명하자면 다음과 같다.

 

server-id Replication 구조내에서 유일한 값을 가져가야 한다.

log-bin binary log 이름 포맷을 셋팅하는 부분으로 필수 변경 사항은 아니다.

bind-address, wsrep_sst_receive_address 에는 장비의 IP Address 를 넣는다.

wsrep_sst_auth 에는 Galera Cluster Nodes 간 연결에 사용되는 user : password 를 넣는다.

 

wsrep_cluster_address 는 최초 구성 시 ‘gcomm://’ 을 넣어 기동한다.

이는 Cluster 최초구성을 하겠다는 의미이다.

최초의 노드가 A 라는 address   떠 있는 상황에서 두 번째 노드를 추가한다면,

gcomm://A’ 라고 넣게 된다.

 

C.     Initial Start-Up

MariaDB 설치 및 기동

./scripts/mysql_install_db --defaults-file=/data/galera/conf/my.cnf --user=galera

./bin/mysqld_safe --defaults-file=/data/galera/conf/my.cnf --user=galera &

 

MariaDB root 에 대한 Password 셋팅

./bin/mysqladmin -S /tmp/galera.sock -u root password 'galera'

 

Anonymous’ 계정 삭제

./bin/mysql -S /tmp/galera.sock  -uroot pgalera

usemysql;

drop user ''@'localhost';

drop user ''@'mari1';

 

Cluster 에서 각 노드가 사용할 계정을 생성

grant all privileges on *.* to 'root'@'172.18.174.161' identified by 'galera';

grant all privileges on *.* to 'root'@'172.18.174.162' identified by 'galera';

grant all privileges on *.* to 'root'@'172.18.174.163' identified by 'galera';

 

MariaDB [mysql]> show status like '%wsrep%';

+----------------------------+--------------------------------------+

| Variable_name              | Value                                |

+----------------------------+--------------------------------------+

| wsrep_local_state_uuid     | 71d5b770-e85a-11e2-0800-b9c6f9644dae |

| wsrep_protocol_version     | 4                                    |

| wsrep_last_committed       | 6                                    |

| wsrep_replicated           | 6                                    |

| wsrep_replicated_bytes     | 2650                                 |

| wsrep_received             | 2                                    |

| wsrep_received_bytes       | 139                                  |

| wsrep_local_commits        | 0                                    |

| wsrep_local_cert_failures  | 0                                    |

| wsrep_local_bf_aborts      | 0                                    |

| wsrep_local_replays        | 0                                    |

| wsrep_local_send_queue     | 0                                    |

| wsrep_local_send_queue_avg | 0.000000                             |

| wsrep_local_recv_queue     | 0                                    |

| wsrep_local_recv_queue_avg | 0.500000                             |

| wsrep_flow_control_paused  | 0.000000                             |

| wsrep_flow_control_sent    | 0                                    |

| wsrep_flow_control_recv    | 0                                    |

| wsrep_cert_deps_distance   | 1.000000                             |

| wsrep_apply_oooe           | 0.000000                             |

| wsrep_apply_oool           | 0.000000                             |

| wsrep_apply_window         | 1.000000                             |

| wsrep_commit_oooe          | 0.000000                             |

| wsrep_commit_oool          | 0.000000                             |

| wsrep_commit_window        | 1.000000                             |

| wsrep_local_state          | 4                                    |

| wsrep_local_state_comment  | Synced                               |

| wsrep_cert_index_size      | 3                                    |

| wsrep_causal_reads         | 0                                    |

| wsrep_incoming_addresses   | 172.18.174.161:3307                  |

| wsrep_cluster_conf_id      | 1                                    |

| wsrep_cluster_size         | 1                                    |

| wsrep_cluster_state_uuid   | 71d5b770-e85a-11e2-0800-b9c6f9644dae |

| wsrep_cluster_status       | Primary                              |

| wsrep_connected            | ON                                   |

| wsrep_local_index          | 0                                    |

| wsrep_provider_name        | Galera                               |

| wsrep_provider_vendor      | Codership Oy <info@codership.com>    |

| wsrep_provider_version     | 23.2.4(r147)                         |

| wsrep_ready                | ON                                   |

+----------------------------+--------------------------------------+

40 rows in set (0.00 sec)

 

wsrep_cluster_size = 1, wsrep_ready = on 이면 이상없이 구성 완료한 것이다.

 

wsrep_cluster_size Cluster 를 구성하는 노드 수를 의미하는 것으로 노드를 추가하게 되면

값이 증가한다.

 

D.     Adding Cluster nodes

Cluster Node 의 추가 작업은 앞서 살펴 본 ‘C’ 와 동일하다.

 

Galera 를 설치하고, MariaDB 를 설치한다.

이후 로컬 장비에 맞게 configuration file 을 셋팅을 하는데 여기서 주의할 variable 은 다음과 같다.

 

wsrep_sst_recieve_address

 

최초에는 gscomm:// 으로 셋팅했다가 이후 변경한다.

다시 말해 C 와 동일한 스텝을 다 밟은 후 다음과 같은 과정을 수행한다.

 

n  MariaDB Shutdown

n  Configuration File 수정

n  Startup

 

다만 C 스텝에서 수행이 필요 없는 부분은 최초 startup 이후 보안을 위해 수행하는 작업들이다.

이러한 DB 에 대한 변경들은 Cluster 에 추가되면 Donor 로부터 데이터를 다시 복제 받기 때문에

생략해도 된다. (단 계정 생성은 동일하게 진행한다.)

 

아래의 내용은 configuration file 을 적절하게 수정한 이후 최초 startup 이후를 다루고 있다.

 

MariaDB shutdown 이후 ./conf/my.cnf 를 다음과 같이 수정한다.

 

wsrep_cluster_address='gcomm://' è 'gcomm://172.18.174.161'

 

위 파라미터는 Donor node 를 가리킨다.

 

이후 Startup 을 실시한 후 Variables 을 확인한다.

 

MariaDB [(none)]> show status like '%wsrep_cluster_size%';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| wsrep_cluster_size | 2     |

+--------------------+-------+

 

정상적으로 노드가 추가되었음을 확인하였다.

 

위와 같은 방법으로 노드 추가를 반복한다.

MariaDB Galera Cluster 는 노드를 홀수 구성해야 한다.

단 짝수 구성시 Brain-Split 을 회피하기 위해 gabd 라는 데몬을 추가 셋팅한다.

 

세번째 노드까지 구성하고 나면 wsrep_cluster_address 를 모든 노드가 다른 노드를 보도록 수정한다.

특히 첫번째 노드의 ‘gscomm://’ 상태는 최초 구성시에만 사용되는 값으로 반드시 수정해야 한다.

 

수정 방법은 다음을 반복한다.

 

n  set global wsrep_cluster_address=gcomm://???.???.???.???

n  ./bin/conf/my.cnf wsrep_cluster_address 값을 수정

 

5.    Challenges for the future

문서에서 언급한 내용 뿐만 아니라 다음의 내용들에 대한 고려가 필요하다.

 

A.     USING REPLICATION THROUGH SSL

MariaDB Galera Cluster 도 노드와 노드를 잇는 건 Replication 에서 출발한다.

노드와 노드 간의 연결에 대해 보안을 강화하는 내용이다.

 

B.     WHEN DO WE USE GARBD

노드를 짝수로 구성할 때 brain-split 을 막기위해 추가적으로 실행하는 데몬이다.

 

C.     Setting HAProxy on Galera Cluster

MariaDB Galera Cluster High Availability 를 달성하기 위한 OPEN Source 프로그램이다.

 

D.     Using xtabackup

wsrep_sst_method 의 옵션으로 mysqldump | xtrabackup 을 사용할 수 있다.

각 옵션은 독자적인 특징들이 있으며 여기서는 mysqldump 를 사용하였다.

xtrabackup 을 사용하려면 xtrabackup (percona) 를 설치해야 한다.

 

6.    REFERENCES

A.     codership | http://codership.com/products/galera_replication

B.     MariaDB | https://downloads.mariadb.org/mariadb-galera/5.5.29/

C.     MariaDB Galera Master / Master Replication on Ubuntu 12.04 HOWTO |

http://edin.no-ip.com/blog/hswong3i/mariadb-galera-mastermaster-replication-ubuntu-12-04-howto

D.     MySQL Multi-Master Replication with Galera

http://www.sebastien-han.fr/blog/2012/04/01/mysql-multi-master-replication-with-galera/