准备环境: 两台centos7.6虚拟机(能联网的)
1.配置网卡更改ip为静态ip
2.关闭防火墙,关闭开机自启 关闭selinux
1.systemctl stop firewalld 关闭防火墙
2.systemctl disable firewalld 关闭防火墙开机自启
3.setenforce 0 临时关闭selinux
4.vim /etc/selinux/config 把SELINUX=enforcing 中enforcing修改成disabled
3.安装mariadb
1.yum install mariadb mariadb-server -y 安装mariadb
4.启动mariadb并设置开机自启
1.systemctl enable mariadb --now
(上面步骤两台机器都要做)
主服务器操作
1.vim /etc/my.cnf.d/server.cnf打开配置文件
2.在[mariadb]下添加两行内容
server_id = 1log-bin=mysql-bin
3.systemctl restart mariadb 重新mariadb
从服务器操作
1.vim /etc/my.cnf.d/server.cnf打开配置文件
2.在[mariadb]下添加两行内容
server_id = 2log-bin=mysql-bin
3.systemctl restart mariadb 重新mariadb
主服务器操作
1.进入数据库 mysql -uroot
2.建立用于从库复制账号slave 设置权限
create user 'slave'@'%' identified by '123456';grant replication slave on *.* to 'slave'@'%';flush privileges;
3.锁表
flush tables with read lock;
4.检测创建结果
select user,host from mysql.user;
4.检测主库状态信息
show master status;
把mysql-bin.000001这个复制一下
后面那个数字记下来 后面会用到
从库操作
1.登录数据库
mysql -uroot
2.配置复制参数
剩下内容都在笔记里面自己去看吧,里面有图片,有什么问题可以留言
笔记网址:




举报 0