mo_ctl 分布式版工具指南

mo_ctl 分布式版是一款面向企业用户,协助用户部署 MatrixOne 分布式集群、安装相关组件并最终向用户提供 MatrixOne 服务的命令行工具

备注

mo_ctl 分布式版是一款专为企业级用户设计的高效数据库集群管理工具。如需获取该工具的下载路径,请与您的 MatrixOne 客户经理取得联系。

功能概览

mo_ctl 目前已经适配过操作系统如下表所示:

操作系统

版本

Debian

11 及以上

Ubuntu

20.04 及以上

UOS

20.0.0

Open EulerOS

20.3.0

mo_ctl 目前的功能列表如下表所示:

命令

功能

mo_ctl help

查看mo_ctl工具本身的语句和功能列表。

mo_ctl precheck

检查安装集群所需要的依赖项,例如:CPU,内存等。

mo_ctl install

创建集群,安装相应插件,并按照配置文件初始化 matrixone 集群。

mo_ctl registry

操作集群中创建的高可用镜像仓库,例如:增删改查镜像。

mo_ctl node

对集群中的节点进行管理,增加节点,删除节点等。

mo_ctl matrixone

对集群中 matrixone 集群进行管理,可创建,启动,停止,删除等操作。

mo_ctl s3

对集群中分布式 minio 进行管理,查看状态,扩展容量等操作。

mo_ctl backup

对集群中 matrixone cluster 进行备份,恢复等操作。

mo_ctl destroy

销毁 matrixone 服务并抹除集群。

快速上手

  1. 使用命令 mo_ctl help 查看工具指南。

  2. 使用命令 mo_ctl precheck 查看前置依赖条件是否满足。

    mo_ctl precheck --config xxx.yaml
    
  3. 使用命令 mo_ctl install 部署 MatrixOne 集群:

    mo_ctl install --config xxx.yaml
    
  4. 使用命令 mo_ctl  matrixone list 检查 MatrixOne 的状态。

    mo_ctl matrixone list --type cluster
    

参考命令指南

help

使用 mo_ctl help 打印参考指南。

./mo_ctl help
Install, destroy, and operation matrixone cluster

Usage:
  mo_ctl [command]

Available Commands:
  backup      backup matrixone cluster
  completion  Generate the autocompletion script for the specified shell
  destroy     destroy k8s cluster and apps on it
  help        Help about any command
  install     Install k8s, matrixone, minio, and other apps
  matrixone   matrixone operation cmd
  precheck    precheck cluster machine environment before install
  registry    registry operations

Flags:
      --config string       Specify the mo_ctl config file
  -d, --debug               turn on debug mode
  -h, --help                help for mo_ctl
      --kubeconfig string   Path to the kubeconfig file to use (default "/root/.kube/config")
      --logfile string      Specify the log file

Use "mo_ctl [command] --help" for more information about a command.

precheck

使用 mo_ctl precheck 预检查硬件和软件的环境是否适合安装 MatrixOne。

./mo_ctl precheck --help
precheck cluster machine environment before install

Usage:
  mo_ctl precheck [flags]

Flags:
  -h, --help   help for precheck

install

使用 mo_ctl install 在计算机(机器或虚拟机)上安装 k8s、matrixone、minio 和其他应用程序,执行此命令前需要联系您的客户经理获取镜像包的下载路径。

  • clusterimage.tar:面向需要使用 mo_ctl 创建集群并安装相关组件,其中包含基础 k8s 组件以及 matrixone 相应的 app 组件

  • moappdistro.tar:面向已有 k8s 集群,需要使用 mo_ctl 进行组件管理,其中包含 matrixone 以及相应的组件

./mo_ctl install --help
Install k8s, matrixone, minio, and other apps

Usage:
  mo_ctl install [flags]

Flags:
      --app       only install k8s app
      --dry-run   dry run
  -h, --help      help for install

destroy

使用 mo_ctl destroy 销毁 k8s 集群及其上的应用程序。

./mo_ctl destroy --help
destroy k8s cluster and apps on it

Usage:
  mo_ctl destroy [flags]

Flags:
      --configmap   get clusterfile from k8s configmap
      --dry-run     dry run
      --force       force destroy, no notice
  -h, --help        help for destroy

registry

使用 mo_ctl registry 操作集群中创建的高可用镜像仓库,例如:增删改查镜像。

 mo_ctl registry --help
Usage:
  mo_ctl registry [flags]
  mo_ctl registry [command]

Aliases:
  registry, reg

