Linux下安装mysql innoDB cluster
一 准备安装环境:
1.准备centos 7系统.
2.
清空安装环境
[[email protected] ~]# yum list |grep mari
[[email protected] ~]# yum remove mariadb-libs.x86_64
二 安装
1. 下载安装包
mysql80-community-release-el7-1.noarch
,传入虚拟机
2. Yum
安装
mysql80-community-release-el7-1.noarch
包,
yum
源
[[email protected] /]# yum install mysql80-community-release-el7-1.noarch.rpm
2.1
[[email protected] /]# yum makecache
2.2
查看安装包
[[email protected] /]# yum list|grep mysql
2.3
安装
mysql-community-server.x86_64
[[email protected] /]# yum install -y mysql-community-server.x86_64
2.4
安装
mysql-shell.x86_64 mysql-router.x86_64
[[email protected] /]# yum install -y mysql-shell.x86_64 mysql-router.x86_64
3.
进入
mysqlsh
初始化
mysql
实例
3.1
查看命令
MySQL JS > \? dba
NAME
dba - Global variable for InnoDB cluster management.
DESCRIPTION
The global variable dba is used to access the AdminAPI functionality and
perform DBA operations. It is used for managing MySQL InnoDB clusters.
PROPERTIES
verbose
Enables verbose mode on the dba operations.
FUNCTIONS
checkInstanceConfiguration
(instance[, options])
Validates an instance for MySQL InnoDB Cluster usage.
configureInstance
([instance][, options])
Validates and configures an instance for MySQL InnoDB Cluster
usage.
configureLocalInstance
(instance[, options])
Validates and configures a local instance for MySQL InnoDB Cluster
usage.
createCluster
(name[, options])
Creates a MySQL InnoDB cluster.
deleteSandboxInstance
(port[, options])
Deletes an existing MySQL Server instance on localhost.
deploySandboxInstance
(port[, options])
Creates a new MySQL Server instance on localhost.
dropMetadataSchema
(options)
Drops the Metadata Schema.
getCluster
([name][, options])
Retrieves a cluster from the Metadata Store.
help([member])
Provides help about this object and it‘s members
killSandboxInstance
(port[, options])
Kills a running MySQL Server instance on localhost.
rebootClusterFromCompleteOutage
([clusterName][, options])
Brings a cluster back ONLINE when all members are OFFLINE.
startSandboxInstance
(port[, options])
Starts an existing MySQL Server instance on localhost.
stopSandboxInstance
(port[, options])
Stops a running MySQL Server instance on localhost.
For more help on a specific function use: dba.help(‘‘)
e.g. dba.help(‘deploySandboxInstance‘)
3.2
创建端口为
3310
、
3320
、
3330
的实例
MySQL JS > dba.deploySandboxInstance(3310)
4.
创建集群
4.1
进入端口
3310
的实例
MySQL JS > \connect [email protected]:3310
4.2
定义集群
MySQL localhost:3310 ssl JS > var cluster=dba.createCluster(‘test‘)
4.3
集群中加入实例
3320
、
3330
MySQL localhost:3310 ssl JS > cluster.addInstance(‘[email protected]:3320‘)
MySQL localhost:3310 ssl JS > cluster.addInstance(‘[email protected]:3330‘)
5. Mysqlrouter
启动
5.1
连接
3310
mysqlrouter --bootstrap [email protected]:3310 --user=mysqlrouter
5.2
编辑
mysqlrouter
配置文件
[[email protected] ~]# vi /etc/mysqlrouter/mysqlrouter.conf
5.3
开启
mysqlrouter
[[email protected] ~]# mysqlrouter &
[1] 11085
6.
通过
mysqlrouter
连入实例
[[email protected] ~]# mysql -uroot -h 127.0.0.1 -P 6446 -poracle
[[email protected] ~]# mysql -uroot -h 192.168.80.164 -P 6446 -poracle
7.
查看集群状态
7.1
连入实例
3310
,获取数据
MySQL JS > \connect [email protected]:3310
MySQL localhost:3310 ssl JS > cluster=dba.getCluster()
7.2
查看状态
MySQL localhost:3310 ssl JS > cluster.status()
MySQL localhost:3310 ssl JS > cluster=dba.getCluster()cluster.status()cluster.status()
{
"clusterName": "test",
"defaultReplicaSet": {
"name": "default",
"primary": "localhost:3310",
"ssl": "REQUIRED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"localhost:3310": {
"address": "localhost:3310",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3320": {
"address": "localhost:3320",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3330": {
"address": "localhost:3330",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
}
},
"groupInformationSourceMember": "mysql://[email protected]:3310"
}
8.
查看
mysql
进程
[[email protected] ~]# ps -ef |grep mysql
9.
通过
socket
连入
3310
实例
[[email protected] 3310]# mysql -uroot -poracle -S /root/mysql-sandboxes/3310/sandboxdata/mysqld.sock