3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ: 準同期レプリケーション設定

Posted at

参考: tap dev blog - MySQL5.5-MySQL5.6+KeepAlivedを使った、2台構成HA型準同期レプリケーションの作り方

準備

  • CentOS7で試した。

プラグインインストール

MariaDBプロンプト
MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

my.cnf

/etc/my.cnf.d/my_custom.cnf
[mysqld]
character-set-server = utf8
innodb_file_per_table = 1

# show variables like slow;
slow_query_log=ON
long_query_time=1
log-slow-queries=/var/log/mariadb/slow.log


log-bin = mysql-bin
relay-log = relay-bin
# サーバごとに一意のIDを振ること。
server-id = 101
# 必須。レプリケーションで取得したログをバイナリログにも書き込む。
log_slave_updates
# 勝手にスレーブ起動はいや。
skip-slave-start
# セミシンクロ(準同期)レプリケーションを許可。
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_slave_enabled = 1

systemctl restart mariadb

現状確認

MariaDBプロンプト
MariaDB [(none)]> show status like '%semi%';
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients               | 0     |
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0     |
| Rpl_semi_sync_master_net_waits             | 0     |
| Rpl_semi_sync_master_no_times              | 0     |
| Rpl_semi_sync_master_no_tx                 | 0     |
| Rpl_semi_sync_master_status                | ON    |
| Rpl_semi_sync_master_timefunc_failures     | 0     |
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |
| Rpl_semi_sync_master_tx_wait_time          | 0     |
| Rpl_semi_sync_master_tx_waits              | 0     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0     |
| Rpl_semi_sync_master_yes_tx                | 0     |
| Rpl_semi_sync_slave_status                 | OFF   |
+--------------------------------------------+-------+
15 rows in set (0.00 sec)
  • Rpl_semi_sync_master_clientsが0であることを覚えておく。

本番

通常MASTER側

通常MASTER側にて実施
GRANT REPLICATION SLAVE ON *.* TO sync@'192.168.100.%' IDENTIFIED BY 'Iatho5zi';
binlog名とポジションを確認
show status LIKE 'Binlog_snapshot_file';
show status LIKE 'Binlog_snapshot_position';
  • binlog名 = mysql-bin.000002
  • ポジション = 397

だったので以下コマンドとなる。

通常BACKUP側

change master to master_host='192.168.100.110',master_user='sync',master_password='Iatho5zi',master_log_file='mysql-bin.000002',master_log_pos=397;
start slave;

確認

masterとbackup両方の比較した図
MariaDB [(none)]> show status like '%semi%';
+--------------------------------------------+-------+-------+
| Variable_name                              | master| backup|
+--------------------------------------------+-------+-------+
| Rpl_semi_sync_master_clients               | 1     | 0     |
| Rpl_semi_sync_master_net_avg_wait_time     | 0     | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0     | 0     |
| Rpl_semi_sync_master_net_waits             | 0     | 0     |
| Rpl_semi_sync_master_no_times              | 1     | 0     |
| Rpl_semi_sync_master_no_tx                 | 1     | 0     |
| Rpl_semi_sync_master_status                | ON    | ON    |
| Rpl_semi_sync_master_timefunc_failures     | 0     | 0     |
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     | 0     |
| Rpl_semi_sync_master_tx_wait_time          | 0     | 0     |
| Rpl_semi_sync_master_tx_waits              | 0     | 0     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0     | 0     |
| Rpl_semi_sync_master_yes_tx                | 0     | 0     |
| Rpl_semi_sync_slave_status                 | OFF   | ON    |
+--------------------------------------------+-------+-------+
15 rows in set (0.00 sec)

あと良くわからん

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?