原理:
主节点生成了二进制日志文件之后,从节点的i/o thread发送读请求,主节点经由dump发送给从节点的中继日志,最后由SQL thread读取中继日志中的内容replay完成复制。
QQ截图20170917185021.png
准备环境:
主节点:192.168.52.138
从节点:192.168.52.139
禁用selinux策略,清空防火墙规则
iptables -F
setenforce 0
更改配制文件:
主节点:
Vim /etc/my.cnf.d/server.cnf
[mysqld]
log_bin=master-log
server_id=1
skip_name_resolve=on
从节点:
[mysqld]
server-id=7
relay-log=relay-log
skip_name_resolve=on
配置完成后启动服务:
systemvtl start mariadb
ss -ntl | grep '3306'
确保3306端口打开
主从配置:
在主节点上授权一个用户
MariaDB [(none)]> grant replication client,replication slave on *.* to 'kongbinquan'@'192.168.52.139' identified by 'kbq';
Query OK, 0 rows affected (0.00 sec)
并找出当前所在节点:
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000006 | 423 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
接着在从节点上配置:
MariaDB [(none)]> change master to master_host='192.168.52.138',master_user='kongbinquan',master_password='kbq',master_log_file='master-log.000006', master_log_pos=423;
Query OK, 0 rows affected (0.03 sec)
从节点状态:
MariaDB [(none)]> start slave ;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.52.138
Master_User: kongbinquan
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-log.000006
Read_Master_Log_Pos: 423
Relay_Log_File: relay-log.000002
Relay_Log_Pos: 530
Relay_Master_Log_File: master-log.000006
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: 423
Relay_Log_Space: 818
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: 1
1 row in set (0.00 sec)
网友评论