MySQL5.7主从同步、读写分离
环境:CentOS7.9
工具:Xshell 7
安装MySQL5.7
下载rpm包
wget /
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-client-5.7.32-1.el7.x86_64.rpm
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-common-5.7.32-1.el7.x86_64.rpm
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-5.7.32-1.el7.x86_64.rpm
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-server-5.7.32-1.el7.x86_64.rpm
安装
yum install -y mysql-community-*-5.7.32-1.el7.x86_64.rpm
启动mysql查看密码
cat /var/log/mysqld.log | grep password
登录mysql
mysql -u root -p
主从同步
关闭每台服务器的防火墙和selinux
systemctl disable –now firewalld
setenforce 0
主从服务器时间同步
主服务器使用本地时钟源
yum -y install ntp
修改配置文件
vi /etc/ntp.conf
server 127.127.136.0
fudge 127.127.136.0 stratum 8
开启ntpd
systemctl start ntpd
从服务器同步主服务器时间
安装ntp工具
启动ntp和主服务器进行时间同步
主服务器mysql配置
修改配置文件
vi /etc/my.conf
server_id = 11
log_bin=master_bin
log_slave_updates=true
重启mysql
给从服务器权限
grant replication slave on *.* to ‘myslave’@’43.248.136.%’ identified by ‘1234’;
出现错误
用 alter user修改密码
密码政策出错
set global validate_password_length=4;
set global validate_password_policy=0;
alter user root@localhost identified by ‘1234’;
查看日志位置
配置从服务器并重启
Vi /etc/my.conf
server-id = 2
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
登录mysql配置主从同步
change master to master_host=’43.248.136.97′,master_user=’myslave’,master_password=’1234′,master_log_file=’master-bin.000001′,master_log_pos=154;
start slave;
show slave status/G;
测试
读写分离
关闭防火墙
systemctl stop firewalld
setenforce 0
Amoeba服务器环境安装
安装jdk
1、查看yum库中有哪些版本
yum search java|grep jdk
2、选择指定版本安装,yum源安装的是OpenJDK
yum install java-1.8.0-openjdk*
3、安装完成后查看版本
Java -version
4、修改配置文件
cd /usr/lib/jvm
ls
vi /etc/profile
安装amoeba
创建amoeba文件夹,使用rz命令从本地放入系统,解压文件
tar -zxf amoeba-mysql-binary-2.2.0.tar.gz
设置文件夹权限
查看是否安装完成
如果这种报错
修改 vi /usr/local/amoeba/bin/amoeba
配置Amoeba读写分离
Mysql服务器添加权限和用户开放给amoeba
grant all on *.* to ‘anyu’@’43.248.136.%’ identified by ‘123.com’;
配置amoeba服务器文件
vi conf/amoeba.xml
vi conf/dbServers.xml
启动
查看服务是否成功,监听端口为8066为成功启动
原创文章,作者:wdmbts,如若转载,请注明出处:https://blog.ytso.com/278257.html