数据库MYSQL&MariaDB研究所

mariaDB主从搭建

2020-01-13  本文已影响0人  百里江山

一. 环境

  1. CentOS7
  2. master: 192.168.21.22
  3. slave: 192.168.21.23

二. master配置文件

cp /usr/share/mysql/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
#开启二进制日志记录
log-bin=mysql-bin
# ignore sync databases;
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
# master设置1
server-id       = 1

三. master配置

  1. 使用grant replication 命令创建1个专用于主从复制的帐号
  2. 注意访问权限设置'marry'@'192.168.21.%', 代表192.168.21.1~192.168.21.255的IP访问都可以.
# 在master上创建一个用于复制的帐号.帐号名:repl, 密码: 123456, 授权*.* 所有的库与表
grant replication slave, replication client on *.* to repl@'192.168.21.%' identified  by '123456';
# 查看master状态
show master status

四. slave配置

cp /usr/share/mysql/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
#开启二进制日志记录
log-bin=mysql-bin
# 开启只读权限
read_only = 1
# 中继日志
relay-log = /var/lib/mysql/mysql-relay-bin
# 允许备库将其重放的事件也记录到自身的二进制日志中.
log_slave_updates = 1
# slave设置
server-id       = 2

启动复制

五. 测试验证

六. look help

  1. help change master to

七. 遇到的坑

重启mariadb报错

[root@kubernetes ~]# systemctl restart mariadb
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

一般采用yum install mariadb mariadb-server安装的情况下

进入cd /usr/share/mysql 这个目录下有5个cnf后缀的文件,其实是为用户准备不同需求的配置文件

./my-huge.cnf  # 适合1~2G内存
./my-innodb-heavy-4G.cnf # 适合4G内存的
./my-large.cnf #适合512M的
./my-medium.cnf #适合32~64M
./my-small.cnf #适合小于64M

可以参考官方文档: http://dev.mysql.com/doc/mysql/en/option-files.html

连接master时报错

MariaDB [(none)]> change master to master_host='192.168.21.22',master_port=3306,master_user='marry',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=245;
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MariaDB error log
>stop slave 
>reset slave

参考

  1. https://blog.csdn.net/u012982280/article/details/80093933
上一篇下一篇

猜你喜欢

热点阅读