MySQL

[MySQL] Group Replication

bbugge 2025. 1. 12. 13:14

# Linux version : 5.15.0-3.60.5.1.el9uek.aarch64
# mysql version : 9.1.0-commercial

 

 

# 10.0.2.10 cluster1
# 10.0.2.20 cluster2
# 10.0.2.30 cluster3

# cluster1,cluster2,cluster3에 mysql이 설치 및 실행되어있다고 가정하고 진행


[root@localhost ~]# vi /etc/hosts
10.0.2.10 cluster1
10.0.2.20 cluster2
10.0.2.30 cluster3
[root@localhost ~]# mysql -ivh mysql-router-commercial-9.1.0-1.1.el9.aarch64.rpm mysql-shell-commercial-9.1.0-1.1.el9.aarch64.rpm
ERROR 2005 (HY000): Unknown MySQL server host 'mysql-router-commercial-9.1.0-1.1.el9.aarch64.rpm' (-2)
[root@localhost ~]# rpm -ivh mysql-shell-commercial-9.1.0-1.1.el9.aarch64.rpm mysql-router-commercial-9.1.0-1.1.el9.aarch64.rpm
경고: mysql-shell-commercial-9.1.0-1.1.el9.aarch64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
준비 중...                         ################################# [100%]
Updating / installing...
   1:mysql-router-commercial-9.1.0-1.1################################# [ 50%]
   2:mysql-shell-commercial-9.1.0-1.1.################################# [100%]
[root@localhost ~]#
[root@localhost ~]#

# 1,2,3 node 다 수행할 것. ====================================================================

[root@localhost ~]# mysqlsh
Please provide the password for 'root@/mysql%2Fmysql.sock': ********
Save password for 'root@/mysql%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No):
MySQL Shell 9.1.0-commercial

Copyright (c) 2016, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a Classic session to 'root@/mysql%2Fmysql.sock'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 8
Server version: 9.1.0-commercial MySQL Enterprise Server - Commercial
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  JS > \sql

 MySQL  localhost  SQL > install plugin group_replication soname 'group_replication.so'; 
 MySQL  localhost  SQL > install plugin clone soname 'mysql_clone.so';
 MySQL  localhost  JS > dba.configureInstance("root@localhost:3306");  
Please provide the password for 'root@localhost:3306': ********
Save password for 'root@localhost:3306'? [Y]es/[N]o/Ne[v]er (default No):
Configuring local MySQL instance listening at port 3306 for use in an InnoDB Cluster...

This instance reports its own address as localhost.localdomain:3306
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.

ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection from all instances must be created to manage the cluster.

1) Create remotely usable account for 'root' with same grants and password
2) Create a new admin account for InnoDB Cluster with minimal required grants
3) Ignore and continue
4) Cancel

Please select an option [1]: 2
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: cluster
Password for new account: ******
Confirm password: ******

applierWorkerThreads will be set to the default value of 4.

NOTE: Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable                                | Current Value   | Required Value  | Note                                                                              |
+--------------------------+---------------+----------------+--------------------------------------------------+
| enforce_gtid_consistency | OFF                    | ON                      | Update read-only variable and restart the server    |
| gtid_mode                           | OFF                    | ON                      | Update read-only variable and restart the server    |
+--------------------------+---------------+----------------+--------------------------------------------------+

Some variables need to be changed, but cannot be done dynamically on the server.
Do you want to perform the required configuration changes? [y/n]: y
Do you want to restart the instance after configuring it? [y/n]: y

Creating user cluster@%.
Account cluster@% was successfully created.

Configuring instance...
The instance 'localhost.localdomain:3306' was configured to be used in an InnoDB Cluster.
Restarting MySQL...
NOTE: MySQL server at localhost.localdomain:3306 was restarted.

# =====================================================================================
 MySQL  localhost  JS >
 MySQL  localhost  JS >
 MySQL  localhost  JS >
 MySQL  localhost  JS > \connect cluster@cluster1:3306
Creating a session to 'cluster@cluster1:3306'
Please provide the password for 'cluster@cluster1:3306': *******
Save password for 'cluster@cluster1:3306'? [Y]es/[N]o/Ne[v]er (default No):
Fetching schema names for auto-completion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 19
Server version: 9.1.0-commercial MySQL Enterprise Server - Commercial
No default schema selected; type \use <schema> to set one.
 MySQL  cluster1:3306 ssl  JS > dba.createCluster("testCluster"); 
A new InnoDB Cluster will be created on instance 'cluster1:3306'.

