Skip to content

macOS 使用源代码部署

本篇文档将指导你使用源代码在 macOS 环境中部署单机版 MatrixOne。我们将采用 mo_ctl 工具帮助我们进行部署与管理 MatrixOne。

MatrixOne 支持 x86 及 ARM 的 macOS 系统,本文以 Macbook M1 ARM 版本为例子展示整个部署过程。

前置依赖参考

通过源码安装及使用单机版 MatrixOne,需要依赖于以下一些软件包。

依赖软件 版本
golang 1.20 及以上
gcc/clang gcc8.5 及以上, clang13.0 及以上
git 2.20 及以上
MySQL Client 8.0 及以上

步骤 1:安装依赖

1. 安装部署 Go 语言

  1. 点击 Go Download and install 进入到 Go 的官方文档,按照官方指导安装步骤完成 Go 语言的安装。

  2. 验证 Go 是否安装,请执行代码 go version,安装成功代码行示例如下:

    > go version
    go version go1.20.5 darwin/arm64
    

2. 安装 GCC/Clang

  1. macOS 中一般已经自带 Clang 编译器,其与 GCC 基本起到相同作用。验证 GCC/Clang 环境是否需要安装:

    gcc -v
    bash: gcc: command not found
    

    如代码所示,未显示 GCC 或 Clang 的版本,则表示 GCC/Clang 的环境需要安装。

  2. 你可以选择点击 GCC Download and install 进入到 GCC 的官方文档,按照官方指导安装步骤完成 GCC 的安装。或者也可以通过 Apple 官方的 Xcode 进行 Clang 的安装。

  3. 验证 GCC/Clang 是否安装,请执行代码 gcc -v,无论显示的是 Clang 或者 GCC 版本均说明安装成功,示例如下:

    Apple clang version 14.0.3 (clang-1403.0.22.14.1)
    Target: arm64-apple-darwin22.5.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    

3. 安装 Git

通过官方文档安装 Git。

使用 git version 检查是否安装成功,安装成功代码示例如下:

> git version
git version 2.40.0

4. 安装 MySQL Client

  1. 点击 MySQL Community Downloads,进入到 MySQL 客户端下载安装页面,根据你的操作系统和硬件环境,下拉选择 Select Operating System > macOS,再下拉选择 Select OS Version,按需选择下载安装包进行安装。

  2. 配置 MySQL 客户端环境变量:

    1. 打开一个新的终端,输入如下命令:

      vim ~/.bash_profile
      
    2. 回车执行上面的命令后,即进入了 bash_profile,点击键盘上的 i 进入 insert 状态,即可在文件下方输入如下命令:

    export PATH=${PATH}:/usr/local/mysql/bin
    
  3. 输入完成后,点击键盘上的 esc 退出 insert 状态,并在最下方输入 :wq 保存退出。

  4. 执行命令 source ~/.bash_profile,回车执行,运行环境变量。

  5. 测试 MySQL 是否可用:

    执行命令 mysql --version,安装成功提示:mysql Ver 8.0.31 for macos12 on arm64 (MySQL Community Server - GPL)

步骤 2:安装 mo_ctl 工具

mo_ctl 是一个部署安装和管理 MatrixOne 的命令行工具,使用它可以非常方便的对 MatrixOne 进行各类操作。如需获取完整的使用细节可以参考 mo_ctl 工具指南

  1. 先安装 wget 下载工具:进入到 Homebrew 页面按照步骤提示,先安装 Homebrew,再安装 wget。验证 wget 是否安装成功可以使用如下命令行:

    wget -V
    

    安装成功结果(仅展示一部分代码)如下:

    GNU Wget 1.21.3 在 darwin21.3.0 上编译。
    ...
    Copyright © 2015 Free Software Foundation, Inc.
    ...
    
  2. 通过以下命令一键安装 mo_ctl 工具:

    wget https://raw.githubusercontent.com/matrixorigin/mo_ctl_standalone/main/install.sh && sudo -u $(whoami) bash +x ./install.sh
    
  3. 安装完成以后,通过 mo_ctl 命令验证是否安装成功,成功代码示例如下:

    > mo_ctl
    Usage             : mo_ctl [option_1] [option_2]
    
    [option_1]        : available: help | precheck | deploy | status | start | stop | restart | connect | get_cid | set_conf | get_conf | pprof | ddl_convert
      0) help         : print help information
      1) precheck     : check pre-requisites for mo_ctl
      2) deploy       : deploy mo onto the path configured
      3) status       : check if there's any mo process running on this machine
      4) start        : start mo-service from the path configured
      5) stop         : stop all mo-service processes found on this machine
      6) restart      : start mo-service from the path configured
      7) connect      : connect to mo via mysql client using connection info configured
      8) get_cid      : print mo commit id from the path configured
      9) pprof        : collect pprof information
      10) set_conf    : set configurations
      11) get_conf    : get configurations
      12) ddl_convert : convert ddl file to mo format from other types of database
      e.g.            : mo_ctl status
    
    [option_2]        : Use " mo_ctl [option_1] help " to get more info
      e.g.            : mo_ctl deploy help
    

