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 修改密碼
mysqladmin -p '上面查到的臨時密碼' password '新的密碼'
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")