/**PageBeginHtml Block Begin **/ /***自定义返回顶部小火箭***/ /*生成博客目录的JS 开始*/ /*生成博客目录的JS 结束*/

mysql 8 集群搭建


1.下载必要的rpm包

登录mysql官网下载:https://dev.mysql.com/downloads/mysql/

我系统是centos 7 的所以选择红帽的操作系统

2.安装mysql 先用sudo root运行,我这是直接su root切换了root用户

1
2
3
4
5
yum remove mariadb-libs
rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm

  

 

 3.启动mysql

1
service mysqld start

 

 4.查看密码

1
grep 'temporary password' /var/log/mysqld.log

 

 

  5.修改密码

 

1
mysql -uroot -p

  输入密码

1
#Root_123456 是新密码,如果出现<br>ERROR 1819 (HY000): Your password does not satisfy the current policy requirements<br>是因为密码太简单,要改成带特殊字符的复杂密码
1
alter user 'root'@'localhost' IDENTIFIED BY '#Root_123456';

  

 

 

修改成功

 6:设置允许远程登录

 

1
2
use mysql;
update user set host='%' where user = 'root';

 

 

 

然后重启mysql

1
service mysqld restart

7.搭建集群  

 准备三台集群

修改hosts文件

1
2
3
4
vi /etc/hosts<br>
192.168.10.11 linux1
192.168.10.12 linux2
192.168.10.13 linux3  

设置免密

1
2
3
4
ssh-keygen -t rsa
ssh-copy-id linux1
ssh-copy-id linux2
ssh-copy-id linux3  

设置远程登录并且刷新

1
2
3
grant all privileges on *.* to 'root'@'%' with grant option;
 
flush privileges;

 

 

安装 mysqlsh

1
rpm -ivh mysql-shell-8.0.20-1.el7.x86_64.rpm

  

  

 

 

登录linux2安装mysql8

在linux2/linu3从linux1 拷贝所有rpm包到本地

1
scp -r linux1:/opt/software/ /opt/software/

 

 

然后安装

然后用mysqlsh搭建

1
2
3
4
5
6
7
8
9
shell.connect('root@linux1:3306')
dba.configureLocalInstance()
shell.connect('root@linux2:3306')
dba.configureLocalInstance()
shell.connect('root@linux3:3306')
dba.configureLocalInstance()
 
shell.connect('root@linux1:3306')
var cluster=dba.createCluster("MySQL_Cluster")

  

如果不想用root用户,建议用root用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
set sql_log_bin=0;
create user rpl_user@'%' identified by '#Root_123456';
grant replication slave,replication client on *.* to rpl_user@'%';
create user rpl_user@'127.0.0.1' identified by '#Root_123456';
grant replication slave,replication client on *.* to rpl_user@'127.0.0.1';
create user rpl_user@'localhost' identified by '#Root_123456';
grant replication slave,replication client on *.* to rpl_user@'localhost';
set sql_log_bin=1;
 
change master to
        master_user='rpl_user',
        master_password='#Root_123456'
        for channel 'group_replication_recovery';
 
install plugin group_replication soname 'group_replication.so';
 
set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;

  关闭防火墙

1
2
3
4
5
6
# 关闭防火墙
systemctl stop firewalld.service
# 禁用防火墙
systemctl disable firewalld.service
vi /etc/selinux/config
SELINUX=disabled

  

安装mysql-router

1
rpm -ivh mysql-router-community-8.0.20-1.el7.x86_64.rpm
1
vim /etc/mysqlrouter/mysqlrouter.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[DEFAULT]
logging_folder = /var/log/mysqlrouter
runtime_folder = /var/run/mysqlrouter
config_folder = /etc/mysqlrouter
 
[logger]
level = INFO
[routing:read_write]
bind_address = 192.168.10.11
bind_port = 7001
mode = read-write
destinations = linux1:3306,linux2:3306
protocol=classic
max_connections=1024
 
[routing:read_only]
bind_address = 192.168.10.11
bind_port = 7002
mode = read-only
destinations = linux1:3306,linux2:3306
protocol=classic
max_connections=1024
# If no plugin is configured which starts a service, keepalive
# will make sure MySQL Router will not immediately exit. It is
# safe to remove once Router is configured.
[keepalive]
interval = 60

 重启mysqlrouter

1
systemctl restart mysqlrouter

  

 

  

  

  

 

为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
转载请标注出处!
posted @ 2021-06-03 09:05  一品堂.技术学习笔记  阅读(46)  评论(0编辑  收藏  举报