设置 mo_ctl 的配置参数(选做)

mo_ctl 工具中有部分参数可能需要你进行调整设置,通过 mo_ctl get_conf 可以查看所有当前参数。

> mo_ctl get_conf
2023-07-07_15:31:24    [INFO]    Below are all configurations set in conf file /Users/username/mo_ctl/conf/env.sh
MO_PATH="/Users/username/mo/matrixone"
MO_LOG_PATH="${MO_PATH}/matrixone/logs"
MO_HOST="127.0.0.1"
MO_PORT="6001"
MO_USER="root"
MO_PW="111"
CHECK_LIST=("go" "gcc" "git" "mysql")
GCC_VERSION="8.5.0"
GO_VERSION="1.20"
MO_GIT_URL="https://github.com/matrixorigin/matrixone.git"
MO_DEFAULT_VERSION="0.8.0"
GOPROXY="https://goproxy.cn,direct"
STOP_INTERVAL="5"
START_INTERVAL="2"
MO_DEBUG_PORT="9876"
MO_CONF_FILE="${MO_PATH}/matrixone/etc/launch-tae-CN-tae-DN/launch.toml"
RESTART_INTERVAL="2"
PPROF_OUT_PATH="/tmp/pprof-test/"
PPROF_PROFILE_DURATION="30"

一般可能会需要调整的参数如下:

mo_ctl set_conf MO_PATH="/Users/username/mo/matrixone" # 设置自定义的MatrixOne下载路径
mo_ctl set_conf MO_GIT_URL="https://ghproxy.com/https://github.com/matrixorigin/matrixone.git" #针对github原地址下载过慢问题,设置代理下载地址
mo_ctl set_conf MO_DEFAULT_VERSION="0.8.0" # 设置所下载的MatrixOne版本

步骤 3:一键安装 MatrixOne

根据您的需要,选择最新的开发版本,还是获得稳定版本的代码。

main 分支是默认分支,主分支上的代码总是最新的,但不够稳定。

mo_ctl deploy main
mo_ctl deploy 0.8.0

步骤 4:启动 MatrixOne 服务

通过 mo_ctl start 命令一键启动 MatrixOne 服务。

如果运行正常将出现以下日志。MatrixOne 的相关运行日志会在 /data/mo/logs/ 中。

> mo_ctl start
2023-07-07_15:33:45    [INFO]    No mo-service is running
2023-07-07_15:33:45    [INFO]    Starting mo-service: cd /Users/username/mo/matrixone/matrixone/ && /Users/username/mo/matrixone/matrixone/mo-service -daemon -debug-http :9876 -launch /Users/username/mo/matrixone/matrixone/etc/launch-tae-CN-tae-DN/launch.toml >/Users/username/mo/matrixone/matrixone/logs/stdout-20230707_153345.log 2>/Users/username/mo/matrixone/matrixone/logs/stderr-20230707_153345.log
2023-07-07_15:33:45    [INFO]    Wait for 2 seconds
2023-07-07_15:33:48    [INFO]    At least one mo-service is running. Process info:
2023-07-07_15:33:48    [INFO]      501 66932     1   0  3:33PM ??         0:00.27 /Users/username/mo/matrixone/matrixone/mo-service -daemon -debug-http :9876 -launch /Users/username/mo/matrixone/matrixone/etc/launch-tae-CN-tae-DN/launch.toml
2023-07-07_15:33:48    [INFO]    Pids:
2023-07-07_15:33:48    [INFO]    66932
2023-07-07_15:33:48    [INFO]    Start succeeded

Note

首次启动 MatrixOne 大致需要花费 20 至 30 秒的时间,在稍作等待后,你便可以连接至 MatrixOne。

步骤 5:连接 MatrixOne 服务

通过 mo_ctl connect 命令一键连接 MatrixOne 服务。

这条命令将调用 MySQL Client 工具自动连接到 MatrixOne 服务。

> mo_ctl connect
2023-07-07_10:30:20    [INFO]    Checking connectivity
2023-07-07_10:30:20    [INFO]    Ok, connecting for user ...
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.30-MatrixOne-v0.8.0 MatrixOne

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Note

上述的连接和登录账号为初始账号 root 和密码 111,请在登录 MatrixOne 后及时修改初始密码,参见密码管理。修改登录用户名或密码后重新登录同样需要通过 mo_ctl set_conf 的方式设置新的用户名和密码,详情可以参考 mo_ctl 工具指南