MySQL レプリケーション設定(マルチマスタ)
http://extstrg.asabiya.net/pukiwiki/index.php?MySQL%20%A5%EC%A5%D7%A5%EA%A5%B1%A1%BC%A5%B7%A5%E7%A5%F3%C0%DF%C4%EA%A1%CA%A5%DE%A5%EB%A5%C1%A5%DE%A5%B9%A5%BF%A1%CB目次 †
設定手順 †
- レプリケーション用ユーザの作成
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY '【パスワード】';
- my.cnf (DB 1台目)
[mysqld] log-bin server-id=1 binlog-ignore-db=mysql auto_increment_increment=2 auto_increment_offset=1 sync_binlog=1 master-host=【レプリケーション先(DB 2台目)】 master-user=【アカウント】 master-password=【パスワード】
- my.cnf (DB 2台目)
[mysqld] log-bin server-id=2 binlog-ignore-db=mysql auto_increment_increment=2 auto_increment_offset=2 sync_binlog=1 master-host=【レプリケーション先(DB 1台目)】 master-user=【アカウント】 master-password=【パスワード】
レプリケーション開始手順 †
- データの複製
マスター側のデータをダンプもしくはディレクトリ丸ごとコピーにてスレーブ側へ複製する。
- mysqlの起動
起動の際に特に順番はありません。
起動後、エラーログ(/usr/local/mysql/var/[HOST NAME].err)を参照する。
以下のメッセージが出ていれば接続成功。
- /usr/local/mysql/var/[HOST NAME].err
090613 14:14:50 [Note] Slave I/O thread: connected to master 'repl@[HOST NAME]:3306',replication started in log '[HOST NAME]-bin.000002' at position 194
先に起動したサーバでは以下のエラーが発生する。
(接続先がまだ起動していないため)
- /usr/local/mysql/var/[HOST NAME].err
090613 14:22:47 [ERROR] Slave I/O: error reconnecting to master 'repl@[HOST NAME]:3306' - retry-time: 60 retries: 86400, Error_code: 2013
このエラーは時間経過で解消するが、手っ取り早く解消させるにはmysqldを再起動させる。
- レプリケーションの稼動状態を確認
MySQLにログインを行い、以下を実行する。
mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: localhost Master_User: root Master_Port: 3306 Connect_Retry: 3 Master_Log_File: gbichot-bin.005 Read_Master_Log_Pos: 79 Relay_Log_File: gbichot-relay-bin.005 Relay_Log_Pos: 548 Relay_Master_Log_File: gbichot-bin.005 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 79 Relay_Log_Space: 552 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: 8
以下の操作は不具合が出るので保留します
- レプリケーションの稼動
MySQLを起動し、log-binのファイル名を確認する
1台目
mysql1> show master status; +------------------+----------+ | File | Position | +------------------+----------+ | mysql-bin.000014 | 941 | +------------------+----------+ 1 row in set (0.00 sec)
2台目
mysql2> show master status; +------------------+----------+ | File | Position | +------------------+----------+ | mysql-bin.000022 | 1164 | +------------------+----------+ 1 row in set (0.00 sec)
- レプリケーションの開始(Slaveの開始)
1台目
mysql1> CHANGE MASTER TO MASTER_HOST='【DB 2台目】', MASTER_USER='【アカウント】', MASTER_PASSWORD='【パスワード】', MASTER_LOG_FILE='mysql2-bin.000014'; mysql1> start slave;
2台目
mysql2> CHANGE MASTER TO MASTER_HOST='【DB 1台目】', MASTER_USER='【アカウント】', MASTER_PASSWORD='【パスワード】', MASTER_LOG_FILE='mysql1-bin.000012'; mysql2> start slave;
参考資料 †
http://dev.mysql.com/doc/refman/5.1/ja/replication.html
http://www.irori.org/doc/mysql-rep.html
http://d.hatena.ne.jp/end0tknr/20090202/1233557966
http://www.open-source-network.info/archives/3
http://www.usamimi.info/~sakura/cgi-bin/blog/article.php?id=96
Last-modified: 2009-07-15 (水) 19:09:46 (5391d)