Validating instance configuration at cluster1:3306...

This instance reports its own address as cluster1:3306

Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'cluster1:3306'. Use the localAddress option to override.

* Checking connectivity and SSL configuration...

Creating InnoDB Cluster 'testCluster' on 'cluster1:3306'...

Adding Seed Instance...
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to
one server failure.

 MySQL  cluster1:3306 ssl  JS > var cluster = dba.getCluster();
 MySQL  cluster1:3306 ssl  JS > cluster.status();
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "cluster1:3306",
        "ssl": "REQUIRED",
        "status": "OK_NO_TOLERANCE",
        "statusText": "Cluster is NOT tolerant to any failures.",
        "topology": {
            "cluster1:3306": {
                "address": "cluster1:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "9.1.0"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "cluster1:3306"
}
 MySQL  cluster1:3306 ssl  JS > 
 MySQL  cluster1:3306 ssl  JS > 
 MySQL  cluster1:3306 ssl  JS > 
 MySQL  cluster1:3306 ssl  JS > 
 MySQL  cluster1:3306 ssl  JS > cluster.addInstance("cluster@cluster2:3306");  -- 2 node addInstance

NOTE: The target instance 'cluster2:3306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental state recovery can correctly provision it.
The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'cluster2:3306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.

The incremental state recovery may be safely used if you are sure all updates ever executed in the cluster were done with GTIDs enabled, there are no purged transactions and the new instance contains the same GTID set as the cluster or a subset of it. To use this method by default, set the 'recoveryMethod' option to 'incremental'.


Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone): C
Validating instance configuration at cluster2:3306...

This instance reports its own address as cluster2:3306

Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'cluster2:3306'. Use the localAddress option to override.

* Checking connectivity and SSL configuration...

A new instance will be added to the InnoDB Cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Adding instance to the cluster...

Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
Clone based state recovery is now in progress.

NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back.

* Waiting for clone to finish...
NOTE: cluster2:3306 is being cloned from cluster1:3306
** Stage DROP DATA: Completed
** Clone Transfer
    FILE COPY  ############################################################  100%  Completed
    PAGE COPY  ############################################################  100%  Completed
    REDO COPY  ############################################################  100%  Completed

NOTE: cluster2:3306 is shutting down...

* Waiting for server restart... ready
* cluster2:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 74.72 MB transferred in about 1 second (~74.72 MB/s)

State recovery already finished for 'cluster2:3306'

The instance 'cluster2:3306' was successfully added to the cluster.

 MySQL  cluster1:3306 ssl  JS > cluster.addInstance("cluster@cluster3:3306");  -- 3 node addInstance

NOTE: The target instance 'cluster3:3306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental state recovery can correctly provision it.
The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'cluster3:3306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.

The incremental state recovery may be safely used if you are sure all updates ever executed in the cluster were done with GTIDs enabled, there are no purged transactions and the new instance contains the same GTID set as the cluster or a subset of it. To use this method by default, set the 'recoveryMethod' option to 'incremental'.


Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone): C
Validating instance configuration at cluster3:3306...

This instance reports its own address as cluster3:3306

Instance configuration is suitable.
NOTE: Group Replication will communicate with other members using 'cluster3:3306'. Use the localAddress option to override.

* Checking connectivity and SSL configuration...

A new instance will be added to the InnoDB Cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Adding instance to the cluster...

Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
Clone based state recovery is now in progress.

NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back.

* Waiting for clone to finish...
NOTE: cluster3:3306 is being cloned from cluster1:3306
** Stage DROP DATA: Completed
** Clone Transfer
    FILE COPY  ############################################################  100%  Completed
    PAGE COPY  ############################################################  100%  Completed
    REDO COPY  ############################################################  100%  Completed

NOTE: cluster3:3306 is shutting down...

* Waiting for server restart... ready
* cluster3:3306 has restarted, waiting for clone to finish...
** Stage RESTART: Completed
* Clone process has finished: 74.71 MB transferred in about 1 second (~74.71 MB/s)

State recovery already finished for 'cluster3:3306'

