Mysql-5.7主从部署-yum方式
一、环境准备
# rpm -qa |grep mariadb |xargs yum remove -y
# setenforce 0(临时关闭),(selinux配置文件:SELINUX=disabled,需重启生效)
# systemctl stop iptables
# systemctl stop firewalld
# systemctl disable firewalld.service
二、安装MySQL 5.7(2个节点都需要安装)
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# yum -y install mysql57-community-release-el7-10.noarch.rpm
# yum -y install mysql-community-server
三、配置MySQL
- more /var/log/mysqld.log 查看初始口令
- 修改初始口令(2个节点都需要修改)
# set global validate_password_length=4;(重启失效)
# set global validate_password_policy=0;(重启失效)
# ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
- 配置IPV4端口(2个节点都需要配置)
# echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
# echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6
##在/etc/my.conf下面添加bind-address=0.0.0.0,重启mysql数据库
四、配置主从
主节点:
1.配置文件my.cof中添加下列
#启用二进制日志
log-bin=mysql-bin
#服务器唯一ID,一般取IP最后一段
server-id=195(自定义一个不重复数值)
- 新建同步账号slave
# CREATE USER 'slave'@'%' IDENTIFIED BY '密码';
# GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
# flush privileges;
- 记录信息
# show master status;
从节点:
1.配置文件my.cof中添加下列
server-id=215(自定义一个不重复数值)
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
- 建立主从连接
# change master to master_host='10.27.134.195', master_user='slave', master_password='密码', master_port=3306, master_log_file='mysql-bin.000006(主节点file号)', master_log_pos= 154(主节点日志号), master_connect_retry=30;
- 查看连接状态
# show slave status \G;
五、主从验证
- 在主节点上新建库
# create database hfzwy;
- 在从节点上查看是否同步
# show databases;
本文来自博客园,作者:苏冷,转载请注明原文链接:https://www.cnblogs.com/jiangshusheng/p/15853289.html