半同期レプリケーションの実装
1、メインサーバー上の配置
1)mariadb-serverのインストール
2)編集/etc/my.cnf
3)ローカルデータベース情報をコピーできるホストの許可
4)rplsemisync_をインストールするマスタープラグイン、有効化
2、サーバーからの構成
1)mariadb-serverのインストール
2)編集/etc/my.cnfファイル
3)同期を開始するホストサーバの場所を設定する
4)rplsemisync_をインストールするslaveプラグインと有効化
上記の構成が完了すると、プライマリ・サーバで半同期レプリケーションに関する情報を表示できます.コマンドは次のとおりです.
3、テスト
1)事前に用意するデータベースhellodbをプライマリサーバにインポートする.sql
2)プライマリ・サーバでの半同期レプリケーションのステータスの表示
3)サーバーから同期するかどうかを確認する
補足:上記の半同期レプリケーション構成レプリケーションのフィルタに基づいて、レプリケーションフィルタはサーバから設定することが望ましい.手順は以下の通りである.
1、サーバーからの構成
1)mariadb serverを閉じる
2)編集/etc/my.cnfファイル
3)mariadb serverの再起動
4)mariadb serverを再起動すると、ハーフ同期レプリケーション機能がオフになりますので、再起動します
2、テスト
1)プライマリ・サーバ上のhellodbデータベースに新しいテーブルsemitableを作成する
2)hellodbデータベースにsemitableがあるかどうかをサーバから確認する
3)プライマリ・サーバにmydbデータベースを作成し、tbl 1テーブルを作成する
4)mydbデータベースのtbl 1テーブルの有無をサーバから確認する
1)mariadb-serverのインストール
[root@localhost ~]# yum -y install mariadb-server
2)編集/etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server-id = 1
log-bin = master-log
3)ローカルデータベース情報をコピーできるホストの許可
[root@localhost ~]# systemctl start mariadb.service ( mariadb server)
[root@localhost ~]# mysql
MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'10.1.51.%' identified by 'replpasswd';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status\G ( , )
*************************** 1. row ***************************
File: master-log.000003 ( )
Position: 245 ( )
Binlog_Do_DB:
Binlog_Ignore_DB:
4)rplsemisync_をインストールするマスタープラグイン、有効化
[root@localhost ~]# mysql
MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
MariaDB [(none)]> set global rpl_semi_sync_master_enabled = ON;
:
MariaDB [(none)]> show plugins;( )
MariaDB [(none)]> show global variables like 'rpl_semi%';( )
MariaDB [(none)]> show global status like '%semi%';( , 0 )
2、サーバーからの構成
1)mariadb-serverのインストール
[root@localhost ~]# yum -y install mariadb-server
2)編集/etc/my.cnfファイル
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
skip_name_resolve = ON
innodb_file_per_table = ON
server-id = 2 (id )
relay-log = slave-log ( )
3)同期を開始するホストサーバの場所を設定する
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# mysql
MariaDB [(none)]> change master to master_host='10.1.51.60',master_user='repluser',master_password='replpasswd',master_log_file='master-log.000003',master_log_pos=245;
4)rplsemisync_をインストールするslaveプラグインと有効化
[root@localhost ~]# mysql
MariaDB [(none)]> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON;
MariaDB [(none)]> start slave;
上記の構成が完了すると、プライマリ・サーバで半同期レプリケーションに関する情報を表示できます.コマンドは次のとおりです.
MariaDB [(none)]> show global status like '%semi%';
Rpl_semi_sync_master_clients 1 ( )
3、テスト
1)事前に用意するデータベースhellodbをプライマリサーバにインポートする.sql
MariaDB [hellodb]> source /root/hellodb.sql;
2)プライマリ・サーバでの半同期レプリケーションのステータスの表示
MariaDB [hellodb]> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000003 | 8102 | | |
+-------------------+----------+--------------+------------------+
MariaDB [hellodb]> show global status like '%semi%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 1684 |
| Rpl_semi_sync_master_net_wait_time | 60630 |
| Rpl_semi_sync_master_net_waits | 36 |
| Rpl_semi_sync_master_no_times | 1 |
| Rpl_semi_sync_master_no_tx | 1 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 1884 |
| Rpl_semi_sync_master_tx_wait_time | 65965 |
| Rpl_semi_sync_master_tx_waits | 35 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 35 |
+--------------------------------------------+-------+
3)サーバーから同期するかどうかを確認する
MariaDB [(none)]> show databases;
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> select * from students;
補足:上記の半同期レプリケーション構成レプリケーションのフィルタに基づいて、レプリケーションフィルタはサーバから設定することが望ましい.手順は以下の通りである.
1、サーバーからの構成
1)mariadb serverを閉じる
[root@localhost ~]# systemctl stop mariadb.service
2)編集/etc/my.cnfファイル
[root@localhost ~]# vim /etc/my.cnf
skip_name_resolve = ON
innodb_file_per_table = ON
server-id = 2
relay-log = slave-log
replicate-do-db = mydb ( mydb )
:
Replicate_Do_DB=
Replicate_Ignore_DB=
Replicate_Do_Table=
Replicate_Ignore_Table=
Replicate_Wild_Do_Table=
Replicate_Wild_Ignore_Table=
3)mariadb serverの再起動
[root@localhost ~]# systemctl start mariadb.service
4)mariadb serverを再起動すると、ハーフ同期レプリケーション機能がオフになりますので、再起動します
MariaDB [(none)]> show global variables like '%semi%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled | OFF |
| rpl_semi_sync_slave_trace_level | 32 |
+---------------------------------+-------+
MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON;
MariaDB [(none)]> stop slave;( )
MariaDB [(none)]> start slave;
2、テスト
1)プライマリ・サーバ上のhellodbデータベースに新しいテーブルsemitableを作成する
MariaDB [hellodb]> create table semitable (id int);
2)hellodbデータベースにsemitableがあるかどうかをサーバから確認する
MariaDB [(none)]> use hellodb
MariaDB [hellodb]> show tables;( )
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
3)プライマリ・サーバにmydbデータベースを作成し、tbl 1テーブルを作成する
MariaDB [hellodb]> create database mydb;
4)mydbデータベースのtbl 1テーブルの有無をサーバから確認する
MariaDB [hellodb]> use mydb;
MariaDB [mydb]> show tables; ( )
+----------------+
| Tables_in_mydb |
+----------------+
| tbl1 |
+----------------+