차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
mysql_mariadb_galera_cluster [2021/01/27 01:40] – 만듦 koov | mysql_mariadb_galera_cluster [2021/01/27 02:12] (현재) – koov | ||
---|---|---|---|
줄 1: | 줄 1: | ||
====== MySQL/ | ====== MySQL/ | ||
- | + | | |
- | DBMS 중에 가장 많이 사용되고 있는 것은 무료로 사용할 수 있는 MySQL이지 않을까 한다. 웹 서비스의 규모가 커지다보니 컴퓨팅 리소스도 많이 필요하게되고 이중화도 필요한 부분이 생기게되었다. 많은 이중화 솔루션 중에 '' | + | |
- | + | | |
- | {{ : | + | |
- | + | ||
- | __MySQL Cluster CGE의 '' | + | |
- | + | ||
- | 또한, '' | + | |
- | + | ||
- | + | ||
- | ===== Galera Cluster의 기능 ===== | + | |
- | ==== 장점 ==== | + | |
- | | + | |
- | * '' | + | |
- | * 장애 조치(Failover)가 없기 때문에 서비스에 연속성을 유지할 수 있다. | + | |
- | * '' | + | |
- | * 모든 노드가 읽기/ | + | |
- | * 자동 노드 프로비저닝이 가능하다. | + | |
- | ==== 단점 ==== | + | |
- | * 모든 노드가 동일한 상태를 유지하기 때문에 노드간 분기 된 데이터를 구성할 수 없다. | + | |
- | * 모든 서버 노드에 동일한 데이터를 유지해야하므로 저장공간이 낭비된다. | + | |
- | * 신규 노드 추가 시 데이터를 복사해야 한다.(부하) | + | |
- | + | ||
- | + | ||
- | ===== Galera Network Port ===== | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | + | ||
- | + | ||
- | ===== 구성 과정 흐름도 ===== | + | |
- | - MariaDB 설치 | + | |
- | - 노드별 설정 | + | |
- | - 최초 노드서버 Clustering 초기화 | + | |
- | - 노드 Cluster에 추가 | + | |
- | - Clustering 확인 | + | |
- | - DB Sync 확인 | + | |
- | + | ||
- | ===== MariaDB Clustering 구성 환경 ===== | + | |
- | * OS : CentOS-7.3-64 | + | |
- | * DB : MariaDB 10.2 | + | |
- | * Server One IP : 10.41.226.226 | + | |
- | * Server Two IP : 10.41.227.100 | + | |
- | + | ||
- | 실 구축이 아닌 Test용으로 구성하기때문에 방화벽은 in/out 모두 오픈하여 진행하였다. 오픈해야하는 Port정보는 Part 1에서 확인이 가능합니다. 또한 '' | + | |
- | + | ||
- | + | ||
- | ===== Install MariaDB ===== | + | |
- | MariaDB 공식사이트에 들어가면 아주 진철하게 설치하는 방법이 소개되어 있다. | + | |
- | + | ||
- | * MariaDB Site : https:// | + | |
- | * MariaDB Repositories Download : https:// | + | |
- | + | ||
- | 나의 구성환경과 동일하게 선택하면 아래 그림과 같이 경로와 파일정보를 제공해준다. | + | |
- | + | ||
- | {{ : | + | |
- | + | ||
- | ==== MariaDB 설치 (Server One, Server Two) ==== | + | |
- | + | ||
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Repository를 생성 | + | |
- | [root@galera-01 ~]# vi / | + | |
- | + | ||
- | + | ||
- | # MariaDB.repo 정보 | + | |
- | # MariaDB 10.2 CentOS repository list - created 2020-06-04 00:40 UTC | + | |
- | # http:// | + | |
- | [mariadb] | + | |
- | name = MariaDB | + | |
- | baseurl = http:// | + | |
- | gpgkey=https:// | + | |
- | gpgcheck=1 | + | |
- | + | ||
- | + | ||
- | # Install MariaDB | + | |
- | [root@galera-01 ~]# yum install MariaDB-server MariaDB-client | + | |
- | ======================================================================================================== | + | |
- | | + | |
- | ======================================================================================================== | + | |
- | Installing: | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | Installing for dependencies: | + | |
- | | + | |
- | | + | |
- | galera | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | Updating for dependencies: | + | |
- | | + | |
- | | + | |
- | + | ||
- | Transaction Summary | + | |
- | ======================================================================================================== | + | |
- | + | ||
- | + | ||
- | # MariaDB version 확인 | + | |
- | [root@galera-01 ~]# mysql --version | + | |
- | mysql Ver 15.1 Distrib 10.2.32-MariaDB, | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ====== MariaDB Setup Root (Server One, Server Two) ====== | + | |
- | MariaDB를 시작하고 Setup을 진행한다. Setting이 완료되면 DB를 Stop해준다. | + | |
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Start MariaDB | + | |
- | [root@galera-01 ~]# service mysql start | + | |
- | Starting mysql (via systemctl): | + | |
- | [root@galera-01 ~]# mysql_secure_installation | + | |
- | + | ||
- | + | ||
- | # Setting | + | |
- | Enter current password for root (enter for none): | + | |
- | OK, successfully used password, moving on... | + | |
- | + | ||
- | Set root password? [Y/n] y | + | |
- | New password: | + | |
- | Re-enter new password: | + | |
- | Password updated successfully! | + | |
- | Reloading privilege tables.. | + | |
- | ... Success! | + | |
- | + | ||
- | | + | |
- | ... Success! | + | |
- | + | ||
- | | + | |
- | ... skipping. | + | |
- | + | ||
- | | + | |
- | - Dropping test database... | + | |
- | ... Success! | + | |
- | - Removing privileges on test database... | + | |
- | ... Success! | + | |
- | + | ||
- | | + | |
- | ... Success! | + | |
- | + | ||
- | | + | |
- | + | ||
- | + | ||
- | # Stop MariaDB | + | |
- | [root@galera-01 ~]# service mysql stop | + | |
- | Stopping mysql (via systemctl): | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== Galera Cluster | + | |
- | Galera Cluster를 처음으로 | + | |
- | ''/ | + | |
- | + | ||
- | ==== Node1(Server One) Galera Cluster 설정 ==== | + | |
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Config node1(Server One) galera clutser | + | |
- | [root@galera-01 ~]# vi / | + | |
- | + | ||
- | [galera] | + | |
- | # Mandatory settings | + | |
- | wsrep_on=ON | + | |
- | wsrep_provider=/ | + | |
- | wsrep_cluster_address=' | + | |
- | wsrep_cluster_name=' | + | |
- | wsrep_node_address=' | + | |
- | wsrep_node_name=' | + | |
- | wsrep_sst_method=rsync | + | |
- | binlog_format=row | + | |
- | default_storage_engine=InnoDB | + | |
- | innodb_autoinc_lock_mode=2 | + | |
- | bind-address=0.0.0.0 | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== Node2(Server Two) Galera Cluster 설정 ==== | + | |
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Config node2(Server Two) galera clutser | + | |
- | [root@galera-02 ~]# vi / | + | |
- | + | ||
- | [galera] | + | |
- | # Mandatory settings | + | |
- | wsrep_on=ON | + | |
- | wsrep_provider=/ | + | |
- | wsrep_cluster_address=' | + | |
- | wsrep_cluster_name=' | + | |
- | wsrep_node_address=' | + | |
- | wsrep_node_name=' | + | |
- | wsrep_sst_method=rsync | + | |
- | binlog_format=row | + | |
- | default_storage_engine=InnoDB | + | |
- | innodb_autoinc_lock_mode=2 | + | |
- | bind-address=0.0.0.0 | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== Galera Clustering 작업 ===== | + | |
- | 초기 설정이 완료되었으니 Node1,2를 Clustering을하여 DB가 잘 연동되었는지 확인해보겠습니다. | + | |
- | 확인 후에 추가로 Node1(Server One)의 초기설정을 변경해야하는 중요한 작업이 있으니 꼭 확인해야합니다. 이 부분은 뒤에서 좀 더 자세히 설명하겠습니다. | + | |
- | + | ||
- | ==== Node 1 Galera Cluster 초기화 ==== | + | |
- | 앞서 Node 1,2 모두 초기 설정을 완료했으니 node1에서 cluster를 초기화하는 작업이 먼저 필요합니다. | + | |
- | + | ||
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Galera Cluster 초기화 | + | |
- | [root@galera-01 ~]# service mysql start --wsrep-new-cluster | + | |
- | Starting mysql (via systemctl): | + | |
- | + | ||
- | # node1(Server One) 상태 확인 | + | |
- | [root@galera-01 ~]# ps -ef | grep mysql | + | |
- | mysql | + | |
- | --basedir=/ | + | |
- | --datadir=/ | + | |
- | --plugin-dir=/ | + | |
- | --user=mysql | + | |
- | --wsrep_on=ON | + | |
- | --wsrep_provider=/ | + | |
- | --log-error=/ | + | |
- | --pid-file=/ | + | |
- | --wsrep_start_position=a4fe716e-a609-11ea-95ab-fa16ac4cfe80: | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ==== Node 2 Galera Cluster 추가 ==== | + | |
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Galera Cluster 초기화 | + | |
- | [root@galera-02 ~]# service mysql start | + | |
- | Starting mysql (via systemctl): | + | |
- | + | ||
- | # node2(Server Two) 상태 확인 | + | |
- | [root@galera-02 ~]# ps -ef | grep mysql | + | |
- | mysql | + | |
- | --basedir=/ | + | |
- | --datadir=/ | + | |
- | --plugin-dir=/ | + | |
- | --user=mysql | + | |
- | --wsrep_on=ON | + | |
- | --wsrep_provider=/ | + | |
- | --log-error=/ | + | |
- | --pid-file=/ | + | |
- | --wsrep_start_position=00000000-0000-0000-0000-000000000000: | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== Clustering 상태 확인 ===== | + | |
- | MariaDB에 접속하여 | + | |
- | + | ||
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # MariaDB 접속 | + | |
- | [root@galera-01 ~]# mysql -u root -p | + | |
- | Enter password: | + | |
- | Welcome to the MariaDB monitor. | + | |
- | Your MariaDB connection id is 12 | + | |
- | Server version: 10.2.32-MariaDB MariaDB Server | + | |
- | + | ||
- | Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. | + | |
- | + | ||
- | Type ' | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | +-------------------------------+---------------------------------------+ | + | |
- | | Variable_name | + | |
- | +-------------------------------+---------------------------------------+ | + | |
- | | wsrep_cluster_status | + | |
- | | wsrep_connected | + | |
- | | wsrep_incoming_addresses | + | |
- | | wsrep_local_state_comment | + | |
- | | wsrep_provider_name | + | |
- | | wsrep_ready | + | |
- | +-------------------------------+---------------------------------------+ | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== DB 생성으로 데이터 sync 확인 ===== | + | |
- | node1에서 galeradb database를 생성하여 실시간으로 node2에서도 생성되었는지 확인해보자. | + | |
- | + | ||
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # node1에서 database 생성 | + | |
- | [root@galera-01 ~]# mysql -u root -p | + | |
- | Enter password: | + | |
- | Welcome to the MariaDB monitor. | + | |
- | Your MariaDB connection id is 12 | + | |
- | Server version: 10.2.32-MariaDB MariaDB Server | + | |
- | + | ||
- | Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. | + | |
- | + | ||
- | Type ' | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | +--------------------+ | + | |
- | | Database | + | |
- | +--------------------+ | + | |
- | | information_schema | | + | |
- | | mysql | | + | |
- | | performance_schema | | + | |
- | +--------------------+ | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | Query OK, 1 row affected (0.00 sec) | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | +--------------------+ | + | |
- | | Database | + | |
- | +--------------------+ | + | |
- | | galeradb | + | |
- | | information_schema | | + | |
- | | mysql | | + | |
- | | performance_schema | | + | |
- | +--------------------+ | + | |
- | 4 rows in set (0.00 sec) | + | |
- | + | ||
- | # node2에 sync되어 생성되었는지 확인 | + | |
- | [root@galera-02 ~]# mysql -u root -p | + | |
- | Enter password: | + | |
- | Welcome to the MariaDB monitor. | + | |
- | Your MariaDB connection id is 13 | + | |
- | Server version: 10.2.32-MariaDB MariaDB Server | + | |
- | + | ||
- | Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. | + | |
- | + | ||
- | Type ' | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | MariaDB [(none)]> | + | |
- | MariaDB [(none)]> | + | |
- | +--------------------+ | + | |
- | | Database | + | |
- | +--------------------+ | + | |
- | | information_schema | | + | |
- | | mysql | | + | |
- | | performance_schema | | + | |
- | +--------------------+ | + | |
- | 3 rows in set (0.00 sec) | + | |
- | + | ||
- | MariaDB [(none)]> | + | |
- | +--------------------+ | + | |
- | | Database | + | |
- | +--------------------+ | + | |
- | | galeradb | + | |
- | | information_schema | | + | |
- | | mysql | | + | |
- | | performance_schema | | + | |
- | +--------------------+ | + | |
- | 4 rows in set (0.00 sec) | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== *중요* 완료 후 node1(Server One) 설정 변경 ===== | + | |
- | + | ||
- | 모든 Test가 완료되었습니다. 하지만 아직 마지막으로 중요한 작업이 남아있습니다. 현 상태로 두게되면 DB를 restart했을때 에러가 발생하게 됩니다. 그 이유는 node1에 '' | + | |
- | <WRAP prewrap> | + | |
- | <code bash> | + | |
- | # Config node1(Server One) galera clutser | + | |
- | [root@galera-01 ~]# vi / | + | |
- | + | ||
- | [galera] | + | |
- | # Mandatory settings | + | |
- | wsrep_on=ON | + | |
- | wsrep_provider=/ | + | |
- | wsrep_cluster_address=' | + | |
- | wsrep_cluster_name=' | + | |
- | wsrep_node_address=' | + | |
- | wsrep_node_name=' | + | |
- | wsrep_sst_method=rsync | + | |
- | binlog_format=row | + | |
- | default_storage_engine=InnoDB | + | |
- | innodb_autoinc_lock_mode=2 | + | |
- | bind-address=0.0.0.0 | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | ===== 출처 ===== | + | |
- | * https:// | + |