[MySQL - Orchestrator 구축] part 1

Orchestrator란? 
MySQL용 복제 토폴로지 관리자로써 고가용성 및 복제 관리 툴입니다. 체인을 위아래로 훑으면서 마스터와 슬레이브를 찾아 MySQL 환경의 복제 토폴로지를 검색하는 기능을 제공합니다. 또한 GUI를 통해 복제 토폴로지를 리팩터링하는 데도 사용할 수 있는데, 드래그 앤 드롭 인터페이스를 사용해서 슬레이브를 마스터로 승격할 수 있습니다. 
상태 개념을 사용해서 올바른 복구 방법을 지능적으로 선택하고 사용할 적당한 마스터 승격 프로세스를 결정하므로 노드에 장애가 발생할 경우 복구를 지원합니다.
 
 
Orchestrator 기능 
복제 트리의 토폴로지 및 상태를 자동으로 감지하고 모니터링합니다.
GUI, CLI 또는 API를 사용하여 상태를 확인하고 작업을 수행할 수 있습니다.
마스터의 자동 장애 조치를 지원하고 트리의 서버가 실패할 경우 수동 또는 자동으로 복제 트리를 수정할 수 있습니다.
MySQL의 특정 버전이나 특징(MySQL, Percona Server, MariaDB 또는 MaxScale binlog 서버)에 의존하지 않습니다.
Orchestrator는 단일 마스터 -> 슬레이브에서 수백 대의 서버로 구성된 복잡한 다중 계층 복제 트리에 이르기까지 다양한 유형의 토폴로지를 지원합니다.
Orchestrator는 토폴로지를 변경할 수 있으며 해당 시점의 상태에 따라 변경합니다. 데이터베이스 토폴로지에 해당하는 것으로 구성을 정의할 필요가 없습니다.
GUI는 상태를 보고할 뿐만 아니라 웹 인터페이스에서 드래그 앤 드롭을 수행하여 복제를 변경할 수 있는 더 멋진 기능 중 하나입니다(물론 CLI 및 API를 통해 이 외에도 훨씬 더 많은 작업을 수행할 수 있음).
 
 
데이터베이스 서버 설치 요구 사항
Orchestrator 는 데이터베이스 서버에 연결하기 위해 제한된 권한( SUPER , PROCESS , REPLICATION SLAVE , RELOAD )을 가진 MySQL 사용자만 필요 합니다. 이러한 권한으로 노드의 복제 상태를 확인하고 필요한 경우 복제 변경을 수행할 수 있습니다. 
binlog 파일 위치, MySQL&MariaDB GTID, Pseudo GTID 및 Binlog 서버와 같은 다양한 복제 방법을 지원합니다.
데이터베이스 서버에 추가 소프트웨어를 설치할 필요가 없습니다.

 

 

 

테스트 환경
Hostname
IP
OS Version
DB Version
master
192.168.100.35
CentOS 7.3
MySQL 8.0.28
slave
192.168.100.36
CentOS 7.3
MySQL 8.0.28
orchestrator
192.168.100.37
CentOS 7.3
MySQL 8.0.28
사용 포트 : 3306(DB통신) (Orchestrator),  3000(Orchestrator 웹 기본 포트)

 

 

 

■ MySQL 서버 설치 (master, slave) 및 replication
-Orchestrator 구성 에서 GTID 사용을 권장 되나 Binlog Position 사용하여 replication 구성
## my.cnf
[mysqld]
datadir=/data
socket=/tmp/mysql.sock

server_id=1
expire_logs_days=7
log_bin=mysql.bin
relay_log=mysql-relay-bin
log_slave_updates=1
relay_log_purge=1

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

log-error=/log/mariadb.log
pid-file=/log/mariadb.pid
[mysqld_safe]
log-error=/log/mariadb.log
pid-file=/log/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d




mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.28    |
+-----------+



mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.100.35
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: mysql.000002
          Read_Master_Log_Pos: 1949
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 322
        Relay_Master_Log_File: mysql.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1949
              Relay_Log_Space: 532
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: 532b1949-9d3e-11ed-ba82-f220cde25fa4
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
       Master_public_key_path:
        Get_master_public_key: 0
            Network_Namespace:
1 row in set, 1 warning (0.00 sec)

 

 

※ 사전에 Orchestrator서버에도 데이터 저장을 위해 DB가 설치되어 있어야합니다.

mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.28    |
+-----------+
1 row in set (0.00 sec

 

 

■ Orchestrator 설치(RPM 설치) (Orchestrator)

[root@orchestrator ~]# yum -y install epel-release


## 필요 패키지 설치
[root@orchestrator ~]# yum -y install ncurses ncurses-devel ncurses-libs ncurses-static openssl openssl-devel bison readline gcc gcc-c++ make cmake glibc automake numactl numactl-devel libaio libaio-devel curl jq oniguruma

 

 

※ Orchestrator DB 유저 생성
MySQL 에 접속하기 위한 유저 와 Repository 에 사용하는 계정을 생성
 
■ MySQL 유저 생성 (Master)
DB -> Orchestrator에 접속하여 컨트롤 및 모니터링 용도를 위한 유저를 생성
mysql> CREATE USER 'orchestrator'@'%' IDENTIFIED BY 'orchestrator';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD ON *.* TO 'orchestrator'@'%';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT SELECT ON mysql.slave_master_info TO 'orchestrator'@'%';
Query OK, 0 rows affected (0.00 sec)

 

 

■ Repository 접속을 위한 Topology 계정 생성 (Orchestrator)
Orchestrator 에서 토폴로지 정보 등을 저장하고 조회하는데 사용하는 Repository 용 DB가 필요하기 때문에 MySQL에 논리 database와 유저 생성
mysql> CREATE DATABASE IF NOT EXISTS orchestrator;

mysql> CREATE USER 'orchestrator'@'127.0.0.1' IDENTIFIED BY 'orchestrator';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON `orchestrator`.* TO 'orchestrator'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)

 

 

