mysql best practice -...
Post on 06-Feb-2018
243 Views
Preview:
TRANSCRIPT
MySQL Best Practice
www . rockp lace . co . k r
r o c k P L A C E I n c . C o m p a n y I n t r o d u c t i o n
©2013 rockPLACE Inc.
Chapter 1. MySQL Overviews 1. MySQL 소개
2. MySQL Architecture
3. MySQL Storage Features
Chapter 2. MySQL Refs. Architectures 1. MySQL Replication
2. MySQL with Pacemaker + DRBD 또는 MySQL with Lifekeeper
3. MySQL Cluster(Carrier Grade Edition)
4. MySQL with OS Cluster
5. HA 구성 별 신뢰수준
6. 기타 솔루션
Chapter 3. Case Study 1. 사례 1. MySQL Replication & OS Cluster
2. 사례 2. MySQL Cluster
3. 사례 3. Private Cloud MySQL+Pacemaker+DRBD
4. 사례 4. (MySQL+MMM) * N
5. 사례 5. MySQL Multi-Zone H/A
Appendix. MySQL 5.6 NEW FEATURES
CONTENTS
>>> Chapter 1. MySQL Overviews
1. MySQL 개요
MySQL is a very fast, fully multi-threaded, multi-user SQL database server.
MySQL databases are relational.
MySQL software is Dual Licensed. GPL vs. Commercial License.
Provides transactional and non-transactional storage engines.
(pluggable storage engine)
MySQL server works in client/server or embedded systems.
A large amount of contributed MySQL software is available.
1. MySQL 소개
Chapter 1. MySQL Overviews
2. MySQL Architecture
Chapter 1. MySQL Overviews
3. MySQL Storage Engine Features
1. MySQL 개요 Chapter 1. MySQL Overviews
>>> Chapter 2. MySQL Refs. Architectures
MySQL Master
I/O Thread
SQL Thread
Writes
relay binlog
MySQL Slave
mysqld
data
index & binlogs
mysqld data binlog Replication
Queries
1. MySQL Replication
Chapter 2. MySQL Reference Architectures
Synchronous Block Replication
IP Management
Active DRBD Server
Passive DRBD Server
2-1. MySQL with Pacemaker + DRBD
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
2-1. MySQL with Pacemaker + DRBD
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
장점
단점 및 제약사항
Pacemaker(Heartbeat)을 통해 Auto-failover 가능
장애 노드 복구 후 Data auto-resynchronization
Transactional storage engines 지원
Shared-nothing 구조
Fail-over time이 30초 이내
Network latency에 의해 성능이 영향을 받는다.
Write-intensive system의 경우 부적합 할 수 있다
Synchronous Block Replication
IP Management
Active Server
Passive Server
2-2. MySQL with Lifekeeper
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
2-2. MySQL with Lifekeeper
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
장점
단점 및 제약사항
Kernel은 Redhat 5.8 이상 커널 사용 가능
Redhat 5.4 이상 버전 사용 가능, 현재 Redhat 6.0은 미지원. 6.1 이상 부터 지원 가능
최초 Disk간 Initial을 위한 오랜 시간 소요
서비스 라인과 Replication 라인은 반드시 분리해야 함
Lifekeeper내 Steeleye-Lkcheck를 통해서 장애 감지. Auto-failover 가능
장애 노드 복구 후 Data auto-resynchronization
Transactional storage engines 지원
Shared-nothing, Disk Mirrored 구조
제약은 있지만 Shared storage 사용 가능
Application/SQL Nodes
(NDB API and/or MySQL Server)
Data Nodes
Management Nodes
Clients
NDB Storage Engine
3. MySQL Cluster (Carrier Grade Edition)
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
3. MySQL Cluster (Carrier Grade Edition)
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
장점
Auto fail-over 가능
Memory based storage engine 사용으로 성능 향상 (Disk based 지원)
Cluster 동작 중 새로운 node 추가 가능(Scale-out)
Data node의 장애 복구 후 자동으로 Data resynchronization
Failover time이 없음
Active-Active 방식
Shared nothing 구조
단점 및 제약사항
대용량의 Data에는 적합하지 않음
Data 용량 이상의 Memory 필요
NDB storage engine을 사용해야만 Clustering 가능
Management node, SQL node, Data node를 분리하여 필요한 시스템 수에 따른 비용 증가
OS Cluster(RHCS, Veritas)
Active MySQL Server
Stand-by MySQL Server
Shared Storage
4. MySQL with OS cluster
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
4. MySQL with OS cluster
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
RHCS(VCS)를 통한 Auto-failover 가능
Active node의 장애 발생 시 Stand-by node가 Active되어 서비스
MySQL에서 제공되는 모든 Storage engine 사용 가능
단점 및 제약사항
Failover를 위한 RHCS나 Veritas Cluster Suite와 같은 3rd party OS 솔루션 필요
Failover time : 1min 30sec (generally)
TCO 가 매우 높다.(SAN, 3rd party solution)
장점
3. MySQL H/A 구성 종류
MySQL Cluster
99.999%
MySQL with Pacemaker + DRBD
99.99%
MySQL Replication
95.0%
MySQL with RHCS
99.95%
% 9 9 9 9 9
35 days 4 days 50 mins 5 mins 8 hours
Unmanaged
Replication Technologies
Clustering Technologies
Clustering & Geographical Redundancy
Well-Managed
Small Business
ISPs & Mainstream
Business
Data Centers
Banking Medical
Telco Military Defense
.
MySQL Cluster
MySQL + DRBD
MySQL Replication
5. HA 구성 별 신뢰수준
Chapter 2. MySQL Reference Architectures
Passive MySQL Server
Storage
6-1 기타 : MySQL with MMM
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
VIP for reads : Read-Only VIP for reads VIP for write
Active MySQL Server
Storage
Multi Master Replication
MySQL Monitoring
Read & Write Read-Only
VIP for reads VIP for write
Read & Write
Failover
6-1 기타 : MySQL with MMM
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
Master의 Active에 장애가 발생하면 기존 Passive로 Failover 진행되며 모든 서비스 IP(VIP)를 자동 이관
Replication 사용시 Auto Failover 기능이 추가된 구성
단점 및 제약사항
모든 네트워크는 동일 세그먼트(segment)에 연결되어야 함. 구성 나름이긴 하나, 일반적으로 1세트 2node 기준으로 시스템 IP 2개(접근,
Replication 전용), Write 전용 VIP, Read 전용 VIP 2개 총 7개의 IP가 필요함. IP or Host Failover 기능만 제공
장점
6-2 기타 : MySQL with MHA
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
VIP
MHA Manager
Master 감지
Replication zone
MySQL Master
MySQL Slave
MySQL Slave
장애 발생시 Master role 변경 (VIP, Replication 변경)
Failover 후 New master
6-2 기타 : MySQL with MHA
3. MySQL H/A 구성 종류 Chapter 2. MySQL Reference Architectures
Replication 서비스에서 Auto-Failover 기능 추가
Master role 및 VIP 자동 이관 지원
단점 및 제약사항
VIP 사용이 가능 해야 함
Third Party이므로 검증이 필요함
장점
Master#1
Slave Slave
Zone#1
[Cascading replication 구성]
Master#2
DRBD
Master Standby
Slave Slave
EIP
Zone#1
[Pacemaker+DRBD 구성]
DRBD
Chapter 2. MySQL Reference Architectures
6-3 기타 : Amazon EC2 EC2는 HA 클러스터 환경을 제공하지 않음
MySQL Cluster의 경우 대용량 환경에 적합하지 않으며 Oracle VM 이외의 VM환경은 Certify가 되어있지 않은 상태
MySQL with Pacemaker + DRBD로 구성 가능 – Custom으로 zone 내에서 EIP를 컨트롤하는 스크립트 작성이 필요함
MySQL Replication 구성 가능 – Read 작업을 분산 시킴으로써 부하를 나누어 처리할 수 있음
– Slave 노드를 증설하는 것으로 쉽게 Scale-out이 가능
– Cascading replication 구성을 통해 Master를 이중화하여 장애에 대응
• 기본 구성만으로는 Auto-failover 불가
>>> Chapter 3. Case Study
3. MySQL H/A 구성 종류
사례 1. MySQL Replication & OS Cluster
Chapter 3. Case Study
Replication 서비스에서 Failover 기능 추가 될 것
대용량분산처리 시스템이어야 할 것
확장에 용이할 것(scale-out)
Master 서버 이중화
Promotion DB를 통한 Failover가 실패될 경우 제 3의 서버를 Master role로 변경
부하분산과 Scale-out을 위해 Replication 구성
지역별 분산 구조로 서버 운영
Requirements
SAN
Master Standby
Slave(Pro) Slave
VIP
Shard#1
SAN
Master Standby
Slave(Pro) Slave
VIP
Shard#2
SAN
Master Standby
Slave(Pro) Slave
VIP
Shard#3
SAN
Master Standby
Slave(Pro)
VIP
Shard#4
사례 1. MySQL Replication & OS Cluster
Chapter 3. Case Study
3. MySQL H/A 구성 종류 Chapter 3. Case Study
사례 2. MySQL Cluster
Active-Active 서비스 구성
Downtime 최소화
Push 메시지 타입의 무중단 서비스 요청
적은 용량의 작지만 빠른 데이터 Read 작업 요청
Read/Write Scale-out
Requirements
4. 구축 사례
NDB
MGM
SQL SQL
MGM
DATA DATA
NDB
Heartbeat
Data
사례 2. MySQL Cluster( 6 nodes)
Chapter 3. Case Study
3. MySQL H/A 구성 종류 Chapter 3. Case Study
사례 3. Private Cloud MySQL+Pacemaker+DRBD
HA(High Availability) & TB 단위 데이터 처리
SAN Storage 대체 방안
Data Redundancy 요구
Application Level + H/W Level 장애감지 가능
Auto failover 요구
Scale-out : Replication( 1Master( HA : Pacemaker+DRBD), 3 slaves(1slave bkup))
Requirements
4. 구축 사례
사례 3. Private Cloud MySQL+Pacemaker+DRBD
Chapter 3. Case Study
DRBD
Active MySQL
Hypervisor pool 1
VIP
DRBD
Passive MySQL
Hypervisor pool 2
3. MySQL H/A 구성 종류 Chapter 3. Case Study
사례 4. (MySQL+MMM) * N
Big data 처리
Data Redundancy 확보
Read & Write Scale-out
Auto Fail-over
Fail-over시 Slave가 자동으로 변경된 Master를 인지한 후 data sync
향후 traffic 증가에 따른 scale-out 방안
Requirements
4. 구축 사례 Chapter 3. Case Study
Active MySQL
Passive MySQL
사례 4. (MySQL+MMM) * N
Multi-master Replication
Client/Web Apps
IP for system
VIP for writes1
VIP for reads1
IP for system
VIP for Reads2
MySQL Monitoring
VIP for writes1
VIP for reads1
Master role change (Passive->Active)
Fail-over
3. MySQL H/A 구성 종류 Chapter 3. Case Study
사례 5. MySQL Multi-Zone H/A(Amazon EC2)
Duplex Configuration
Multi-Zone HA : EC2 환경에서 Active / Stand-by 구성
Read Scale-out : 1 Master, 2 Slaves
Auto failover, failback
Requirements
WAS (JBOSS)
Slave Slave
Read/Write
MySQL Master @1
Chapter 3. Case Study
Replication
Read-only Read-only
Active Zone
Slave Slave
Read/Write
MySQL Master #2
Replication
Read-only Read-only
Stand-by Zone
Fail-over
Fail-back
사례 5. MySQL Multi-Zone H/A
H/A
Q&A
>>> Appendix. MySQL 5.6 NEW FEATURES
GTID(Global Transaction ID)
1. MySQL Replication Automatic failover
Chapter 4. MySQL 5.6 NEW FEATURES
3. MySQL H/A 구성 종류
1. MySQL Replication Automatic failover
Chapter 4. MySQL 5.6 NEW FEATURES
장점
Replication Automatic failover 구현
특이사항
선행조건 – Slave 사용가능
– GTID enabled
– GTID Replication 사용
– replication user 필요
– Binary logging enabled
GTID Replication 사용
autofailover.exe를 사용하여 candidates설정함 – MySQL Utilities 사용
Chapter 4. MySQL 5.6 NEW FEATURES
1. MySQL Replication Automatic failover
실습 환경 – MySQL Workbench 서버 1대
– 1Master 2 Slave MySQL replication 구성
• Configuration 필요사항
실습
gtid-mode=on enforce-gtid-consistency log-slave-updates log-bin master-info-repository=table relay-log-info-repository=table
Chapter 4. MySQL 5.6 NEW FEATURES
GTID Replication 사용 mysql$ change master to master_host=master_ip',
master_user=‘replication_id', master_password=‘password', master_auto_position=1;
autofailover.exe를 사용하여 candidates설정함 - MySQL Utilities for mysqlfailover 사용 - Mysqlfailover용 계정 사용(ID: test, Password: 1111) - $mysqlfailover --master=test:1111@master:ip:3306 --slaves=test:1111@slave1_ip:3306,test:1111@slave2_ip:3306 --discover-slaves-login=test:1111 --candidates=test:1111@cantidates_server_ip:3306 --force
1. MySQL Replication Automatic failover
3. MySQL H/A 구성 종류 Chapter 4. MySQL 5.6 NEW FEATURES
Failover 전
1. MySQL Replication Automatic failover
Chapter 4. MySQL 5.6 NEW FEATURES
Failover 후
2. Online DDL
Chapter 4. MySQL 5.6 NEW FEATURES
Test table schema
Alter 및 DDL 구문
alter table a3 add test char(10);
insert into sbtest values(NULL,0,0,'','');
update sbtest set pad='testtest' where id< 100;
delete from sbtest where id < 100;
2. Online DDL
Chapter 4. MySQL 5.6 NEW FEATURES
Session 1 – altering Session 2 – DDL
alter table a3 add test char(10);
insert into sbtest values(NULL,0,' ',' '); update sbtest set pad='testtest' where id< 100; delete from sbtest where id < 100;
5.6
5.5
top related