最近看了一下MariaDB的常规复制章节,就按部就班的搭建了一下最简单的主从复制。需要的硬件环境很简单(在虚拟机VMware中搭建):

1:两台server:Master: 192.168.6.133  Slave:192.168.6.132

2:网络配置,这里图个简单,直接关闭master的防火墙

[root@master Desktop]# service iptables stop

概览实现主从复制需要完成的配置:

1:主从集群里面的每台server需要有一个唯一的server_id,下面的配置中,将master的server_id设置为1, slave1的server_id设置为2;

2:master需要启用二进制日志,slave需要启动relay日志。

3:master上创建一个用户,供slave登录到master上复制二进制日志数据。

具体配置过程如下:

1:master配置。

    首先停掉mysql服务(用root用户执行service mysql status查看是否在正在运行):

[root@master Desktop]# service mysql stop
Shutting down MySQL.. SUCCESS!

网上的教程都是在my.cnf中添加相关配置,这个文件初始内容如下:

[mariadb@master Desktop]$ cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server] #
# include all files from the config directory
#
!includedir /etc/my.cnf.d

如果在[client-server]节点添加配置项,会造成mysql无法启动,不知是什么原因,看了下错误日志master.err文件也没发现有用的信息。看这个文件的内容,server端和client端配置文件位于/etc/my.cnf.d/目录下:

[mariadb@master Desktop]$ ls /etc/my.cnf.d
mysql-clients.cnf server.cnf tokudb.cnf

修改server.cnf文件如下,完成服务端配置:

[mariadb@master Desktop]$ vi /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
# # this is read by the standalone daemon and embedded servers
[server] # this is only for the mysqld standalone daemon
[mysqld] # this is only for embedded server
[embedded] # This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
log-basename = master
log-bin = /var/lib/mysql/master.bin
binlog-format = row
server_id = 1
# This group is only read by MariaDB-10.0 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.0]

(红色部分为新增内容)
    接下来启动mysql服务:

[root@master mysql]# service mysql start
Starting MySQL. SUCCESS!

登录到mariadb:

[mariadb@master Desktop]$ mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.0.-MariaDB-log MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

授权用户(这个用户稍后会在配置slave节点用到)

MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.6.133' identified by 'replpass';
Query OK, rows affected (0.00 sec)

2.slave配置

首先停掉salve节点的mysql服务,方法同上。

修改server.cnf文件,具体内容如下:

[mariadb@slave1 Desktop]$ vi /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
# # this is read by the standalone daemon and embedded servers
[server] # this is only for the mysqld standalone daemon
[mysqld] # this is only for embedded server
[embedded] # This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
server_id = 2
relay-log = /var/lib/mysql/relay-bin
# This group is only read by MariaDB-10.0 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.0]

(红色部分为新增)
    启动mysql服务

[root@slave1 Desktop]# service mysql status
SUCCESS! MySQL running ()

登录到mysql数据库,查看relay log中继日志状态:

[root@slave1 Desktop]# mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.0.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show global variables like '%relay%';
+-----------------------+--------------------------+
| Variable_name | Value |
+-----------------------+--------------------------+
| max_relay_log_size | |
| relay_log | /var/lib/mysql/relay-bin |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | |
| sync_relay_log | |
| sync_relay_log_info | |
+-----------------------+--------------------------+
rows in set (0.00 sec)

(relay_log参数值是我们设定的路径下的文件,说明中继日志设定OK)
    连接到主服务器master

MariaDB [(none)]> change master to master_host='192.168.6.133', master_user='repluser', master_password='replpass';
Query OK, rows affected (0.09 sec)

在masterserver上查看master进程数量

MariaDB [(none)]> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+----+------+-----------+------+---------+------+-------+------------------+----------+
| | root | localhost | NULL | Query | | init | show processlist | 0.000 |
+----+------+-----------+------+---------+------+-------+------------------+----------+
row in set (0.00 sec)

在master上查看操作日志状态

MariaDB [(none)]> show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| master. | | | |
+---------------+----------+--------------+------------------+
row in set (0.00 sec)

在slave上查看slave状态

MariaDB [(none)]> show slave status\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 192.168.6.133
Master_User: repluser
Master_Port:
Connect_Retry:
Master_Log_File:
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
row in set (0.00 sec)

关键看Slave_IO_Running: No            Slave_SQL_Running: No 这两个,现在是未启动,接下来在salve上启动slave节点:

MariaDB [(none)]> start slave;
Query OK, rows affected (0.01 sec)

再次查看slave状态

MariaDB [(none)]> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.6.133
Master_User: repluser
Master_Port:
Connect_Retry:
Master_Log_File: master.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
row in set (0.00 sec)

Slave_IO_State: Waiting for master to send event

Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

从节点已经处于接收master节点发送事件的状态,可以进行主从复制了,现在去master上创建一个数据库:

MariaDB [(none)]> create database testsync;
Query OK, row affected (0.01 sec)

去从节点查看,是否已经自动同步:

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| testsync |
+--------------------+
rows in set (0.02 sec)

已经完成同步。再次查看主从状态:

其中read_master_log_pos也是838,表示主从状态一致。

