利用mysql shell搭建MGR

打印 上一主题 下一主题

主题 565|帖子 565|积分 1695

预备环境

资源有限只需要预备一台Linux主机
腾讯云主机159.75.158.18
(1)规划部署
主机端口配置文件数据目次159.75.158.183381/etc/my3381.cnf/data/3381/data159.75.158.183382/etc/my3382.cnf/data/3382/data159.75.158.183383/etc/my3383.cnf/data/3383/data (2)预备实例配置文件
编辑3个配置文件,分别是
my3381.cnf
my3382.cnf
my3383.cnf
配置文件内容以my3383.cnf为例
将此中对应的数字3383 改为对应端口到差别配置文件
  1. [mysqld]
  2. log_timestamps=SYSTEM
  3. user=mysql
  4. basedir=/usr/local/mysql8
  5. datadir=/data/3383/data
  6. log_bin=/data/3383/binlog/mysql-bin
  7. port=3383
  8. server_id=20243383
  9. socket=/tmp/mysql3383.sock
  10. gtid-mode=on
  11. enforce-gtid-consistency=true
  12. log_slave_updates=1
  13. relay_log_info_repository=TABLE
  14. master_info_repository=TABLE
  15. relay_log_recovery=on
复制代码
(3)创建目次
  1. mkdir -p /data/3381/data
  2. mkdir -p /data/3381/binlog
  3. mkdir -p /data/3382/data
  4. mkdir -p /data/3382/binlog
  5. mkdir -p /data/3383/data
  6. mkdir -p /data/3383/binlog
  7. chown mysql.mysql -R /data
复制代码
(4)初始化和启动库
  1. /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3381.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3381/data --user=mysql &
  2. /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3382.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3382/data --user=mysql &
  3. /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3383.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3383/data --user=mysql &
  4. /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3381.cnf --user=mysql &
  5. /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3382.cnf --user=mysql &
  6. /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3383.cnf --user=mysql &
复制代码
(5)创建账号
为了简化步调,直接执行
  1. 三个库都执行
  2. mysql> create user admin@'%' identified by 'admin';
  3. Query OK, 0 rows affected (0.02 sec)
  4. mysql> grant all on *.* to admin@'%' with grant option;
  5. Query OK, 0 rows affected (0.01 sec)
复制代码
此步调不规范,正常操作应当是
Create a new admin account for InnoDB cluster with minimal required grants
#在当地通过socket方式登入
$ mysqlsh -S /data/****/mysql.sock root@localhost
执行
dba.configureInstance()
选择
2) Create a new admin account for InnoDB cluster with minimal required grants
数据用户和暗码
在利用
mysqlsh --uri 用户@IP:端口 进入mysql shell界面
搭建MySQL shell环境

(1)下载:
https://dev.mysql.com/downloads/shell/
下载的shell版本和数据库版本保持一致
(2)解压
tar -zxvf mysql-shell-8.0.25-linux-glibc2.12-x86-64bit.tar.gz -C /opt/idc/mysql-shell8.0.25
(3)配置环境变量
vi /etc/profile
export PATH=/opt/idc/mysql-shell8.0.25/binPATH
source /etc/profile
利用shell搭建MGR

(1)查抄是否适配MGR节点
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3381’)
  1. MySQL  JS > dba.checkInstanceConfiguration('admin@159.75.158.18:3381')
  2. Validating MySQL instance at VM-20-8-centos:3381 for use in an InnoDB cluster...
  3. This instance reports its own address as VM-20-8-centos:3381
  4. Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.
  5. Checking whether existing tables comply with Group Replication requirements...
  6. No incompatible tables detected
  7. Checking instance configuration...
  8. Instance configuration is compatible with InnoDB cluster
  9. The instance 'VM-20-8-centos:3381' is valid to be used in an InnoDB cluster.
  10. {
  11.     "status": "ok"
  12. }
复制代码
另外两台节点需要做此操作
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3382’)
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3383’)
如果此步报错说不符合MGR节点要求,执行第二步
(2)
执行 dba.configureInstance() 命令开始查抄当前实例是否满足安装MGR集群的条件,如果不满足可以直接配置成为MGR集群的一个节点:
dba.configureInstance(‘admin@159.75.158.18:3381’)
  1. dba.configureInstance('admin@159.75.158.18:3381')
  2. Configuring MySQL instance at VM-20-8-centos:3381 for use in an InnoDB cluster...
  3. This instance reports its own address as VM-20-8-centos:3381
  4. Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.
  5. applierWorkerThreads will be set to the default value of 4.
  6. The instance 'VM-20-8-centos:3381' is valid to be used in an InnoDB cluster.
  7. The instance 'VM-20-8-centos:3381' is already ready to be used in an InnoDB cluster.
  8. Successfully enabled parallel appliers.
复制代码
根据需要选择YES,后再返回执行第一个,看结果是否是OK
另外两个节点同样执行相同步调
dba.configureInstance(‘admin@159.75.158.18:3382’)
dba.configureInstance(‘admin@159.75.158.18:3383’)
(3)连接主节点
MySQL JS > \connect admin@159.75.158.18:3381
(4)创建集群
dba.createCluster(‘mgrCluster’)
var cluster = dba.getCluster()
(5)添加节点
这里要指定MGR专用账号,我们用的是测试账户不符合规范
cluster.addInstance(‘admin@159.75.158.18:3382’)
cluster.addInstance(‘admin@159.75.158.18:3383’)
(6)查看集群状态
cluster.status()
  1. 查看集群状态
  2.   MySQL  159.75.158.18:3381 ssl  JS > cluster.status()
  3.   {
  4.     "clusterName": "mgrCluster",
  5.     "defaultReplicaSet": {
  6.         "name": "default",
  7.         "primary": "VM-20-8-centos:3381",
  8.         "ssl": "REQUIRED",
  9.         "status": "OK",
  10.         "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
  11.         "topology": {
  12.             "VM-20-8-centos:3381": {
  13.                 "address": "VM-20-8-centos:3381",
  14.                 "memberRole": "PRIMARY",
  15.                 "mode": "R/W",
  16.                 "readReplicas": {},
  17.                 "replicationLag": null,
  18.                 "role": "HA",
  19.                 "status": "ONLINE",
  20.                 "version": "8.0.25"
  21.             },
  22.             "VM-20-8-centos:3382": {
  23.                 "address": "VM-20-8-centos:3382",
  24.                 "memberRole": "SECONDARY",
  25.                 "mode": "R/O",
  26.                 "readReplicas": {},
  27.                 "replicationLag": null,
  28.                 "role": "HA",
  29.                 "status": "ONLINE",
  30.                 "version": "8.0.25"
  31.             },
  32.             "VM-20-8-centos:3383": {
  33.                 "address": "VM-20-8-centos:3383",
  34.                 "memberRole": "SECONDARY",
  35.                 "mode": "R/O",
  36.                 "readReplicas": {},
  37.                 "replicationLag": null,
  38.                 "role": "HA",
  39.                 "status": "ONLINE",
  40.                 "version": "8.0.25"
  41.             }
  42.         },
  43.         "topologyMode": "Single-Primary"
  44.     },
  45.     "groupInformationSourceMember": "VM-20-8-centos:3381"
  46. }
复制代码
R/O是只读,R/W是读写,PRIMARY是主节点。
补充

切换到多主模式
cluster.switchToMultiPrimaryMode()
切换到单主模式
cluster.switchToSinglePrimaryMode(‘159.75.158.18:3381’)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

三尺非寒

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表