• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >MariaDB > mariadb的主从复制、主主复制、半同步复制配置详解

mariadb的主从复制、主主复制、半同步复制配置详解

作者:运维部落 字体:[增加 减小] 来源:互联网 时间:2017-05-11

运维部落通过本文主要向大家介绍了mariadb主从复制,mariadb 主从,mariadb,mariadb使用教程,mariadb安装等相关知识,希望本文的分享对您有所帮助

主从服务器的时间要同步,数据库版本最好是一致的,以免造成函数处理、日志读取、日志解析等发生异常。

以下三个主从复制的设置是独立的。

注意防火墙和selinux的影响。

1、简单主从复制的实现

(1)主服务器的配置

1)安装mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)编辑/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下内容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 1 (id号不能跟从服务器相同)
    log-bin = master-log (自定义二进制日志文件名)

3)授权可以复制本地数据库信息的主机

[root@localhost ~]# systemctl start mariadb.service (启动mariadb server)

[root@localhost ~]# mysql
 MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'10.1.51.%' identified by 'replpasswd';
 MariaDB [(none)]> flush privileges;

MariaDB [(none)]> show master status\G (查看主服务器的状态信息,在从服务器中要用到)
*************************** 1. row ***************************
   File: master-log.000003 (正在使用的二进制日志文件)
  Position: 497 (所处的位置)
 Binlog_Do_DB: 
Binlog_Ignore_DB:

</div>

(2)从服务器的配置

1)安装mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)编辑/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下内容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 2 (id号不能跟主服务器相同)
    relay-log = slave-log (自定义二进制日志文件名)

3)设置要从哪个主服务器的那个位置开始同步

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql
 MariaDB [(none)]> change master to master_host='10.1.51.60',master_user='repluser',master_password='replpasswd',master_log_file='master-log.000003',master_log_pos=497;

MariaDB [(none)]> start slave; (启动复制功能)
MariaDB [(none)]> show slave status\G (查看从服务器的状态,下面显示的是部分内容)
 Master_Host: 10.1.51.60
 Master_User: repluser
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: master-log.000003
 Read_Master_Log_Pos: 497
 Relay_Log_File: slave-log.000002
 Relay_Log_Pos: 530
 Relay_Master_Log_File: master-log.000003
 Slave_IO_Running: Yes 
 Slave_SQL_Running: Yes
 Master_Server_Id: 1

</div>

(3)测试

1)在主服务器导入事先准备好的数据库

[root@localhost ~]# mysql < hellodb.sql

2)在从服务器查看是否同步

MariaDB [(none)]> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| hellodb   |(数据库已经同步)
| mysql    |
| performance_schema |
| test    |
+--------------------+
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> show tables; (hellodb数据库的表也是同步的)
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes   |
| coc    |
| courses   |
| scores   |
| students   |
| teachers   |
| toc    |
+-------------------+
</div>

2、双主复制的实现

(1)服务器1的配置

1)安装mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)编辑/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下内容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 1 (id号不能跟从服务器相同)
    log-bin = master-log (自定义主服务器的二进制日志文件名)
    relay-log = slave-log (自定义从服务器的二进制日志文件名)
    auto_increment_offset = 1
    auto_increment_increment = 2

3)在服务器2上查看的master状态

MariaDB [(none)]> show master status\G
*************************** 1. row ***************************
   File: master-log.000003
  Position: 422
 Binlog_Do_DB: 
Binlog_Ignore_DB:
</div>

4)启动mariadb server并进行如下配置

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql

 MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'10.1.51.%' identified by 'replpasswd';

 MariaDB [(none)]> change master to master_host='10.1.51.50',master_user='repluser',master_password='replpasswd',master_log_file='master-log.000003',master_log_pos=422;

 MariaDB [(none)]> start slave;

 MariaDB [(none)]> SHOW SLAVE STATUS\G (仅是部分内容)
  Master_Host: 10.1.51.50
  Master_User: repluser
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: master-log.000003
  Read_Master_Log_Pos: 422
  Relay_Log_File: slave-log.000002
  Relay_Log_Pos: 530
  Relay_Master_Log_File: master-log.000003
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Master_Server_Id: 2

</div>

(2)服务器2的配置

1)安装mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)编辑/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf
    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 2
    relay-log = slave-log
    lob-bin = master-log
    auto_increment_offset = 2
    auto_increment_increment = 2

3)在服务器1查看master状态

MariaDB [(none)]> show master status\G
*************************** 1. row ***************************
            File: master-log.000003
        Position: 245
    Binlog_Do_DB:
Binlog_Ignore_DB:

4)启动mariadb server并配置

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql

 MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'10.1.51.%' identified by 'replpasswd';

 MariaDB [(none)]> change master to master_host='10.1.51.60',master_user='repluser',master_password='replpasswd',master_log_file='master-log.000003',master_log_pos=245;

 MariaDB [(none)]> start slave;

 MariaDB [(none)]> show slave status\G (仅是部分内容) 
  Master_Host: 10.1.51.60
  Master_User: repluser
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: master-log.000003
  Read_Master_Log_Pos: 422
  Relay_Log_File: slave-log.000003
  Relay_Log_Pos: 530
  Relay_Master_Log_File: master-log.000003
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Master_Server_Id: 1

</div>

(3)测试

1)在任意一台服务器上创建mydb数据库

MariaDB [(none)]> create database mydb;

2)在另一台服务器上查

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • mariadb的主从复制、主主复制、半同步复制配置详解

相关文章

  • 2017-05-11centos中找回MariaDB数据库root用户权限的方法
  • 2017-05-11在Ubuntu系统中安装MariaDB数据库的教程
  • 2017-05-11Mysql/MariaDB启动时处于进度条状态导致启动失败的原因及解决办法
  • 2017-05-11MySQL分支选择参考:Percona还是MariaDB
  • 2017-05-11浅谈MySQL和mariadb区别
  • 2017-05-11MariaDB中的thread pool详细介绍和使用方法
  • 2017-05-11centos 7安装mysql5.5和安装 mariadb使用的命令
  • 2017-05-11详解Centos 使用YUM安装MariaDB
  • 2017-05-11记一次mariadb数据库无法连接
  • 2017-05-11MariaDB性能调优工具mytop的使用详解

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • CentOS 7中成功安装MariaDB的方法教程
    • MySQL分支选择参考:Percona还是MariaDB
    • 浅谈MySQL和mariadb区别
    • 记一次mariadb数据库无法连接
    • 关于mongoose连接mongodb重复访问报错的解决办法
    • CentOS安装和设置MariaDB的教程
    • 详解Centos 使用YUM安装MariaDB
    • Mac中MariaDB数据库的安装步骤
    • Mysql/MariaDB启动时处于进度条状态导致启动失败的原因及解决办法
    • MariaDB配置双主复制方案

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有