暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

「更易用的OceanBase」| 0193.O 使用Docker快速部署OceanBase v4.0测试环境

rundba 2022-11-17
1210

文章来源:https://mp.weixin.qq.com/s/FRoPi2sJgrWzyB7htZjp2w ,首发于微信公众号:rundba,转载请注明出处。


如何使用docker快速部署OceanBase测试环境?部署完成后如何进行连接?如何停启?

 

 

0. ENV

 

CentOS 7.6;

Docker 20.10.21;

oceanbase-ce 4.0.0.0;


docker资源不低于2核8GB。

docker版本仅仅做为测试使用,采用单机部署,未使用分布式。


 

1. 启动OceanBase数据库实例

 

确保docker联网情况下,直接启动OceanBase数据库的实例:

# 部署 mini 的独立实例。如果当前测试环境资源较低,可使用mini规格,便于基础测试。

    docker run -p 2881:2881 --name obstandalone -e MINI_MODE=1 -d oceanbase/oceanbase-ce

    # 根据当前容器部署最大规格的实例。如果主机资源较多时,可部署该规格。

    docker run -p 2881:2881 --name obstandalone -d oceanbase/oceanbase-ce

    当前部署为最新版本,版本为4.0.0.0。

    如果要指定版本时,可使用如下语句:

    [root@rundba ~]# docker run -p 2881:2881 --name obstandalone -d oceanbase/oceanbase-ce:4.0.0.0
    Unable to find image 'oceanbase/oceanbase-ce:4.0.0.0' locally
    4.0.0.0: Pulling from oceanbase/oceanbase-ce
    2d473b07cdd5: Already exists 
    22338b824aaa: Pull complete 
    09a412a0d9a2: Pull complete 
    8ca6368c2328: Pull complete 
    Digest: sha256:b16bcfb6c48dac735e09667b41b97e15539e359370f05dcebdc23863a7b9518f
    Status: Downloaded newer image for oceanbase/oceanbase-ce:4.0.0.0
    d8a4474179c2480f66875199e1e4c1986ee4e90f9c2c45e943fb8b3bbcae5855

    启动预计需要 2-5 分钟。执行以下命令,如果返回 boot success!,则启动成功。

      [root@rundba ~]# docker logs obstandalone | tail -1
      boot success!

      查看已拉取的镜像:

        [root@rundba ~]# docker images | grep oceanbase
        oceanbase/oceanbase-ce                                                    4.0.0.0   bf8b05927847   11 days ago     447MB

        查看当前已启动的OceanBase:

        [root@rundba ~]# docker ps
        CONTAINER ID   IMAGE                            COMMAND              CREATED         STATUS         PORTS                                       NAMES
        d8a4474179c2   oceanbase/oceanbase-ce:4.0.0.0   "/bin/sh -c _boot"   4 minutes ago   Up 4 minutes   0.0.0.0:2881->2881/tcp, :::2881->2881/tcp   obstandalone

        当前已经OB容器的oceanbase 2881端口映射为主机的2881端口,可通过docker主机访问OB。


         

        2. 连接 OceanBase 数据库实例

         

        2.1 docker主机连接oceanbase

        oceanbase-ce 镜像安装了 OceanBase 数据库客户端 OBClient,并提供了默认连接脚本 ob-mysql。

        docker exec -it obstandalone ob-mysql sys   # 连接sys租户的root用户

        如:

          [root@rundba ~]# docker exec -it obstandalone ob-mysql sys
          login as root@sys
          Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881 
          Welcome to the OceanBase.  Commands end with ; or \g.
          Your OceanBase connection id is 3221487621
          Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)
          
          Copyright (c) 2000, 2018, OB Corporation Ab and others.
          
          Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
          
          obclient [oceanbase]>

          连接其它租户:

          docker exec -it obstandalone ob-mysql root  # 连接test租户的root用户,当前已内置test租户
          docker exec -it obstandalone ob-mysql test  # 连接test租户的test用户

          也可以运行以下命令,使用您本机的 OBClient 或者 MySQL 客户端连接实例。

          mysql -uroot -h127.1 -P2881      #当前docker主机需要安装mysql或mysql-client


          2.2 进入docker容器访问

          在docker主机进入docker容器,访问OceanBase:

          [root@rundba ~]# docker exec -it obstandalone ob-mysql sys
          login as root@sys
          Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881 
          Welcome to the OceanBase.  Commands end with ; or \g.
          Your OceanBase connection id is 3221487625
          Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)
          
          Copyright (c) 2000, 2018, OB Corporation Ab and others.
          
          Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
          
          obclient [oceanbase]>


            2.3 外部主机访问oceanbase

            直接访问docker主机2881端口:

              [root@quickstart ~]# mysql -uroot -h192.168.80.123 -P2881
              Welcome to the MySQL monitor.  Commands end with ; or \g.
              Your MySQL connection id is 3221487624
              Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)
              
              Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
              
              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>


              2.4 其它工具访问

              使用ODC或其它支持OB的工具访问时,连接docker主机IP和2881端口。


               

              3. 停启oceanbase

               

              停止oceanbase:

              [root@rundba ~]# docker stop obstandalone
              obstandalone

              查看是否停止/启动:

                [root@rundba ~]# docker ps
                CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

                启动oceanbase:

                  [root@rundba ~]# docker start obstandalone
                  obstandalone


                   

                  4. 参考

                   

                    https://www.oceanbase.com/docs/community-observer-cn-10000000000901197



                    最后修改时间:2022-11-18 13:59:30
                    文章转载自rundba,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                    评论