MySQL 8.4 : レプリケーション2026/02/17 |
|
MySQL レプリケーションの設定です。プライマリー/レプリカ型の冗長構成になります。 |
|
| [1] | |
| [2] |
レプリケーション時には、こちらに記載の通り、mysqld が自動生成した自己署名の SSL/TLS 証明書をそのまま利用します。 |
| [3] | プライマリーサーバー側で設定を変更し、必要なユーザーを作成しておきます。 |
|
root@dlp:~ #
vi /usr/local/etc/mysql/my.cnf # my.cnf が存在しない場合は以下の内容で新規作成 # 13行目 : 変更 (全てリスンする) bind-address = 0.0.0.0 # 23行目 : コメント解除して変更 (一意なサーバーID を定義) server-id = 101 # [mysqld] セクション内に追記 : クローンプラグインを有効にする plugin-load = mysql_clone.so
root@dlp:~ #
root@dlp:~ # service mysql-server restart mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.4.7 Source distribution Copyright (c) 2000, 2025, 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 '\h' for help. Type '\c' to clear the current input statement. # レプリケーション用ユーザー作成 ([password] は任意のパスワードを設定) mysql> create user 'repl_user'@'%' identified by 'password'; Query OK, 0 rows affected (0.10 sec) mysql> grant replication slave on *.* to repl_user@'%'; Query OK, 0 rows affected (0.05 sec) # クローン用ユーザー作成 ([password] は任意のパスワードを設定) mysql> create user 'clone_user'@'%' identified by 'password'; Query OK, 0 rows affected (0.07 sec) mysql> grant backup_admin on *.* to 'clone_user'@'%'; Query OK, 0 rows affected (0.06 sec) mysql> exit Bye |
| [4] | レプリカサーバー側の設定をレプリケーション用に変更します。 |
|
root@node01:~ #
vi /usr/local/etc/mysql/my.cnf # my.cnf が存在しない場合は以下の内容で新規作成 # 31行目 : 変更 (全てリスンする) bind-address = 0.0.0.0 # 23行目 : コメント解除して変更 (一意なサーバーID を定義) server-id = 102 # [mysqld] セクション内に追記 # リードオンリー read_only = 1 # 自身のホスト名を定義 report-host = node01.srv.world # リレーログファイルを定義 relay-log = node01-relay-bin relay-log-index = node01-relay-bin # クローンプラグインを有効にする plugin-load = mysql_clone.so
root@node01:~ #
root@node01:~ # service mysql-server restart mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.4.7 Source distribution Copyright (c) 2000, 2025, 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 '\h' for help. Type '\c' to clear the current input statement. # クローン用ユーザー作成 ([password] は任意のパスワードを設定) mysql> create user 'clone_user'@'%' identified by 'password'; Query OK, 0 rows affected (0.07 sec) mysql> grant clone_admin on *.* to 'clone_user'@'%'; Query OK, 0 rows affected (0.06 sec) mysql> exit Bye |
| [5] | レプリカサーバー側で、プライマリーサーバーのデータをクローンして、レプリケーションを開始します。 レプリケーション開始後は、プライマリーサーバー側でデータベースを作成する等して、レプリケーションが正常に行われていることを確認しておくとよいでしょう。 |
|
root@node01:~ # mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.4.7 Source distribution Copyright (c) 2000, 2025, 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 '\h' for help. Type '\c' to clear the current input statement. # [set global clone_valid_donor_list = (プライマリーサーバーの IP アドレス:ポート)] mysql> set global clone_valid_donor_list = '10.0.0.30:3306'; Query OK, 0 rows affected (0.00 sec) # クローン開始 mysql> clone instance from clone_user@10.0.0.30:3306 identified by 'password'; Query OK, 0 rows affected (0.49 sec) # クローン状況確認 # [Completed] であればコピー完了 mysql> select ID,STATE,SOURCE,DESTINATION,BINLOG_FILE,BINLOG_POSITION from performance_schema.clone_status; +------+-----------+----------------+----------------+---------------+-----------------+ | ID | STATE | SOURCE | DESTINATION | BINLOG_FILE | BINLOG_POSITION | +------+-----------+----------------+----------------+---------------+-----------------+ | 1 | Completed | 10.0.0.30:3306 | LOCAL INSTANCE | binlog.000006 | 158 | +------+-----------+----------------+----------------+---------------+-----------------+ 1 row in set (0.00 sec) # レプリケーションの設定 # source_host ⇒ プライマリーサーバーの IP アドレス # source_user ⇒ レプリケーション用 ID # source_password ⇒ レプリケーション用 ID のパスワード # source_ssl ⇒ SSL 接続有効 # source_log_file ⇒ クローン確認で表示された [BINLOG_FILE] 値 # source_log_pos ⇒ クローン確認で表示された [BINLOG_POSITION] 値 mysql> change replication source to source_host='10.0.0.30', source_user='repl_user', source_password='password', source_ssl=1, source_log_file='binlog.000006', source_log_pos=158; Query OK, 0 rows affected, 2 warnings (0.03 sec) # レプリケーション開始 mysql> start replica; Query OK, 0 rows affected (0.03 sec) # ステータス確認 mysql> show replica status\G *************************** 1. row *************************** Replica_IO_State: Waiting for source to send event Source_Host: 10.0.0.30 Source_User: repl_user Source_Port: 3306 Connect_Retry: 60 Source_Log_File: binlog.000006 Read_Source_Log_Pos: 158 Relay_Log_File: node01-relay-bin.000002 Relay_Log_Pos: 325 Relay_Source_Log_File: binlog.000006 Replica_IO_Running: Yes Replica_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_Source_Log_Pos: 158 Relay_Log_Space: 537 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Source_SSL_Allowed: Yes Source_SSL_CA_File: Source_SSL_CA_Path: Source_SSL_Cert: Source_SSL_Cipher: Source_SSL_Key: Seconds_Behind_Source: 0 Source_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Source_Server_Id: 101 Source_UUID: 7609a460-0b93-11f1-a4ab-525400ce0df9 Source_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates Source_Retry_Count: 10 Source_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Source_SSL_Crl: Source_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Source_TLS_Version: Source_public_key_path: Get_Source_public_key: 0 Network_Namespace: 1 row in set (0.00 sec) |
| Sponsored Link |
|
|