1、环境
服务器名称 | IP地址 | 备注 |
db-161-131 | 10.32.161.131 | 主 |
db-161-132 | 10.32.161.132 | 从 |
2、MariaDB安装
参考:https://www.cnblogs.com/a120608yby/p/17312862.html
3、修改配置并重启服务
# 主节点主要配置 # vim /etc/my.cnf ... server-id = 131 log_bin = mysql-bin ... # 从节点主要配置 # vim /etc/my.cnf ... server-id = 132 log_bin = mysql-bin read_only = 1 report-host = node04 ... # 重启MariaDB服务 systemctl restart mariadb # 在主节点上创建复制账号 > grant replication slave on *.* to repl_user@'%' identified by 'password'; > flush privileges;
4、备份主节点数据并在从节点恢复
# 在主节点上备份数据 mkdir /data/backup -p mariabackup --backup --target-dir /data/backup/ -u root # 同步备份数据到从节点 scp -r /data/backup/ 10.32.161.132:/data # 停止从节点服务并删除数据 systemctl stop mariadb rm -rf /var/lib/mysql/* # 在恢复任务之前运行准备任务(从节点) mariabackup --prepare --target-dir /data/backup/ # 运行恢复(从节点) mariabackup --copy-back --target-dir /data/backup/ # 修改数据库目录权限 chown -R mysql. /var/lib/mysql # 启动数据库服务 systemctl start mariadb
5、主从复制配置
# 查看binlog及position # cat /data/backup/xtrabackup_binlog_info mysql-bin.000001 27392 [] mysql-bin.000002 647 [] mysql-bin.000003 385 0-1-43 # 登录从节点配置复制 > change master to master_host='10.32.161.131', master_user='repl_user', master_password='password', master_log_file='mysql-bin.000003', master_log_pos=385; # 启动复制 > start slave; # 查看复制状态 > show slave status\G
标签:--,data,主从,集群,mysql,master,MariaDB,backup,节点 From: https://www.cnblogs.com/a120608yby/p/17314545.html