1. 程式人生 > 其它 >MySQL8叢集搭建(innodb cluster)

MySQL8叢集搭建(innodb cluster)

1 基本環境

1.1 作業系統

Linux centos3 3.10.0-327.el7.x86_64(關閉防火牆,關閉selinux)

1.2 準備rpm包

1.2.1 MySQL8安裝包

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-server-8.0.19-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-client-8.0.19-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-common-8.0.19-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-libs-8.0.19-1.el7.x86_64.rpm

1.2.2 MySQL8 Cluster安裝包

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7/mysql-router-8.0.12-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7/mysql-shell-8.0.12-1.el7.x86_64.rpm

2 安裝mysql

2.1 安裝rpm包

yum remove mariadb-libs
rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm

2.2 啟動mysql

service mysqld start

2.3 修改密碼

2.3.1 檢視密碼

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

2.3.2 修改密碼

用臨時密碼進入mysql,輸入ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';
然後輸入flush privileges;
quit
即可修改密碼成功

2.4 設定允許遠端訪問

2.4.1 登入mysql

mysql -uroot -p

2.4.2 設定允許遠端訪問

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

3.4.2 重啟服務

service mysqld restart

3 安裝叢集

3.1 準備三臺伺服器

10.10.10.201,主機名:centos1,角色:管理節點、資料節點
10.10.10.202,主機名:centos2
10.10.10.203,主機名:centos3

3.2 三臺伺服器設定hosts

vim /etc/hosts

新增

10.10.10.201 centos1
10.10.10.202 centos2
10.10.10.203 centos3

3.3 三臺伺服器設定免密

ssh-keygen -t rsa
ssh-copy-id centos1
ssh-copy-id centos2
ssh-copy-id centos3

3.4 三臺伺服器安裝MySQL

參見步驟2

3.5 三臺伺服器Mysql賦予root使用者所有許可權

3.5.1 登入mysql

mysql -uroot -p

3.5.2 設定允許遠端訪問

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

3.6 centos1上安裝mysql-shell

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

3.7 centos1上進入mysql-shell並建立叢集

3.7.1 進入mysql-shell

mysqlsh

3.7.2 建立叢集

shell.connect('root@centos1:3306')
dba.configureLocalInstance()
shell.connect('root@centos2:3306')
dba.configureLocalInstance()
shell.connect('root@centos3:3306')
dba.configureLocalInstance()

shell.connect('root@centos1:3306') 
var cluster=dba.createCluster("MySQL_Cluster")