一、环境准备
# 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
# set global validate_password_length=4;(重启失效)
# set global validate_password_policy=0;(重启失效)
# ALTER USER \'root\'@\'localhost\' IDENTIFIED BY \'新密码\';
# 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(自定义一个不重复数值)
# 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
图文来源于网络,如有侵权请联系删除。