MySQLの各Versionを跨いだ多段レプリケーション構成構築手順
前回の記事(
MySQL+groonga+mroonga構築手順 - :>/dev/null
)でレガシーシステムから現時点(2019/07/18)の最新Versionにアップデートする手順を検証したが、多段レプリケーションを用いた構成で再検討したので作業記録メモを残す。
多段構成として5.1 → 5.5 → 5.6 → 5.7の順でレプリケーションを行い、データ反映完了後、最終的に現master(5.1)と新master(5.7)間でスイッチオーバーさせ切り替える。
一気に最新までアップデートを行い手順を簡略化させたが2世代またいだレプリケーションはサポート対象外
の為、数珠つなぎで1バージョン毎にアップデートを行う。
- 以下各Version毎の構築要件
- OS:CentOS7.6 x86_84 ← OSは全てこのVerで統一
MySQL | Groonga | Mroonga |
---|---|---|
5.1.60 | 2.10 | 2.1.0 |
5.5.62 | 4.10 | 4.10 |
5.6.44 | 9.0.4 | 9.0.3 |
5.7.26 | 9.0.4 | 9.0.4 |
- 多段レプリケーション構成
現Master(5.1) -> relay(5.5) -> relay(5.6) -> relay(5.7) ← バージョンアップ後、Master
- 各バージョンのSQL_MODEに関して
- バージョン毎で設定値に変更が発生してる為、現Master構成の「設定なし」に統一
- 5.1.60
- 設定なし
- 5.5.62
- 設定なし
- 5.6.44
- NO_ENGINE_SUBSTITUTION
- 5.7.26
- ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- 5.1.60
- バージョン毎で設定値に変更が発生してる為、現Master構成の「設定なし」に統一
sql_mode設定
各環境の/etc/my.cnfの[mysqld]セクションに「sql_mode=''」を設定し、sql_modeのバージョン依存を改善する
◎ 各Version環境構築
■ インストール&設定
MySQL5.1.60 + Mroonga2.10(Groonga2.1.0) 構築手順
構築手順に関しては
MySQL+groonga+mroonga構築手順 - :>/dev/null
を参照
Replication構成に関しては
MySQL+groonga+mroonga移行手順(バージョンアップ) - :>/dev/null
のReplication構成部分を参照
● Masterデータ取得先として、Slaveの一台をレプリケーション停止→dump→リストアを行う。
既存Slaveから複製 dumpファイル出力の為、slave停止
# mysql -uroot -p mysql> stop slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000022 Read_Master_Log_Pos: 383 Relay_Log_File: mysql-relay-bin.000027 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000022 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「No」となっていれば、レプリケーション停止。
dumpファイルのステータス状況確認
ダンプした時点の、マスターのバイナリログファイル名(MASTER_LOG_FILE)と開始位置(MASTER_LOG_POS)を確認する。
mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000019 Read_Master_Log_Pos: 270 Relay_Log_File: mysql-relay-bin.000019 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000019 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 270 Relay_Log_Space: 557 Until_Condition: None
対象DBのデータdump
# mysqldump -uroot -p -c --add-drop-table=0 --skip-comments --default-character-set=ujis --order-by-primary --skip-extended-insert -B db1 > /tmp/mysql51.sql
slave再開
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000019 Read_Master_Log_Pos: 270 Relay_Log_File: mysql-relay-bin.000019 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000019 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
対象DBのdumpファイルをslaveDBへ転送
$ scp -i ~/.ssh/private.pem /tmp/mysql51.sql xxx.xxx.xxx.xxx:/tmp/
参考)
以下Masterノードからdumpデータを取得する場合の手順
レプリケーションユーザー登録
# mysql -uroot mysql> use mysql; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.0.0.0/255.0.0.0' IDENTIFIED BY '******'; mysql> select user, host from user\g; +-------+--------------------+ | user | host | +-------+--------------------+ | repl | 10.0.0.0/255.0.0.0 | +-------+--------------------+ mysql> show grants for repl@'10.0.0.0/255.0.0.0'; +---------------------------------------------------------------------------------------------------------+ | Grants for repl@10.0.0.0/255.0.0.0 | +---------------------------------------------------------------------------------------------------------+ | GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.0.0.0/255.0.0.0' IDENTIFIED BY PASSWORD '****************' | +---------------------------------------------------------------------------------------------------------+
binファイルのステータス状況確認
ダンプした時点の、マスターのバイナリログファイル名(File)と開始位置(Position)を確認する。
mysql> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-bin.000019 | 270 | | | +-------------------+----------+--------------+------------------+
対象DBのデータdump
# mysqldump -uroot -p -c --add-drop-table=0 --skip-comments --default-character-set=ujis --order-by-primary --skip-extended-insert -B db1 > /tmp/mysql51.sql
対象DBのdumpファイルをslaveDBへ転送
$ scp -i ~/.ssh/private.pem /tmp/mysql51.sql xxx.xxx.xxx.xxx:/tmp/
MySQL5.5.62 + Mroonga4.10(Groonga4.10) 構築手順
関連パッケージ
# yum install wget tar gcc-c++ make mecab-devel # yum remove mariadb-libs
# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
MySQLパッケージ確認
# yum repolist all |grep mysql mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118 mysql-connectors-community-source MySQL Connectors Community - disabled mysql-tools-community/x86_64 MySQL Tools Community enabled: 95 mysql-tools-community-source MySQL Tools Community - Sour disabled mysql55-community/x86_64 MySQL 5.5 Community Server disabled <-ここ注目 mysql55-community-source MySQL 5.5 Community Server - disabled mysql56-community/x86_64 MySQL 5.6 Community Server disabled mysql56-community-source MySQL 5.6 Community Server - disabled mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 364 <-ここ注目 mysql57-community-source MySQL 5.7 Community Server - disabled
この環境では、5.7がenabled、5.6がdisabledである。
このままインストールすると、5.7がインストールされるので、有効/無効の切り替えをする。
この切り替えをするためにはyumの設定変更用のyum-utilsパッケージが必要なので、インストールされていない場合はインストールする。
# yum list installed |grep yum-utils yum-utils.noarch 1.1.31-50.el7 @anaconda
リポジトリ有効/無効切替
# yum-config-manager --disable mysql57-community <-5.7を無効設定 # yum-config-manager --enable mysql55-community <-5.5を有効設定
リポジトリ再確認
# yum repolist all |grep mysql mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118 mysql-connectors-community-source MySQL Connectors Community - disabled mysql-tools-community/x86_64 MySQL Tools Community enabled: 95 mysql-tools-community-source MySQL Tools Community - Sour disabled mysql55-community/x86_64 MySQL 5.5 Community Server enabled: 427 mysql55-community-source MySQL 5.5 Community Server - disabled mysql56-community/x86_64 MySQL 5.6 Community Server disabled mysql56-community-source MySQL 5.6 Community Server - disabled mysql57-community/x86_64 MySQL 5.7 Community Server disabled mysql57-community-source MySQL 5.7 Community Server - disabled
MySQLパッケージ確認
# yum info mysql-community-server mysql-community-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp-srv2.kddilabs.jp * extras: ftp-srv2.kddilabs.jp * updates: ftp-srv2.kddilabs.jp Available Packages Name : mysql-community-server Arch : x86_64 Version : 5.5.62 Release : 2.el7 Size : 45 M Repo : mysql55-community/x86_64 Summary : A very fast and reliable SQL database server URL : http://www.mysql.com/ License : Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown : in the Description field.
MySQLパッケージインストール
# yum install mysql-community-server # mysql --version mysql Ver 14.14 Distrib 5.5.62, for Linux (x86_64) using readline 5.1
MySQL起動
# systemctl start mysqld
自動起動設定
# systemctl enable mysqld
/etc/my.cnf作成
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server-id=55 log_bin=mysql-bin log_slave_updates relay_log=mysql-relay-bin sql_mode=''
設定反映
# systemctl restart mysqld
Groonga
# yum install https://packages.groonga.org/centos/groonga-release-latest.noarch.rpm # yum install --enablerepo=epel groonga groonga-devel
Mroonga
# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.62.tar.gz # tar -zxvf mysql-5.5.62.tar.gz # http://packages.groonga.org/source/mroonga/mroonga-4.10.tar.gz # wget http://packages.groonga.org/source/mroonga/mroonga-4.10.tar.gz # tar -zxvf mroonga-4.10.tar.gz # cd mroonga-4.10/ # ./configure --with-mysql-source=/tmp/mysql-5.5.62 --with-mysql-config=/bin/mysql_config # make # make install
mysqlにpluginを組み込む
# mysql -uroot mysql> INSTALL PLUGIN Mroonga SONAME 'ha_mroonga.so'; mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | | Mroonga | YES | CJK-ready fulltext search, column store | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
/etc/my.cnf更新 (既存環境のmy.cnfを反映)
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server-id=55 log_bin=mysql-bin log_slave_updates relay_log=mysql-relay-bin sql_mode='' port = 3306 #skip-locking skip-external-locking skip-character-set-client-handshake skip-name-resolve #old_passwords ← 5.5⇔5.6間でのレプリケーションで接続エラー発生※1 key_buffer_size=64M table_cache = 2048 ##table_open_cache = 2048 [client] port = 3306 default-character-set=ujis [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set=ujis [mysqlhotcopy] interactive-timeout
設定反映
# systemctl restart mysqld
◆ Slave設定
database作成
# mysql -uroot -p mysql> CREATE DATABASE db1 DEFAULT CHARACTER SET ujis COLLATE ujis_japanese_ci;
masterのdumpファイルをrestore
# mysql -uroot db1 < /tmp/mysql51.sql
master DBへ接続するためのパラメータ設定
ダンプした時点の、ホスト名、ユーザー、バイナリログファイル名(MASTER_LOG_FILE)と開始位置(MASTER_LOG_POS)を設定し、レプリケーションを構成する。
# mysql -uroot mysql> change master to -> master_host='xxx.xxx.xxx.xxx', -> master_user='repl', -> master_password='******', -> master_log_file='master-bin.000019', -> master_log_pos=270;
slave開始/状況確認
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000019 Read_Master_Log_Pos: 270 Relay_Log_File: mysql-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000019 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「Yes」となっていれば、レプリケーション設定完了。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
◆ Master設定
dumpファイル出力の為、slave停止
mysql> stop slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000022 Read_Master_Log_Pos: 383 Relay_Log_File: mysql-relay-bin.000027 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000022 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「No」となっていれば、レプリケーション停止。
binファイルのステータス状況確認
ダンプした時点の、マスターのバイナリログファイル名(File)と開始位置(Position)を確認する。
mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000008 | 62842 | | | +------------------+----------+--------------+------------------+
レプリケーションユーザー登録
mysql> use mysql; mysql> select user, host, password from user\g; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.0.0.0/255.0.0.0' IDENTIFIED BY '******';
対象DBのデータdump
# mysqldump -uroot -p -c --add-drop-table=0 --skip-comments --default-character-set=ujis --order-by-primary --skip-extended-insert -B db1 > /tmp/mysql55.sql
slave再開
mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000022 Read_Master_Log_Pos: 383 Relay_Log_File: mysql-relay-bin.000027 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000022 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000022 Read_Master_Log_Pos: 383 Relay_Log_File: mysql-relay-bin.000028 Relay_Log_Pos: 253 Relay_Master_Log_File: master-bin.000022 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
対象DBのdumpファイルをslaveDBへ転送
$ scp -i ~/.ssh/private.pem /tmp/mysql55.sql xxx.xxx.xxx.xxx:/tmp/
※1 old_passwordsに関する問題
slave側で「show slave status \G;」を実行した時、下記エラー発生
[ERROR] Slave I/O: error connecting to master '
これは16文字のパスワードを持っている場合、それらは古いパスワードです。有効な41byteハッシュパスワードを持っている必要があります。
よって、old_passwordsを無効化しmysqlを起動する必要があります。
ref)
http://lucianoshow.biz/charlie/tumblr/158847295488.html
https://charlietokyojp.tumblr.com/post/158847295488/mysql-55-56%E3%81%AEoldpasswords%E3%81%AB%E9%96%A2%E3%81%99%E3%82%8B%E3%83%A1%E3%83%A2
http://anothermysqldba-jp.blogspot.com/2013/09/secureauthmysql.html
パスワード保存のセキュリティ警告について
「CHANGE MASTER TO」で「MASTER_USER」や「MASTER_PASSWORD」を指定すると、MySQL5.6からは警告されるようになりました。これは『スレーブサーバの「master.info」にユーザ名やパスワードがそのまま保存されるよ!』と注意してくれています。
SHOW WARNINGSオプション
(略) Message: Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
ref)
https://blog.apar.jp/linux/6725/
MySQL5.6.44 + Mroonga9.0.3(Groonga9.0.4) 構築手順
関連パッケージ
# yum install wget tar gcc-c++ make mecab-devel # yum remove mariadb-libs
# wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-server-5.6.44-2.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-client-5.6.44-2.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-devel-5.6.44-2.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-common-5.6.44-2.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-libs-5.6.44-2.el7.x86_64.rpm # rpm -ivh mysql-community-*
ダウンロードサイト
https://centos.pkgs.org/7/mysql-5.6-x86_64/
mysql起動
# systemctl start mysqld
自動起動設定
# systemctl enable mysqld
/etc/my.cnf作成
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server-id=56 log_bin=mysql-bin log_slave_updates relay_log=mysql-relay-bin sql_mode='' [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
Mecab
※mysql-mroongaの依存関係にあるmecabおよびgroonga関連のパッケージが必要な場合、下記インストール
# yum install mecab mecab-devel mecab-ipadic --disablerepo=* --enablerepo=groonga → Version指定の場合 # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-devel-0.996-1.el7.centos.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-ipadic-2.7.0.20070801-13.el7.centos.1.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-0.996-1.el7.centos.x86_64.rpm # rpm -ivh mecab-*
Groonga
# wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-libs-9.0.3-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-tokenizer-mecab-9.0.3-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-9.0.3-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-devel-9.0.3-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-plugin-suggest-9.0.3-1.el7.x86_64.rpm # rpm -ivh groonga-*
ダウンロードサイト
https://packages.groonga.org/centos/7/x86_64/Packages/
Mroonga plugin
# yum install groonga-normalizer-mysql ← 関連パッケージ # wget http://packages.groonga.org/centos/7/x86_64/Packages/mysql-community-mroonga-9.03-1.el7.x86_64.rpm # rpm -ivh mysql-community-mroonga-9.03-1.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:mysql-community-mroonga-9.03-1.el################################# [100%] Redirecting to /bin/systemctl status mysqld.service /bin/mysql -u root < /usr/share/mroonga/install.sql Mroonga plugin確認 # mysql -uroot mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Mroonga | YES | CJK-ready fulltext search, column store | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
/etc/my.cnf更新 (既存環境のmy.cnfを反映)
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server-id=56 log_bin=mysql-bin log_slave_updates relay_log=mysql-relay-bin sql_mode='' port = 3306 #skip-locking skip-external-locking #old_passwords key_buffer_size=64M #table_cache = 2048 table_open_cache = 2048 #thread_cache=512 thread_cache_size=512 [client] port = 3306 default-character-set=ujis [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set=ujis [mysqlhotcopy] interactive-timeout [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
設定反映
# systemctl restart mysqld
● Replication
◆ Slave設定
#mysql -uroot -p mysql> CREATE DATABASE db1 DEFAULT CHARACTER SET ujis COLLATE ujis_japanese_ci;
masterのdumpファイルをrestore
mysql -uroot db1 < /tmp/mysql55.sql
master DBへ接続するためのパラメータ設定
ダンプした時点の、ホスト名、ユーザー、バイナリログファイル名(File)と開始位置(Position)を設定し、レプリケーションを構成する。
mysql> change master to master_host='xxx.xxx.xxx.xxx', master_user='repl', master_password='********', master_log_file='mysql-bin.000008', master_log_pos=62842;
slave開始/状況確認
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000009 Read_Master_Log_Pos: 545 Relay_Log_File: mysql-relay-bin.000003 Relay_Log_Pos: 704 Relay_Master_Log_File: mysql-bin.000009 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「Yes」となっていれば、レプリケーション設定完了。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
◆ Master設定
dumpファイル出力の為、slave停止
mysql> stop slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000009 Read_Master_Log_Pos: 850 Relay_Log_File: mysql-relay-bin.000003 Relay_Log_Pos: 1009 Relay_Master_Log_File: mysql-bin.000009 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「No」となっていれば、レプリケーション停止。
binファイルのステータス状況確認
ダンプした時点の、バイナリログファイル名(File)と開始位置(Position)を設定し、レプリケーションを構成する。
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000006 | 105233 | | | | +------------------+----------+--------------+------------------+-------------------+
レプリケーションユーザー登録
mysql> use mysql; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.0.0.0/255.0.0.0' IDENTIFIED BY 'replpw'; mysql> select user, host, password from user\g; +------+--------------------+-------------------------------------------+ | user | host | password | +------+--------------------+-------------------------------------------+ | repl | 10.0.0.0/255.0.0.0 | ***************************************** | +------+--------------------+-------------------------------------------+
対象DBのデータdump
mysqldump -uroot -p -c --add-drop-table=0 --skip-comments --default-character-set=ujis --order-by-primary --skip-extended-insert -B db1 > /tmp/mysql56.sql
slave再開
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000009 Read_Master_Log_Pos: 850 Relay_Log_File: mysql-relay-bin.000004 Relay_Log_Pos: 266 Relay_Master_Log_File: mysql-bin.000009 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
対象DBのdumpファイルをslaveDBへ転送
$ scp -i ~/.ssh/private.pem /tmp/mysql56.sql xxx.xxx.xxx.xxx:/tmp/
MySQL5.7.26 + Mroonga9.0.4(Groonga9.0.4) 構築手順
関連パッケージ
# yum install wget tar gcc-c++ make mecab-devel # yum remove mariadb-libs
# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64//mysql-community-server-5.7.26-1.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64//mysql-community-client-5.7.26-1.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64//mysql-community-devel-5.7.26-1.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64//mysql-community-common-5.7.26-1.el7.x86_64.rpm # wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64//mysql-community-libs-5.7.26-1.el7.x86_64.rpm # rpm -ivh mysql-community-*
ダウンロードサイト
https://centos.pkgs.org/7/mysql-5.7-x86_64/
自動起動設定
# systemctl enable mysqld
/etc/my.cnf作成
# vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server-id=57 log_bin=mysql-bin sql_mode=''
設定反映
# systemctl start mysqld
初期パスワード確認
# cat /var/log/mysqld.log | grep password 初期化(mysql_secure_installation) # mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: [初期パスワード] The existing password for the user account root has expired. Please set a new password. New password: [新しいパスワード] Re-enter new password: [もう一度新しいパスワード] The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: [新しいパスワード] Re-enter new password: [もう一度新しいパスワード] Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
※mysql-mroongaの依存関係にあるmecabおよびgroonga関連のパッケージが必要な場合、下記インストール
# yum install mecab mecab-devel mecab-ipadic --disablerepo=* --enablerepo=groonga → Version指定の場合 # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-0.996-2.el7.1.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-devel-0.996-2.el7.1.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/mecab-ipadic-2.7.0.20070801-17.el7.x86_64.rpm # rpm -ivh mecab-*
Groonga
# wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-libs-9.0.4-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-tokenizer-mecab-9.0.4-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-9.0.4-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-devel-9.0.4-1.el7.x86_64.rpm # wget https://packages.groonga.org/centos/7/x86_64/Packages/groonga-plugin-suggest-9.0.4-1.el7.x86_64.rpm # rpm -ivh groonga-*
ダウンロードサイト
https://packages.groonga.org/centos/7/x86_64/Packages/
Mroonga
関連パッケージ # yum install groonga-normalizer-mysql Mroonga plugin # wget https://packages.groonga.org/centos/7/x86_64/Packages/mysql57-community-mroonga-9.04-1.el7.x86_64.rpm # rpm -ivh mysql57-community-mroonga-9.04-1.el7.x86_64.rpm Mroonga plugin確認 # mysql -uroot -p mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Mroonga | YES | CJK-ready fulltext search, column store | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
/etc/my.cnf更新 (既存環境のmy.cnfを反映)
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid validate_password_length=4 validate_password_policy=LOW server-id=57 log_bin=mysql-bin log_slave_updates relay_log=mysql-relay-bin sql_mode='' port = 3306 skip-external-locking table_open_cache = 2048 thread_cache_size=512 [client] port = 3306 socket=/var/lib/mysql/mysql.sock default-character-set=ujis [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set=ujis [mysqlhotcopy] interactive-timeout
設定反映
# systemctl restart mysqld
● Replication
◆ Slave設定
database作成
# mysql -uroot -p mysql> CREATE DATABASE db1 DEFAULT CHARACTER SET ujis COLLATE ujis_japanese_ci;
masterのdumpファイルをrestore
# mysql -uroot -p db1 < /tmp/mysql56.sql
master DBへ接続するためのパラメータ設定
ダンプした時点の、ホスト名、ユーザー、バイナリログファイル名(File)と開始位置(Position)を設定し、レプリケーションを構成する。
mysql> change master to master_host='xxx.xxx.xxx.xxx', master_user='repl', master_password='******', master_log_file='mysql-bin.000006', master_log_pos=105233;
slave開始/状況確認
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000006 Read_Master_Log_Pos: 105233 Relay_Log_File: mysql-relay-bin.000002 Relay_Log_Pos: 317 Relay_Master_Log_File: mysql-bin.000006 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「Yes」となっていれば、レプリケーション設定完了。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
◆ Master設定
dumpファイル出力の為、slave停止
mysql> stop slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000006 Read_Master_Log_Pos: 106336 Relay_Log_File: mysql-relay-bin.000003 Relay_Log_Pos: 317 Relay_Master_Log_File: mysql-bin.000006 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB:
ステータス結果
「Slave_IO_Running」と「Slave_SQL_Running」がともに「No」となっていれば、レプリケーション停止。
binファイルのステータス状況確認
ダンプした時点の、マスターのバイナリログファイル名(File)と開始位置(Position)を確認する。
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000003 | 37328 | | | | +------------------+----------+--------------+------------------+-------------------+
レプリケーションユーザー登録
mysql> use mysql; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.0.0.0/255.0.0.0' IDENTIFIED BY '******'; mysql> select user, host, authentication_string from user \g; +---------------+--------------------+-------------------------------------------+ | user | host | authentication_string | +---------------+--------------------+-------------------------------------------+ | repl | 10.0.0.0/255.0.0.0 | ***************************************** | +---------------+--------------------+-------------------------------------------+
対象DBのデータdump
mysqldump -uroot -p -c --add-drop-table=0 --skip-comments --default-character-set=ujis --order-by-primary --skip-extended-insert -B db1 > /tmp/mysql57.sql
slave再開
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000006 Read_Master_Log_Pos: 106336 Relay_Log_File: mysql-relay-bin.000004 Relay_Log_Pos: 317 Relay_Master_Log_File: mysql-bin.000006 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB:
対象DBのdumpファイルをslaveDBへ転送
$ scp -i ~/.ssh/private.pem /tmp/mysql56.sql xxx.xxx.xxx.xxx:/tmp/
◆ Slave Replication設定(MySQL5.7間)
masterのdumpファイルをrestore
# mysql -uroot -p db1 < /tmp/mysql57.sql
master DBへ接続するためのパラメータ設定
change master to master_host='xxx.xxx.xxx.xxx', master_user='repl', master_password='******', master_log_file='mysql-bin.000004', master_log_pos=154;
slave開始/状況確認
mysql> start slave; mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: xxx.xxx.xxx.xxx Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 37633 Relay_Log_File: sql57mroo90401-relay-bin.000003 Relay_Log_Pos: 625 Relay_Master_Log_File: mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: