본문 바로가기

Database/MySQL

semi replication

install master semi repl plugin

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.01 sec)
  
mysql> show variables like 'rpl%';
+-------------------------------------------+------------+
| Variable_name                             | Value      |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled              | OFF        |
| rpl_semi_sync_master_timeout              | 10000      |
| rpl_semi_sync_master_trace_level          | 32         |
| rpl_semi_sync_master_wait_for_slave_count | 1          |
| rpl_semi_sync_master_wait_no_slave        | ON         |
| rpl_semi_sync_master_wait_point           | AFTER_SYNC |
| rpl_stop_slave_timeout                    | 31536000   |
+-------------------------------------------+------------+

install slave semi repl plugin

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'rpl%';
+-------------------------------------------+------------+
| Variable_name                             | Value      |
+-------------------------------------------+------------+
| rpl_read_size                             | 8192       |
| rpl_semi_sync_master_enabled              | ON         |
| rpl_semi_sync_master_timeout              | 1000       |
| rpl_semi_sync_master_trace_level          | 32         |
| rpl_semi_sync_master_wait_for_slave_count | 1          |
| rpl_semi_sync_master_wait_no_slave        | ON         |
| rpl_semi_sync_master_wait_point           | AFTER_SYNC |
| rpl_semi_sync_slave_enabled               | ON         |
| rpl_semi_sync_slave_trace_level           | 32         |
| rpl_stop_slave_timeout                    | 31536000   |
+-------------------------------------------+------------+
10 rows in set (0.01 sec)
 
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> show slave status \G;     
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.1.5.21
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 156
               Relay_Log_File: tsdb02-relay-bin.000003
                Relay_Log_Pos: 371
        Relay_Master_Log_File: mysql-bin.000001
             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: 156
              Relay_Log_Space: 581
              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: 4074d152-0c4c-11eb-aa27-02f7979ac73c
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave 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: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
       Master_public_key_path:
        Get_master_public_key: 0
            Network_Namespace:
1 row in set (0.00 sec)
 
ERROR:
No query specified
 
mysql>

install slave semi repl plugin

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'rpl%';
+-------------------------------------------+------------+
| Variable_name                             | Value      |
+-------------------------------------------+------------+
| rpl_read_size                             | 8192       |
| rpl_semi_sync_master_enabled              | ON         |
| rpl_semi_sync_master_timeout              | 1000       |
| rpl_semi_sync_master_trace_level          | 32         |
| rpl_semi_sync_master_wait_for_slave_count | 1          |
| rpl_semi_sync_master_wait_no_slave        | ON         |
| rpl_semi_sync_master_wait_point           | AFTER_SYNC |
| rpl_semi_sync_slave_enabled               | ON         |
| rpl_semi_sync_slave_trace_level           | 32         |
| rpl_stop_slave_timeout                    | 31536000   |
+-------------------------------------------+------------+
10 rows in set (0.01 sec)
 
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> show slave status \G;     
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.1.5.21
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 156
               Relay_Log_File: tsdb02-relay-bin.000003
                Relay_Log_Pos: 371
        Relay_Master_Log_File: mysql-bin.000001
             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: 156
              Relay_Log_Space: 581
              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: 4074d152-0c4c-11eb-aa27-02f7979ac73c
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave 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: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
       Master_public_key_path:
        Get_master_public_key: 0
            Network_Namespace:
1 row in set (0.00 sec)
 
ERROR:
No query specified
 
mysql>

master my.cnf

[mysqld]
datadir = /home/bos/mysql/data
socket  = /home/bos/mysql/data/mysql.sock
 
log-error=/home/bos/mysql/data/mysqld.log
pid-file= /home/bos/mysql/data/mysqld.pid
 
 
validate_password_policy=LOW
validate_password_length=4
 
# authentic
default_authentication_plugin=mysql_native_password
 
max_connections=600
max_user_connections=600
 
max_allowed_packet=32M
 
open_files_limit = 8192
table_open_cache = 4000
 
# replication
log-bin=mysql-bin
log_slave_updates = slave_only
gtid_mode=ON
session_track_gtids=OWN_GTID
enforce_gtid_consistency=ON
server-id=1
 
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1second
rpl_semi_sync_slave_enabled=1
 
binlog_format=row
binlog_do_db=DBBOS
 
# optional for consistency
innodb_flush_log_at_trx_commit=1
sync_binlog=1
 
general_log=0
general_log_file=/home/bos/mysql/data/tsdb01_general.log

slave my.cnf

[mysqld]
datadir = /home/bos/mysql/data
socket  = /home/bos/mysql/data/mysql.sock
 
log-error=/home/bos/mysql/data/mysqld.log
pid-file= /home/bos/mysql/data/mysqld.pid
 
 
validate_password_policy=LOW
validate_password_length=4
 
# authentic
default_authentication_plugin=mysql_native_password
 
max_connections=600
max_user_connections=600
 
max_allowed_packet=32M
 
open_files_limit = 8192
table_open_cache = 4000
 
# replication
log-bin=mysql-bin
log_slave_updates = slave_only
gtid_mode=ON
session_track_gtids=OWN_GTID
enforce_gtid_consistency=ON
server-id=1
 
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1second
rpl_semi_sync_slave_enabled=1
 
binlog_format=row
binlog_do_db=DBBOS
 
# optional for consistency
innodb_flush_log_at_trx_commit=1
sync_binlog=1
 
general_log=0
general_log_file=/home/bos/mysql/data/tsdb01_general.log

create replication user (on master)

mysql> create user repl@'%' identified by 'repl';
Query OK, 0 rows affected (0.03 sec)
 
mysql> grant replication slave on *.* to repl@'%';
Query OK, 0 rows affected (0.00 sec)

change master

CHANGE MASTER TO
          MASTER_HOST = '10.1.5.21',
          MASTER_PORT = 3306,
          MASTER_USER = 'repl',
          MASTER_PASSWORD = 'repl',
          MASTER_AUTO_POSITION = 1;

 

replication status command 

-- master / slave 구분
mysql> show variables like 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | ON    |
+---------------+-------+
1 row in set (0.00 sec)
 
--  master 상태 확인
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      155 | test         |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
 
-- master 의 binary log 를 purge 시킨다.
mysql> reset master;
Query OK, 0 rows affected (0.00 sec)
 
-- 데이터 플러쉬
mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)
SLAVE
-- slave 시작
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
 
-- slave 중지
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
 
-- slave 리셋 (replication 을 위한 position 정보를 삭제)
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
 
-- master 의 채널 정보까지 삭제
mysql> reset slave all;
Query OK, 0 rows affected (0.01 sec)
 
mysql> show slave status;
Empty set (0.00 sec)
 
-- master 채널 정보 지정
mysql> CHANGE MASTER TO
    ->      MASTER_HOST = '10.1.5.11',
    ->      MASTER_PORT = 3306,
    ->      MASTER_USER = 'test',
    ->      MASTER_PASSWORD = 'test',
    ->      MASTER_AUTO_POSITION = 1;
Query OK, 0 rows affected, 1 warning (0.02 sec)
 
mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.1.5.11
                  Master_User: test
                  Master_Port: 3306
... ...

'Database > MySQL' 카테고리의 다른 글

MySQL Lock  (0) 2021.10.13
mysql admin script  (0) 2021.10.01
install mysql(percona) by tarball  (0) 2021.10.01
MySQL partition 관리  (0) 2021.10.01
InnoDB on-disk structures  (0) 2021.10.01