1.准备来两台虚拟机,并修改主机名称
192.168.223.159 mysql1
192.168.223.160 mysql2
2.配置hosts文件
3.两个节点安装数据库服务
yum install -y mariadb mariadb-server
4.两个节点启动数据库服务并设置开机自启
systemctl start mariadb systemctl enable mariadb
5.初始化数据库 配置数据库root密码为000000
mysql_secure_installation
6.修改mysql1节点的数据库配置文件
vi /etc/my.cnf
7.修改mysql2节点的数据库配置文件
8.重启数据库服务,并进入数据库
systemctl restart mariadb
mysql -uroot -p123456
9.创建节点
grant all privileges on *.* to root@'%' identified by "000000"; grant replication slave on *.* to 'user'@'mysql2' identified by '000000';
10.在从节点mysql2上登录MariaDB数据库
mysql -uroot -p000000
stop slave change master to master_host='mysql1',master_user='user',master_password='000000';
start slave
11.查询
show slave status\G