Available Commands:
  delete      delete (image)
  list        list (image | chart)
  push        push (image | chart)

Flags:
  -h, --help          help for registry
      --type string   registry type (image | chart) (default "image")

backup

使用 mo_ctl backup 对集群中 matrixone cluster 进行备份,恢复等操作

 ./mo_ctl backup --help
backup matrixone cluster

Usage:
  mo_ctl backup [flags]
  mo_ctl backup [command]

Available Commands:
  list        list matrixone cluster backup revison
  restore     restore backup matrixone cluster
  start       start backup matrixone cluster

Flags:
  -h, --help   help for backup
  • start

    1. 首先需要准备描述 backup job 的 yaml 文件,此处预设生成的 yaml 名称为 backup.yaml。

      apiVersion: core.matrixorigin.io/v1alpha1
      kind: BackupJob
      metadata:
        name: backupjob
        namespace: mocluster1
      spec:
        source:
          clusterRef: mocluster-mocluster1
        target:
          s3:
            type: minio
            endpoint: http://minio.s3-minio-tenant-test1
            path: mo-test/backup-01
            secretRef:
              name: minio
      
    2. 通过以下命令创建一个 backup job 来进行备份操作

      # 退出码为 0 则证明备份 job 创建成功
      sudo ./mo_ctl backup start --values backup.yaml
      
    3. 创建成功后可通过以下命令等待备份完成

      # 此处的 backupjob 即为在步骤一中定义的 name
      kubectl -n mocluster1 wait --for=condition=Ended backupjob/backupjob --timeout=5m
      
  • restore

    1. 获取已成功备份的 Backup 资源名称(不是 BackupJob 名称),可通过以下命令查看

      kubectl -n mocluster1 get backups
      
    2. 首先需要准备描述 restore job 的 yaml 文件,此处预设生成的 yaml 名称为 restore.yaml。

      apiVersion: core.matrixorigin.io/v1alpha1
      kind: MatrixOneCluster
      metadata:
        name: morestore
        namespace: mocluster1
      spec:
        restoreFrom: backup-name
        imageRepository: your-registry/matrixorigin/matrixone
        version: "REPLACE_WITH_VERIFIED_MO_VERSION"
        logService:
          replicas: 1
          sharedStorage:
            s3:
              type: minio
              path: mo-test/restore-01
              endpoint: http://minio.s3-minio-tenant-test1
              secretRef:
                name: minio
          volume:
            size: 10Gi
        tn:
          replicas: 1
          cacheVolume:
            size: 10Gi
        cnGroups:
          - name: tp
            replicas: 1
            cacheVolume:
              size: 10Gi
      
    3. 执行备份恢复命令

      sudo ./mo_ctl backup restore --values restore.yaml
      

matrixone

使用 mo_ctl matrixone 对集群中 matrixone 集群进行管理,可创建,启动,停止,删除等操作

./mo_ctl matrixone --help
Used for matrixone operation cmd

Usage:
  mo_ctl matrixone [flags]
  mo_ctl matrixone [command]

Aliases:
  matrixone, mo

Available Commands:
  history     history all matrixone (cluster | operator)
  list        list matrixone (cluster | operator)
  remove      remove matrixone (cluster)
  rollback    rollback depoly of matrixone (cluster | operator)
  setup       setup matrixone (cluster)
  start       start matrixone (cluster)
  stop        stop matrixone (cluster)
  upgrade     upgrade matrixone (cluster | operator)

Flags:
      --dry-run       dry run
  -h, --help          help for matrixone
      --name string   Specify matrixorigin cluster name
      --type string   Specify a type (cluster | operator) (default "cluster")

备份任务成功判据

上述 YAML 是结构示例,须替换 namespace、集群名、镜像版本、存储地址和 Secret,并用已安装版本 CRD 校验。恢复目标必须使用独立的对象存储前缀,不覆盖原集群数据;单副本示例不代表生产高可用拓扑。

kubectl wait --for=condition=Ended 只说明任务结束。Operator 在失败时也设置 Ended=True;还必须检查 .status.phase 为 Completed、.status.backup 指向实际 Backup,并完成独立恢复及数据校验。使用具体任务和命名空间,避免 --all -A 等待其他任务。

kubectl -n mocluster1 wait --for=condition=Ended backupjob/backupjob --timeout=5m
kubectl -n mocluster1 get backupjob backupjob -o yaml
kubectl -n mocluster1 get backups

完整流程见 Operator 操作验收。