CentOS7安装MariaDB并配置主从同步

环境声明:

防火墙firewalld及SElinux均为关闭状态

主库节点:192.168.0.63

从库节点:192.168.0.64

配置主库节点:

前提:配置好yum软件安装源

yum install mariadb-server

vim /etc/my.cnf

主库节点mariadb配置文件/etc /my.cnd

[mysqld]
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
log-bin=mysql-bin
server-id=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 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

配置文件补充说明:

binlog-ignore-db 用来指定忽略同步的数据库,未指定的默认都进行主从复制。

log-bin 指定数据库操作日志,主从复制的过程本质就是从数据库在主数据库读取该日志,并且再执行一次。

server-id 只要满足在数据库集群中不重复即可且必须不能重复

保存退出,重启Mysqld服务,使配置生效。修改到配置文件,最好都重启该配置相关的程序或服务。

systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
Enter current password for root (enter for none): # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n] # 设置密码,y
New password: # 新密码
Re-enter new password: # 再次输入密码
Remove anonymous users? [Y/n] # 移除匿名用户, y
Disallow root login remotely? [Y/n] # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it? [Y/n] # 删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要
Reload privilege tables now? [Y/n] # 重新加载权限表,y。或者重启服务也许

MariaDB [(none)]> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000003 # slave根据此信息进行数据同步

Position: 1208 # slave根据此信息进行数据同步

Binlog_Do_DB:

Binlog_Ignore_DB: mysql,information_schema

1 row in set (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> GRANT REPLICATION SLAVE ON . to 'slave'@'192.168.0.64' identified by 'root'

-> ;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.0.63' IDENTIFIED BY 'root' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.0.64' IDENTIFIED BY 'root' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit

Bye

[root@cosmo-0-63 yum.repos.d]# systemctl restart mariadb

至此主库配置完毕

配置从库节点:

安装步骤和主库一样

配置文件修改

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=2 # 添加此行
# 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

然后重启mariadb,进行登陆

执行sql语句:change master to master_host='192.168.0.63',master_user='slave',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=1208;
MariaDB [(none)]> change master to master_host='192.168.0.63',master_user='slave',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=1208;
MariaDB [(none)]> slave start;
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.0.63
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 1208
Relay_Log_File: mariadb-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Connecting
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: 1208
Relay_Log_Space: 245
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: NULL
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: 0
1 row in set (0.00 sec)

只有当Slave_IO_Running和Slave_SQL_Running都显示Yes时,才表示主从复制配置成功。否则失败,检查上述配置过程。

主从复制验证:

首先,在主数据建立一个demo数据库,看两个从数据库是否会自动进行复制。

在服务器A登录主数据库,查看现有数据库。

63主库节点:

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec) MariaDB [(none)]> create database demo;
Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| demo |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

然后登陆64节点进行查看

能看到在63上创建的demo库则代表配置主从成功

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| demo |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

THE END

CentOS7安装配置MariaDB(mysql)数据主从同步的更多相关文章

  1. MySql数据主从同步配置

    由于需要配置MySQL的主从同步配置,现将配置过程记录下,已被以后不时之需 MySql数据主从同步   1.1. 同步介绍 Mysql的 主从同步 是一个异步的复制过程,从一个 Master复制到另一 ...

  2. Centos7 安装配置优化mysql(mariadb分支)

    1.说明 由于在centos7的yum仓库中没有mysql,centos7用mariadb替代了mysql. mariadb是mysql源代码的一个分支, mysql被ORACLE闭源,而mariad ...

  3. 生产环境高可用centos7 安装配置RocketMQ-双主双从-同步双写(2m-2s-sync)

    添加hosts信息[四台机器] vim /etc/hosts 192.168.119.130 rocketmq-nameserver1 192.168.119.130 rocketmq-master1 ...

  4. MySQL数据库主从同步安装与配置总结

    MySQL的主从同步是一个很成熟的架构,优点为: ①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力: ②在从主服务器进行备份,避免备份期间影响主服务器服务: ③当主服务器出现问题时 ...

  5. Linux下MySQL数据库主从同步配置

    说明: 操作系统:CentOS 5.x 64位 MySQL数据库版本:mysql-5.5.35 MySQL主服务器:192.168.21.128 MySQL从服务器:192.168.21.129 准备 ...

  6. Centos7安装配置Apache+PHP+Mysql+phpmyadmin

    转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...

  7. mysql数据库主从同步

    环境: Mater:   CentOS7.1  5.5.52-MariaDB  192.168.108.133 Slave:   CentOS7.1  5.5.52-MariaDB  192.168. ...

  8. Mysql数据实时同步

    企业运维的数据库最常见的是 mysql;但是 mysql 有个缺陷:当数据量达到千万条的时候,mysql 的相关操作会变的非常迟缓; 如果这个时候有需求需要实时展示数据;对于 mysql 来说是一种灾 ...

  9. mysql数据库主从同步读写分离(一)主从同步

    1.mysql数据库主从同步读写分离 1.1.主要解决的生产问题 1.2.原理 a.为什么需要读写分离? 一台服务器满足不了访问需要.数据的访问基本都是2-8原则. b.怎么做?  不往从服务器去写了 ...

随机推荐

  1. 【51nod 1824】染色游戏

    题目 有 n 个红球, m 个蓝球,从中取出 x 个红球和 y 个蓝球排成一排的得分是 rx⋅by ,其中 r0=b0=1 . 定义 f(t) 表示恰好取出 t 个球排成一排的所有可能局面的得分之和. ...

  2. Burpsuite的Intruder模块发现敏感目录

    提前配置好浏览器的代理设置,并且成功访问了目标地址(这里是http://192.168.146.133/WackoPicko) 1.在burpsuite的proxy栏目中,找到对WackoPicko路 ...

  3. Apicloud_(问题)P54提示错误:Uncaught SyntaxError: Unexpected token ) at main.html : 117

    <30天App开发从0到1:APICloud移动开发实战>第54页 打开main.html,在apiready中添加一段代码 api.addEventListener({ name: 'c ...

  4. Unity3D_(API)Random随机数

    Unity随机数Random官方文档: 传送门 一.生成一个随机数 二.Random.InitState()生成伪随机数 三.官方文档中常用的方法 创建一个Cube用来挂载Random_Gary.cs ...

  5. python学习之路(9)

    函数的参数 定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道如何传递正确的参数,以及函数将返回什么样的值就够了,函数内部的复杂逻辑被封装起来,调 ...

  6. JS Generator yield

    function show() { console.log('a') console.log('b') } show() // 普通函数 function *show2() { console.log ...

  7. 【Spark机器学习速成宝典】模型篇08保序回归【Isotonic Regression】(Python版)

    目录 保序回归原理 保序回归代码(Spark Python) 保序回归原理 待续... 返回目录 保序回归代码(Spark Python) 代码里数据:https://pan.baidu.com/s/ ...

  8. What is the !! (not not) operator in JavaScript?

    What is the !! (not not) operator in JavaScript? 解答1 Coerces强制 oObject to boolean. If it was falsey ...

  9. Dubbo HA 高可用

    一.zookeeper 宕机 现象:zookeeper 注册中心宕机,还可以消费 dubbo 暴露的服务 健壮性  监控中心宕掉不影响使用,只是丢失部分采样数据  数据库宕掉后,注册中心仍能通过缓 ...

  10. java面试要点

    基础篇 基本功 面向对象的特征 final, finally, finalize 的区别 int 和 Integer 有什么区别 重载和重写的区别 抽象类和接口有什么区别 说说反射的用途及实现 说说自 ...