■ Orchestrator 패키지 설치 (Orchestrator)
Download URL : https://github.com/openark/orchestrator/releases
 

Releases · openark/orchestrator

MySQL replication topology management and HA. Contribute to openark/orchestrator development by creating an account on GitHub.

github.com

[root@orchestrator ~]# rpm -ivh https://github.com/openark/orchestrator/releases/download/v3.2.6/orchestrator-3.2.6-1.x86_64.rpm
Retrieving https://github.com/openark/orchestrator/releases/download/v3.2.6/orchestrator-3.2.6-1.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:orchestrator-1:3.2.6-1           ################################# [100%]

 

 

 

■ orchestrator.conf.json 컨피그 수정(Orchestrator)

[root@orchestrator ~]# cd /usr/local/orchestrator/

[root@orchestrator orchestrator]# cp orchestrator-sample.conf.json orchestrator.conf.json

[root@orchestrator orchestrator]# vi orchestrator.conf.json
[root@orchestrator orchestrator]# cat orchestrator.conf.json
...
  "MySQLTopologyUser": "orchestrator",
  "MySQLTopologyPassword": "orchestrator",
...
  "MySQLOrchestratorHost": "127.0.0.1",
  "MySQLOrchestratorPort": 3306,
  "MySQLOrchestratorDatabase": "orchestrator",
  "MySQLOrchestratorUser": "orchestrator",
  "MySQLOrchestratorPassword": "orchestrator",
...
==>오케스트레이터가 자동 복구할 수 있도록 하기 위해 위와 같이 Pseudo-GTID를 설정해야 합니다.
  "AutoPseudoGTID": true,
  "PseudoGTIDPattern": "",
...
==> 호스트를 식별하기 위해 모든 DB 서버에서 다음 구성과 일치하도록 보고서 호스트를 설정합니다.
"HostnameResolveMethod": "none",
"MySQLHostnameResolveMethod": "",



## 로그 디렉토리 => 기본 경로 /tmp

 

 

■ Hosts 등록(Orchestrator) 
Orchestrator 에서는 기본적으로 조회되는 호스트로 Orchestrator 서버에서 -> MySQL DB 로 접속을 하는 방식을 사용합니다.
그래서 Orchestrator 서버에서는 DNS 로 IP가 조회되는 환경이거나 /etc/hosts 에 각 서버의 호스트명과 IP를 입력해줘야 정상적으로 사용할 수 있습니다.
[root@orchestrator ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.100.35 master
192.168.100.36 slave
192.168.100.37 orchestrator

 

 

 

Orchestrator Start (Orchestrator)

[root@orchestrator ~]# systemctl start orchestrator.service


[root@orchestrator ~]# systemctl status orchestrator.service
● orchestrator.service - orchestrator: MySQL replication management and visualization
   Loaded: loaded (/etc/systemd/system/orchestrator.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-01-27 15:38:46 KST; 1s ago
     Docs: https://github.com/openark/orchestrator
Main PID: 78625 (orchestrator)
   CGroup: /system.slice/orchestrator.service
           └─78625 /usr/local/orchestrator/orchestrator http

Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 DEBUG Orchestrator pool SetMaxOpenConns: 128
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 DEBUG Initializing orchestrator
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO Connecting to backend 127.0.0.1:3306: maxConnections: 128, maxIdleConns: 32
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO Starting Discovery
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO Registering endpoints
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO continuous discovery: setting up
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO continuous discovery: starting
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 DEBUG Queue.startMonitoring(DEFAULT)
Jan 27 15:38:46 orchestrator orchestrator[78625]: 2023-01-27 15:38:46 INFO Starting HTTP listener on :3000
Jan 27 15:38:47 orchestrator orchestrator[78625]: 2023-01-27 15:38:47 INFO Not elected as active node; active node: orchestrator; polling

 

 

■ Orchestrator 웹 접속
웹 브라우저에서 http://ip:3000 으로 접속을 합니다.

 

 

■ Master 노드 등록
Clusters -> Discover -> Master IP등록

 

 

■ Dashborad 확인
Clusters -> Dashboard
Dashboard 에는 Discovery 된 정보가 표기되며, Master MySQL Node 의 hostname 과 Instance 에 Master 와 Slave 노드를 포함한 수가 기재되어 있습니다.

 

 

■ 구조 확인
Hostname(Master) 클릭시 아래와같이 DB구조에 대해서 나옵니다.

 

 

■ 상세정보 확인
해당 노드의 톱니바퀴 모양 클릭시 노드에 대한 상세 정보 확인 가능합니다.
<Master>

 

<Slave>

 

 

 

참고