MatrixOne从入门到实践03——部署MatrixOne

MatrixOne从入门到实践——部署MatrixOne

前两章节我们简单介绍了MatrixOne和源码编译了MatrixOne。本章节将使用不同的部署方式,来部署MatrixOne的服务。

注意:不同版本的MO,启动所使用的的命令不一样,请执行相应版本的启动命令!

源码部署

源码编译

源码编译直通车:MatrixOne从入门到实践——源码编译

上一章节讲了MatrixOne的源码编译,在编译完成之后,会在当前目录生成一个二进制文件:mo-service

目录结构如下所示:

drwxr-xr-x.  4 root root      4096 Sep  6 14:32 cgo
drwxr-xr-x.  3 root root        24 Sep  6 14:32 cmd
-rw-r--r--.  1 root root      3371 Sep  6 14:11 CODE_OF_CONDUCT.md
-rw-r--r--.  1 root root      2597 Sep  6 14:32 CODEOWNERS
-rw-r--r--.  1 root root      3704 Sep  6 14:11 CONTRIBUTING.md
drwxr-xr-x.  5 root root        38 Sep  6 14:11 docs
drwxr-xr-x.  4 root root      4096 Sep  6 19:06 etc
-rw-r--r--.  1 root root      6079 Sep  6 19:07 go.mod
-rw-r--r--.  1 root root     70341 Sep  6 14:32 go.sum
-rw-r--r--.  1 root root     11309 Sep  6 14:11 LICENSE
drwxr-xr-x.  2 root root        76 Sep  6 14:11 LICENSES
-rw-r--r--.  1 root root      5322 Sep  6 14:32 Makefile
-rwxr-xr-x.  1 root root  68334672 Sep  6 19:07 mo-service
-rw-------.  1 root root 624590427 Sep  8 16:24 nohup.out
drwxr-xr-x.  6 root root       102 Sep  6 14:32 optools
drwxr-xr-x. 27 root root      4096 Sep  6 14:32 pkg
drwxr-xr-x.  2 root root       201 Sep  6 19:06 proto
-rw-r--r--.  1 root root     11791 Sep  6 14:32 README_CN.md
-rw-r--r--.  1 root root     31404 Sep  6 14:32 README.md
drwxr-xr-x.  6 root root        65 Sep  6 19:13 store
drwxr-xr-x.  5 root root        50 Sep  6 19:06 test

部署

./mo-service -cfg ./etc/cn-standalone-test.toml

启动成功后会有一下日志显示:

