Mysqlマスタースレーブ構成
1.Mysqlマスタスレーブ構成環境情報
Master:192.168.231.128
Slave:192.168.231.129
2.Matser構成
①プロファイルの編集/etc/my.cnf
修正my.cnf、server-id=128とlog_を追加bin=test_01、その後mysqlサービスを再起動
②同期ユーザを作成し、テーブルを一時的にロックして再書き込みを許可しない
③マスターの状態情報の表示
このステータスにはmasterのbin_が表示されます.logファイル名と現在位置
④現在のすべてのデータベースをバックアップする
3.Slave構成
①プロファイルの編集/etc/my.cnfはserver-id=129を追加し、mysqldサービスを再起動します.
②MasterでバックアップしたデータベースバックアップファイルをSlaveにコピーする
③データベースバックアップファイルを対応するデータベースに復元する
Master:192.168.231.128
Slave:192.168.231.129
2.Matser構成
①プロファイルの編集/etc/my.cnf
修正my.cnf、server-id=128とlog_を追加bin=test_01、その後mysqlサービスを再起動
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
server-id=128
log_bin=test_01
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
[root@test_01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL... SUCCESS!
Starting MySQL. SUCCESS!
②同期ユーザを作成し、テーブルを一時的にロックして再書き込みを許可しない
mysql> grant replication slave on *.* to 'replicate'@'192.168.231.129' identified by 'P@ssw0rd';
Query OK, 0 rows affected (0.00 sec)
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)
③マスターの状態情報の表示
このステータスにはmasterのbin_が表示されます.logファイル名と現在位置
mysql> show master status
-> ;
+----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+------------------+-------------------+
| test_01.000002 | 653120 | | | |
+----------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
④現在のすべてのデータベースをバックアップする
[root@test_01 mysql]# ls
auto.cnf ib_logfile0 mysql test test_01.000002 test_01.index wennan
ibdata1 ib_logfile1 performance_schema test_01.000001 test_01.err test_01.pid
[root@test_01 mysql]# ls .tmp
ls: .tmp:
[root@test_01 mysql]# ls /tmp
mysql.sock mysql.sql systemd-private-e3f448a092a245e78ad7f85feac7cd9a-vmtoolsd.service-hIsgS1
[root@test_01 mysql]# mysqldump -uroot -pP@ssw0rd test > /tmp/test.sql
Warning: Using a password on the command line interface can be insecure.
[root@test_01 mysql]# mysqldump -uroot -pP@ssw0rd wennan > /tmp/wennan.sql
Warning: Using a password on the command line interface can be insecure.
[root@test_01 mysql]# ls /tmp
mysql.sock mysql.sql systemd-private-e3f448a092a245e78ad7f85feac7cd9a-vmtoolsd.service-hIsgS1 test.sql wennan.sql
3.Slave構成
①プロファイルの編集/etc/my.cnfはserver-id=129を追加し、mysqldサービスを再起動します.
[root@test_01 mysql]# ls
auto.cnf ib_logfile0 mysql test test_01.000002 test_01.index wennan
ibdata1 ib_logfile1 performance_schema test_01.000001 test_01.err test_01.pid
[root@test_01 mysql]# ls .tmp
ls: .tmp:
[root@test_01 mysql]# ls /tmp
mysql.sock mysql.sql systemd-private-e3f448a092a245e78ad7f85feac7cd9a-vmtoolsd.service-hIsgS1
[root@test_01 mysql]# mysqldump -uroot -pP@ssw0rd test > /tmp/test.sql
Warning: Using a password on the command line interface can be insecure.
[root@test_01 mysql]# mysqldump -uroot -pP@ssw0rd wennan > /tmp/wennan.sql
Warning: Using a password on the command line interface can be insecure.
[root@test_01 mysql]# ls /tmp
mysql.sock mysql.sql systemd-private-e3f448a092a245e78ad7f85feac7cd9a-vmtoolsd.service-hIsgS1 test.sql wennan.sql
[root@test_02 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
②MasterでバックアップしたデータベースバックアップファイルをSlaveにコピーする
[root@test_02 ~]# scp 192.168.231.128:/tmp/*.sql /tmp
The authenticity of host '192.168.231.128 (192.168.231.128)' can't be established.
ECDSA key fingerprint is b2:0d:32:2b:8f:40:2e:c2:2d:ab:6d:f0:2c:6b:2d:9a.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.231.128' (ECDSA) to the list of known hosts.
[email protected]'s password: 100% 637KB 636.7KB/s 00:00
test.sql 100% 1258 1.2KB/s 00:00
wennan.sql
③データベースバックアップファイルを対応するデータベースに復元する
[root@test_02 ~]# mysql -uroot -pP@ssw0rd wennan
④ , slave slave
mysql>stop slave;
mysql>change master to master_host='192.168.231.128', master_user='replicate', master_password='P@ssw0rd', master_log_file='test_01.000002', master_log_pos=653120,
⑤slaveを し、slave を するmysql> start slave;
mysql> show slave stauts\G
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stauts' at line 1
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.231.128
Master_User: replicate
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: test_01.000002
Read_Master_Log_Pos: 653120
Relay_Log_File: test_02-relay-bin.000002
Relay_Log_Pos: 281
Relay_Master_Log_File: test_01.000002
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: 653120
Relay_Log_Space: 456
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: 128
Master_UUID: 40078eac-e0ed-11e7-92e6-000c296b046f
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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: 0
1 row in set (0.00 sec)
⑥ のテスト
masterでテーブルtest 1を するmysql> create table test1(`id` int(4), `name` char(40));
Query OK, 0 rows affected (0.39 sec)
mysql> select count(*) test1;
+-------+
| test1 |
+-------+
| 1 |
+-------+
1 row in set (0.00 sec)
slaveはテーブルtest 1 を し、 を するmysql> select count(*) test1;
+-------+
| test1 |
+-------+
| 1 |
+-------+
1 row in set (0.00 sec)