MariaDB——(三) MariaDB 10.0.15 standard replication主从复制搭建的更多相关文章

  1. Cenos7 编译安装 Mariadb Nginx PHP Memcache ZendOpcache (实测 笔记 Centos 7.0 + Mariadb 10.0.15 + Nginx 1.6.2 + PHP 5.5.19)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  2. CentOS7 编译安装 Mariadb (实测 笔记 Centos 7.0 + Mariadb 10.0.15)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  3. MariaDB——(二) MariaDB 10.0.15 日志文件—undo 日志

          日志的记录和维护是数据库中相当重要的内容,写这篇文章和后面几篇文章作为学习官网文档的笔记.MariaDB数据库日志可分为二进制日志.查询日志.错误日志.myISAM表日志.relay日志和 ...

  4. MariaDB——(一)CentOS 6.5 下 MariaDB 10.0.15 YUM 安装

    1.配置yum源: 在MariaDB官网提供了yum源在线生成器,选择合适的系统和版本后,会生成所需的repo文件内容: 在/etc/yum.repos.d/目录下新建一个MariaDB.repo文件 ...

  5. SQLServer2012 和 MariaDB 10.0.3 分页效率的对比

    1. 实验环境      R910服务器, 16G内存 SqlServer 2012   64bit MariaDB 10.0.3   64bit  (InnoDB) 2. 实验表情况 rtlBill ...

  6. [mysql] MariaDB 10.0.10 GTID复制

    一:概念理解:    1.TID:Transaction ID,即Mysql服务器的事务ID号. 2.GTID:Global Transaction ID,全局事务ID,在整个主从复制架构中任何两个事 ...

  7. MariaDB Galera Cluster 10.1 只支持 LINUX ?!

    MariaDB Galera Cluster  (MariaDB 10.1) 当前只支持:LINUX ! 参考: https://mariadb.com/kb/en/mariadb/getting-s ...

  8. CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置

    1.安装MariaDB 安装命令 yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB,两条命令都可以 systemctl sta ...

  9. [mariadb]Windows Mariadb 10.2安装过程

    在学习Flask的过程中,碰到SQLAlchemy不支持Mariadb 10.2.9以前版本的问题,于是升级Mariadb到10.2.10. 升级过程中,我只能说,Mariadb及Mysql的文档结构 ...

随机推荐

  1. mysql 实现 sqlserver的row_number over() 方法

    1.创建表 CREATE TABLE `heyf_t10` ( `empid` int(11) DEFAULT NULL, `deptid` int(11) DEFAULT NULL, `salary ...

  2. 2019-04-25-day040-数据库的查询

    内容回顾 数据的增删改查 插入数据 insert into 表 values (值1,值2...) insert into 表(指定字段名1,字段名2) values (值1,值2...) 删除数据 ...

  3. Verilog中的reg一定会被综合成寄存器么

    对应于实际的数字电路中,如果该程序块描述的是时序逻辑,则该寄存器变量对应为寄存器:如果该程序块描述的是组合逻辑,该寄存器变量对应为硬件逻辑:如果该程序块描述的是不完全组合逻辑,那么该寄存器变量也可以对 ...

  4. Android第二次作业

    另一成员链接:https://www.cnblogs.com/2575590018dqy/p/10053353.html

  5. 网易2019校招内推编程题-俄罗斯方块-C++实现

    [编程题] 俄罗斯方块 时间限制:1秒 空间限制:262144K 小易有一个古老的游戏机,上面有着经典的游戏俄罗斯方块.因为它比较古老,所以规则和一般的俄罗斯方块不同.荧幕上一共有 n 列,每次都会有 ...

  6. Nginx+Tomcat配置负载均衡(一)

    关于负载均衡原理方面的知识点不在本文讨论范畴,本文主要就负载均衡配置过程中的细节部分配置做详细说明. 本次负载均衡大致的配置如下: 环境 : WIN7 + VM虚拟机3台(centos6.5) Ngi ...

  7. imeiimsi生成规则

    添加SMI 和 IMSI修改  添加模拟器名修改(MEmu_ 修改成其他的名字,不支持批量修改)   IMSI第十位:7代表是145卡,6代表186卡,3代表156,0代表130,其他的可以自己找 预 ...

  8. thinkphp5.0--编写api,返回json格式

    前几天没有写php代码,今天写了一下,今天的任务主要是构建自己的异常体系类,出现一个问题,就是返回结果不是json格式,而是一个页面,我找了一两个小时,没有找到问题,以为代码的问题,用断点调试了一通, ...

  9. UML第二次作业:类在类图中的表示

    类在类图中的表示 一.概览 1.plant UML语法学习小结 2.班级学生管理系统中的 —— “学生” 类的属性.方法 3.类图脚本程序 4.类图示例 二.类图语法学习小结 1.类之间的关系 通过某 ...

  10. tensorflow模型ckpt转pb以及其遇到的问题

    使用tensorflow训练模型,ckpt作为tensorflow训练生成的模型,可以在tensorflow内部使用.但是如果想要永久保存,最好将其导出成pb的形式. tensorflow已经准备好c ...