The instance 'cluster3:3306' was successfully added to the cluster.

 MySQL  cluster1:3306 ssl  JS > cluster.status();  -- 생성된 cluster 확인
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "cluster1:3306",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "cluster1:3306": {
                "address": "cluster1:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "9.1.0"
            },
            "cluster2:3306": {
                "address": "cluster2:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "9.1.0"
            },
            "cluster3:3306": {
                "address": "cluster3:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "9.1.0"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "cluster1:3306"
}
 MySQL  cluster1:3306 ssl  JS >
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mkdir /mysql/mysqlrouter
[root@localhost ~]# chown mysql:mysql /mysql/mysqlrouter
[root@localhost ~]# mysqlrouter --bootstrap cluster@cluster1:3306 --name myrouter1 --directory /mysql/myrouter --account myrouter --user mysql
Please enter MySQL password for cluster:
# Bootstrapping MySQL Router 9.1.0 (MySQL Enterprise - Commercial) instance at '/mysql/myrouter'...

Please enter MySQL password for myrouter:
- Creating account(s) (only those that are needed, if any)
- Verifying account (using it to run SQL queries that would be run by Router)
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /mysql/myrouter/mysqlrouter.conf

# MySQL Router 'myrouter1' configured for the InnoDB Cluster 'testCluster'

After this MySQL Router has been started with the generated configuration

    $ mysqlrouter -c /mysql/myrouter/mysqlrouter.conf

InnoDB Cluster 'testCluster' can be reached by connecting to:

## MySQL Classic protocol

- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447
- Read/Write Split Connections: localhost:6450

## MySQL X protocol

- Read/Write Connections: localhost:6448
- Read/Only Connections:  localhost:6449

[root@localhost ~]#
[root@localhost ~]# cat /mysql/myrouter/mysqlrouter.conf
# File automatically generated during MySQL Router bootstrap
[DEFAULT]
name=myrouter1
user=mysql
logging_folder=/mysql/myrouter/log
runtime_folder=/mysql/myrouter/run
data_folder=/mysql/myrouter/data
keyring_path=/mysql/myrouter/data/keyring
master_key_path=/mysql/myrouter/mysqlrouter.key
connect_timeout=5
read_timeout=30
dynamic_state=/mysql/myrouter/data/state.json
client_ssl_cert=/mysql/myrouter/data/router-cert.pem
client_ssl_key=/mysql/myrouter/data/router-key.pem
client_ssl_mode=PREFERRED
server_ssl_mode=PREFERRED
server_ssl_verify=DISABLED
unknown_config_option=error
max_idle_server_connections=64
router_require_enforce=1

[logger]
level=info

[metadata_cache:bootstrap]
cluster_type=gr
router_id=1
user=myrouter
metadata_cluster=testCluster
ttl=0.5
auth_cache_ttl=-1
auth_cache_refresh_interval=2
use_gr_notifications=0

[routing:bootstrap_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://testCluster/?role=PRIMARY
routing_strategy=first-available
protocol=classic

[routing:bootstrap_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://testCluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=classic

[routing:bootstrap_rw_split]
bind_address=0.0.0.0
bind_port=6450
destinations=metadata-cache://testCluster/?role=PRIMARY_AND_SECONDARY
routing_strategy=round-robin
protocol=classic
connection_sharing=1
client_ssl_mode=PREFERRED
server_ssl_mode=PREFERRED
access_mode=auto

[routing:bootstrap_x_rw]
bind_address=0.0.0.0
bind_port=6448
destinations=metadata-cache://testCluster/?role=PRIMARY
routing_strategy=first-available
protocol=x
router_require_enforce=0
client_ssl_ca=
server_ssl_key=
server_ssl_cert=

[routing:bootstrap_x_ro]
bind_address=0.0.0.0
bind_port=6449
destinations=metadata-cache://testCluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=x
router_require_enforce=0
client_ssl_ca=
server_ssl_key=
server_ssl_cert=

[http_server]
port=8443
ssl=1
ssl_cert=/mysql/myrouter/data/router-cert.pem
ssl_key=/mysql/myrouter/data/router-key.pem

[http_auth_realm:default_auth_realm]
backend=default_auth_backend
method=basic
name=default_realm

[rest_router]
require_realm=default_auth_realm

[rest_api]

[http_auth_backend:default_auth_backend]
backend=metadata_cache

[rest_routing]
require_realm=default_auth_realm

[rest_metadata_cache]
require_realm=default_auth_realm

'MySQL' 카테고리의 다른 글

[MySQL] 쿼리 프로파일링 (Query profiling)  (0) 2025.01.12
[MySQL] MySQL 성능 분석 프로시저  (0) 2025.01.12
[MySQL] 모니터링 쿼리  (0) 2024.12.21
[MySQL] MySQL Parameter  (0) 2024.11.16
[MySQL] FEDERATED (DBLINK)  (0) 2020.07.24