{"level":"INFO","time":"2022/09/08 16:27:14.821702 +0800","caller":"frontend/session.go:842","msg":"dbName mo_catalog tableNames [mo_database mo_tables mo_columns mo_user mo_account mo_role mo_user_grant mo_role_grant mo_role_priv]"}
{"level":"INFO","time":"2022/09/08 16:27:14.821934 +0800","caller":"frontend/mysql_cmd_executor.go:1921","msg":"time of Exec.Build : 536.76µs","span":{"TraceId":"0b15b180-2f50-11ed-923c-000c29a35f3c","SpanId":"0000000000000000"}}
{"level":"INFO","time":"2022/09/08 16:27:14.822689 +0800","caller":"compile/scope.go:44","msg":"\t:2 filter(typ:<id:10 size:1 > f:<func:<obj:73014444032 > args:<typ:<id:10 size:1 > f:<func:<obj:12 obj_name:\"=\" > args:<typ:<id:61 width:100 > col:<col_pos:1 name:\"mo_tables.reldatabase\" > > args:<typ:<id:61 width:10 size:4 > c:<sval:\"mo_catalog\" > > > > args:<typ:<id:10 size:1 > f:<func:<obj:4294967308 obj_name:\"<>\" > args:<typ:<id:61 width:100 > col:<name:\"mo_tables.relname\" > > args:<typ:<id:61 width:23 size:4 > c:<sval:\"%!%mo_increment_columns\" > > > > > ) -> projection(typ:<id:61 width:100 > col:<name:\"mo_tables.relname\" > ) -> projection(typ:<id:61 width:100 > col:<name:\"mo_tables.relname\" > ) -> pipe connector"}
{"level":"INFO","time":"2022/09/08 16:27:14.822737 +0800","caller":"compile/scope.go:44","msg":":0  union all  -> sql output"}
{"level":"DEBUG","time":"2022/09/08 16:27:14.822785 +0800","caller":"moengine/helper.go:41","msg":"try set 18 txn access info to t0(true) u0(true) r0(true), ","span":{"TraceId":"00000000-0000-0000-0000-000000000000","SpanId":"0000000000000000"}}
{"level":"INFO","time":"2022/09/08 16:27:14.823203 +0800","caller":"frontend/mysql_cmd_executor.go:2004","msg":"time of Exec.Run : 1.150387ms"}
{"level":"INFO","time":"2022/09/08 16:27:14.823247 +0800","caller":"frontend/mysql_cmd_executor.go:2277","msg":"----close mce"}
{"level":"INFO","time":"2022/09/08 16:27:14.823469 +0800","caller":"frontend/server.go:38","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823528 +0800","caller":"frontend/server.go:39","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823536 +0800","caller":"frontend/server.go:40","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823542 +0800","caller":"frontend/server.go:41","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823548 +0800","caller":"frontend/server.go:42","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823557 +0800","caller":"frontend/server.go:43","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823563 +0800","caller":"frontend/server.go:44","msg":"Server Listening on : 0.0.0.0:6001 "}
{"level":"INFO","time":"2022/09/08 16:27:14.823569 +0800","caller":"frontend/server.go:45","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823575 +0800","caller":"frontend/server.go:46","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823580 +0800","caller":"frontend/server.go:47","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823585 +0800","caller":"frontend/server.go:48","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823590 +0800","caller":"frontend/server.go:49","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"INFO","time":"2022/09/08 16:27:14.823600 +0800","caller":"frontend/server.go:50","msg":"++++++++++++++++++++++++++++++++++++++++++++++++"}
{"level":"DEBUG","time":"2022/09/08 16:27:14.823632 +0800","caller":"v2@v2.0.3-0.20220812142536-dfcb3d33cfdc/application.go:190","msg":"application started","listen-address":"0.0.0.0:6001"}
{"level":"INFO","time":"2022/09/08 16:27:14.823772 +0800","caller":"morpc/client.go:299","msg":"gc inactive backends task started"}
{"level":"DEBUG","time":"2022/09/08 16:27:14.823872 +0800","caller":"v2@v2.0.3-0.20220812142536-dfcb3d33cfdc/application.go:246","msg":"application accept loop started","listen-address":"0.0.0.0:6001"}

此时看见 application accept loop started,代表程序已经启动成功,但是此时是在前台启动的程序,当前界面会一直打印日志,因此,可以选择如下命令来启动mo-service:

nohup ./mo-service -cfg ./etc/cn-standalone-test.toml &

日志就会输出在当前目录下的nohup.out文件中。

二进制包部署

从 0.3.0 版本开始,就可以直接下载二进制包,然后在 X86_64 Linux 环境或者 X86_64 的 MacOS 环境中运行 MatrixOne。

下载二进制包

解压并部署

解压我们上一步下载的压缩包

unzip mo-server-v0.5.1-linux-amd64.zip
# 如提示没有unzip 命令,请使用下列命令安装
yum install -y unzip 

解压完成后会有一个二进制文件,如下所示

[root@node01 matrixone]# unzip mo-server-v0.5.1-linux-amd64.zip 
Archive:  mo-server-v0.5.1-linux-amd64.zip
  inflating: mo-server               
  inflating: system_vars_config.toml  
[root@node01 matrixone]# ll
total 53200
-rwxr-xr-x. 1 root root 38715328 Aug 19 10:35 mo-server
-rw-r--r--. 1 root root 15747914 Aug 19 10:35 mo-server-v0.5.1-linux-amd64.zip
-rw-r--r--. 1 root root    10755 Aug 19 10:35 system_vars_config.toml

准备部署MO的服务

./mo-server ./system_vars_config.toml

启动后,有如下日志,就说明启动成功

{"level":"INFO","time":"2022/09/08 16:54:58.592942 +0800","caller":"frontend/mysql_cmd_executor.go:1639","msg":"time of Exec.Build : 10.615µs"}
{"level":"INFO","time":"2022/09/08 16:54:58.592967 +0800","caller":"frontend/mysql_cmd_executor.go:1763","msg":"time of Exec.Run : 9.16µs"}
{"level":"INFO","time":"2022/09/08 16:54:58.592982 +0800","caller":"frontend/mysql_cmd_executor.go:1769","msg":"time of SendResponse 76ns"}
{"level":"INFO","time":"2022/09/08 16:54:58.592996 +0800","caller":"frontend/session.go:537","msg":"commit autocommit only"}
{"level":"INFO","time":"2022/09/08 16:54:58.593004 +0800","caller":"frontend/session.go:84","msg":"switch from 2 to 3"}
{"level":"INFO","time":"2022/09/08 16:54:58.593014 +0800","caller":"frontend/session.go:608","msg":"clean tae txn"}
{"level":"INFO","time":"2022/09/08 16:54:58.593020 +0800","caller":"frontend/session.go:84","msg":"switch from 3 to 0"}
{"level":"INFO","time":"2022/09/08 16:54:58.593164 +0800","caller":"frontend/session.go:452","msg":"start txn autocommit if needed"}
{"level":"INFO","time":"2022/09/08 16:54:58.593175 +0800","caller":"frontend/session.go:375","msg":"current txn state 0"}
{"level":"INFO","time":"2022/09/08 16:54:58.593181 +0800","caller":"frontend/session.go:457","msg":"need create new txn"}
{"level":"INFO","time":"2022/09/08 16:54:58.593187 +0800","caller":"frontend/session.go:438","msg":"start txn by autocommit"}
{"level":"INFO","time":"2022/09/08 16:54:58.593198 +0800","caller":"frontend/session.go:84","msg":"switch from 0 to 2"}
{"level":"INFO","time":"2022/09/08 16:54:58.593205 +0800","caller":"frontend/mysql_cmd_executor.go:1529","msg":"start autocommit txn in default"}
{"level":"INFO","time":"2022/09/08 16:54:58.593219 +0800","caller":"frontend/mysql_cmd_executor.go:1639","msg":"time of Exec.Build : 4.645µs"}
{"level":"INFO","time":"2022/09/08 16:54:58.593238 +0800","caller":"frontend/mysql_cmd_executor.go:1763","msg":"time of Exec.Run : 4.643µs"}
{"level":"INFO","time":"2022/09/08 16:54:58.593252 +0800","caller":"frontend/mysql_cmd_executor.go:1769","msg":"time of SendResponse 64ns"}
{"level":"INFO","time":"2022/09/08 16:54:58.593265 +0800","caller":"frontend/session.go:537","msg":"commit autocommit only"}
{"level":"INFO","time":"2022/09/08 16:54:58.593272 +0800","caller":"frontend/session.go:84","msg":"switch from 2 to 3"}
{"level":"INFO","time":"2022/09/08 16:54:58.593279 +0800","caller":"frontend/session.go:608","msg":"clean tae txn"}
{"level":"INFO","time":"2022/09/08 16:54:58.593286 +0800","caller":"frontend/session.go:84","msg":"switch from 3 to 0"}
{"level":"DEBUG","time":"2022/09/08 16:54:58.593295 +0800","caller":"metric/metric.go:159","msg":"[Metric] init metrics tables: create cost 4 ms"}
{"level":"INFO","time":"2022/09/08 16:54:58.593382 +0800","caller":"metric/metric.go:104","msg":"[Metric] metrics scrape endpoint is ready at http://0.0.0.0:7001/metrics"}
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
Server Listening on : 0.0.0.0:6001 
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
{"level":"info","ts":"2022-09-08 16:54:58.593","logger":"goetty","caller":"goetty@v1.13.0/application.go:96","msg":"application started","listen-address":"0.0.0.0:6001"}
{"level":"info","ts":"2022-09-08 16:54:58.593","logger":"goetty","caller":"goetty@v1.13.0/application.go:155","msg":"application accept loop started","listen-address":"0.0.0.0:6001"}

同理,我们可以使用后台启动的方式,将日志输出到文件中去

nohup ./mo-server ./system_vars_config.toml &

Docker部署

安装Docker

在进行docker部署之前,请先检查机器上是否有docker的环境,使用如下命令检查:

docker version

如果有以下输出,就说明具有docker的环境,并且docker的服务也启动着

[root@node01 matrixone]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-209.git7d71120.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      7d71120/1.13.1
 Built:           Wed Mar  2 15:25:43 2022
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-209.git7d71120.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      7d71120/1.13.1
 Built:           Wed Mar  2 15:25:43 2022
 OS/Arch:         linux/amd64
 Experimental:    false

如果出现以下内容,说明具有docker环境,但是docker服务没有启动

[root@node01 matrixone]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: 
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

直接执行以下命令启动docker即可

systemctl start docker

如果出现以下情况,说明docker没有安装

[root@node01 matrixone]# docker version
-bash: /usr/bin/docker: No such file or directory

需要安装,然后启动服务

yum install -y docker
# 安装完成后使用 
systemctl start docker

部署MO环境

  • 拉取matrixone镜像

    使用如下命令拉取最新的matrixone的镜像文件

    docker pull matrixorigin/matrixone:latest
    

    如果需要拉取固定版本的镜像,请更换最后的版本描述即可,例如拉取0.5.1

    docker pull matrixorigin/matrixone:0.5.1
    

    拉取成功后,使用docker image 命令可以查看到我们拉取的镜像文件

    [root@node01 matrixone]# docker images
    REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
    docker.io/matrixorigin/matrixone   0.5.1               c92ab76b7376        2 weeks ago         117 MB
    docker.io/matrixorigin/matrixone   latest              c92ab76b7376        2 weeks ago         117 MB
    
  • 运行镜像文件

    这里因为我们需要将容器内的端口映射到主机上,便于我们外部去和MO通信,同时我们还需要将数据目录挂载在我们本机上,所以我们在启动镜像的时候,需要添加这些操作,具体命令如下:

    docker run -d -p 6001:6001 --name matrixone matrixorigin/matrixone:latest
    # 或者
    docker run -d -p 6001:6001 --name matrixone matrixorigin/matrixone:0.5.1
    来启动不同版本的镜像
    

    如果需要挂载数据目录,请使用以下命令启动

    docker run -d -p 6001:6001 -v ${path_name}/system_vars_config.toml:/system_vars_config.toml:ro -v ${path_name}/store:/store:rw --name matrixone matrixorigin/matrixone:0.5.1
    
  • 检查是否成功

    启动对应镜像之后,需要查看对应容器是否启动成功,使用以下命令查看容器状态

    docker ps -a
    

    例如这里,容器启动有问题就会有下面的提示:

    CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS                     PORTS               NAMES
    f7f0bf405b06        matrixorigin/matrixone:latest   "/mo-server /syste..."   2 minutes ago       Exited (2) 2 minutes ago                       matrixone
    

    此时,我们需要查看对应日志:

    docker logs f7f0bf405b06
    

    如果遇到启动不了的问题,需要升级docker,升级步骤如下:

    # 卸载老版本docker
    yum  remove docker docker-common  docker-selinux docker-engine
    # 安装相关依赖
    yum install  -y  yum-utils  device-mapper-persistent-data  lvm2
    # 设置docker yum源
    yum-config-manager  --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
    

    配置好源之后就可以查看对应的docker 版本了

    # 查看对应版本
    yum  list  docker-ce  --showduplicates |  sort -r
    

    如下所示:

    [root@node01 matrixone]# yum  list  docker-ce  --showduplicates |  sort -r
     * updates: mirrors.ustc.edu.cn
    This system is not registered with an entitlement server. You can use subscription-manager to register.
                  : manager
    Loading mirror speeds from cached hostfile
    Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-
    Installed Packages
     * extras: mirrors.bupt.edu.cn
    docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.9-3.el7                    @docker-ce-stable
    docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.17-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.16-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.15-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.14-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:20.10.13-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.12-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.11-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.10-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:20.10.0-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.15-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.14-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:19.03.13-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
    

    我们选择最新的版本下载

    yum  install  -y --setopt=obsoletes=0 docker-ce-20.10.9-3.el7
    

    下载完成之后,启动docker,然后重新pull镜像,启动容器即可。

    命令如下:

    # pull镜像
    docker pull matrixorigin/matrixone:0.5.1
    # 启动容器
    docker run -d -p 6001:6001 --name mo0.5.1 matrixorigin/matrixone:0.5.1
    

    查看是否启动成功

    # 查看状态
    docker ps -a
    # 输出如下:
    CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS                      PORTS                                       NAMES
    bd58ac4181d2   matrixorigin/matrixone:0.5.1   "/mo-server /system_…"   5 minutes ago    Up 5 minutes                0.0.0.0:6001->6001/tcp, :::6001->6001/tcp   mo0.5.1
    
posted @ 2022-09-08 17:52  自由如风fly  阅读(126)  评论(0编辑  收藏  举报