我和OceanBase的故事系列:Docker 安装部署 oceanbase 4 社区版操作记录

一、前言

这是一篇前段时间学习OceanBase的记录文章。
生产环境若要部署oceanbase企业版往往需要较高的服务器配置,动辄几十G内存,多个物理CPU,显得有些不太亲民,而测试环境服务器又很难达到如此高的配置,难以像Oracle和MySQL数据库可以在较低的测试服务器上进行部署。

所以对于想要在测试环境上部署OceanBase ,目前更合适的方法是使用其社区版,通过docker等方式来进行部署。

2022年的云栖大会,阿里发布了OceanBase 4.0社区版,今天就打算尝试在docker环境下部署OceanBase 4.0,于是找了下网上相关资料,并在测试环境进行了测试,以下是部署过程。

注:截止到2023年12月26日,当前OB官网最新的社区版是V4.2.1_CE_BP2_HF1

二、安装部署

2.1 搜索oceanbase镜像

首先搜索下当前OceanBase镜像,操作信息如下:

[root@opensource-db ~]# docker search oceanbase
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oceanbase/oceanbase-ce             OceanBase is an open-source, distributed HTA…   11                  
obpilot/oceanbase-ce               3 steps to run an OceanBase-CE docker in you…   4                   
oceanbase/oceanbase-xe             OceanBase Database 2.2 Express Edition          4                   
oceanbase/obce-mini                obce-mini is a mini standalone test image fo…   3                   
oceanbase/miniob                   miniob database competition                     2                   
zibuyu886/oceanbase-ce-cluster     OceanBase ce cluster                            1                   
oceanbase/obce-operator            obce-operator                                   1                   
oceanbase/oceanbase-cloud-native                                                   0                   
oceanbase/obproxy-ce                                                               0                   
oceanbasedev/oceanbase-cn                                                          0                   
oceanbase/centos7                                                                  0                   
oceanbase/obagent                                                                  0                   
oceanbasedev/ob-operator                                                           0                   
oceanbase/ob-operator                                                              0                   
oceanbasedev/obagent                                                               0                   
datatomdev/oceanbase                                                               0                   
huweijie/oceanbase-ce-deploy                                                       0                   
superbigfu/oceanbase                                                               0                   
oceanbasedev/obproxy-ce                                                            0                   
hongxinsun/oceanbase-cn                                                            0                   
hnwyllmm/oceanbase-ce                                                              0                   
oceanbasedev/obproxy                                                               0                   
hnwyllmm/oceanbase-ce-x86                                                          0                   
oceanbasedev/create_tenant                                                         0                   
hnwyllmm/oceanbase-ce-aarch64                                                      0

image.png

2.2 下载镜像

使用docker pull oceanbase/oceanbase-ce:latest下载最新镜像

[root@opensource-db ~]# docker pull oceanbase/oceanbase-ce:latest
latest: Pulling from oceanbase/oceanbase-ce
2d473b07cdd5: Pull complete
ec4409f1be83: Pull complete
3b480fbef1fe: Pull complete
c5081e00feee: Pull complete
Digest: sha256:12dbd6de41f452b4247a9aa74c45d18a02143246497602c167970a13a1e445af
Status: Downloaded newer image for oceanbase/oceanbase-ce:latest
docker.io/oceanbase/oceanbase-ce:latest

image.png

2.3 查看镜像

可以通过如下命令查看下载的镜像信息

[root@opensource-db ~]# docker images
REPOSITORY               TAG       IMAGE ID       CREATED      SIZE
oceanbase/oceanbase-ce   latest    1baf760d088f   2 days ago   457MB

-- 可以通过inspect 参数来查看下载镜像的详细信息
[root@opensource-db ~]# docker inspect oceanbase/oceanbase-ce
[
    {
        "Id": "sha256:1baf760d088f664bf03424880bcf44fbf57a4eff87e79fb58f4c82118336233a",
        "RepoTags": [
            "oceanbase/oceanbase-ce:latest"
        ],
        "RepoDigests": [
            "oceanbase/oceanbase-ce@sha256:12dbd6de41f452b4247a9aa74c45d18a02143246497602c167970a13a1e445af"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2022-12-06T05:54:54.135865316Z",
        "Container": "0ba77fee2b779b0acc527d49498e3b00ac1f9777d76e43c86b4346ff98e7b803",
        "ContainerConfig": {
            "Hostname": "0ba77fee2b77",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/root/boot:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/sh\" \"-c\" \"_boot\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:c779bf7fc3bdc1b5d0e73edc686ef00a94145ddec3ee1d9a0aa923a5b0c6c0f7",
            "Volumes": null,
            "WorkingDir": "/root",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20201113",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS",
                "org.opencontainers.image.created": "2020-11-13 00:00:00+00:00",
                "org.opencontainers.image.licenses": "GPL-2.0-only",
                "org.opencontainers.image.title": "CentOS Base Image",
                "org.opencontainers.image.vendor": "CentOS"
            }
        },
        "DockerVersion": "18.06.1-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/root/boot:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "_boot"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:c779bf7fc3bdc1b5d0e73edc686ef00a94145ddec3ee1d9a0aa923a5b0c6c0f7",
            "Volumes": null,
            "WorkingDir": "/root",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20201113",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS",
                "org.opencontainers.image.created": "2020-11-13 00:00:00+00:00",
                "org.opencontainers.image.licenses": "GPL-2.0-only",
                "org.opencontainers.image.title": "CentOS Base Image",
                "org.opencontainers.image.vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 457056957,
        "VirtualSize": 457056957,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/ca9a785913dfc0456f9671e2173f3a05958c5898645d5e77a311ed298c7ce668/diff:/var/lib/docker/overlay2/cd5de663cff5c8b0a4d2f43fffec2ff342e634cc307d995c86f92f150ca7ba8d/diff:/var/lib/docker/overlay2/917086ff9c592cc5b3cb76389fcbf76918e4ef65e4cfb3f1f3ef87b3eecf3709/diff",
                "MergedDir": "/var/lib/docker/overlay2/0c87bae9f134aee7d0ce78f8b86778647ee9d1202c132c9b228963eb8a4e5826/merged",
                "UpperDir": "/var/lib/docker/overlay2/0c87bae9f134aee7d0ce78f8b86778647ee9d1202c132c9b228963eb8a4e5826/diff",
                "WorkDir": "/var/lib/docker/overlay2/0c87bae9f134aee7d0ce78f8b86778647ee9d1202c132c9b228963eb8a4e5826/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02",
                "sha256:89a9b0585f14b54d3ecb42120761d4c93ab6736715dfe909625afa572becee7b",
                "sha256:fadec0c9d10fe63a6890d3a58cb70b1c648ca8f81d6bab51b17692eefe373f9c",
                "sha256:9988fa17fd16e25206b3fca425cc9d9a522173b3248077188d2795816a2687ad"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

2.4 启动镜像

-- 为该镜像启动分配10G内存    --name 是定义镜像的别名
[root@opensource-db ~]# docker run -tid --memory 10G --name oceanbase4 oceanbase/oceanbase-ce
ca203346509821ca5503c024235ac287641422e7356252d71067dd57565f15c5

image.png

2.5 查看容器进程

通过docker ps -a 可以查看容器进程信息。

[root@opensource-db ~]# docker ps -s
CONTAINER ID   IMAGE                    COMMAND              CREATED         STATUS         PORTS     NAMES        SIZE
ca2033465098   oceanbase/oceanbase-ce   "/bin/sh -c _boot"   3 minutes ago   Up 3 minutes             oceanbase4   11.8GB (virtual 12.2GB)

image.png

2.5 启动集群

-- 发现通过以上步骤执行后 ob是启动状态
[root@opensource-db ~]# docker exec -it ca2033465098 bash
[root@ca2033465098 ~]# ob
bash: ob: command not found
[root@ca2033465098 ~]# obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
 
-- 可以测试下OB集群的启停
[root@ca2033465098 ~]# obd cluster stop obcluster
Get local repositories ok
Search plugins ok
Open ssh connection ok
Stop observer ok
Stop obagent ok
obcluster stopped
 
[root@ca2033465098 ~]# obd cluster start obcluster
Get local repositories ok
Search plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] OBD-2000: (127.0.0.1) not enough memory. (Free: 3.3G, Need: 3.0G)
 
Check before start obagent ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster ok
Start obagent ok
obagent program health check ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A
 
+------------------------------------------------+
|                    obagent                     |
+------------+-------------+------------+--------+
| ip         | server_port | pprof_port | status |
+------------+-------------+------------+--------+
| 172.17.0.2 | 8088        | 8089       | active |
+------------+-------------+------------+--------+
obcluster running
 
[root@ca2033465098 ~]# obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
 
-- 查看OB集群config.yaml配置文件
[root@ca2033465098 ~]# cat /root/.obd/cluster/obcluster/config.yaml
oceanbase-ce:
  servers:
    # Please don't use hostname, only IP can be supported
  - 127.0.0.1
  global:
    #  The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
    home_path: /root/ob
    devname: lo
    mysql_port: 2881
    rpc_port: 2882
    zone: zone1
    cluster_id: 1
    # please set memory limit to a suitable value which is matching resource.
    memory_limit: 6G # The maximum running memory for an observer
    system_memory: 1G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
    datafile_size: 5G # Size of the data file.
    log_disk_size: 5G # The size of disk space used by the clog files.
    cpu_count: 16
    production_mode: true
    syslog_level: INFO # System log level. The default value is INFO.
    enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.
    enable_syslog_recycle: true # Enable auto system log recycling or not. The default value is false.
    max_syslog_file_count: 4 # The maximum number of reserved log files before enabling auto recycling. The default value is 0.
    appname: obcluster
  127.0.0.1:
    devname: lo
    system_memory: 1G
    production_mode: false
obagent:
  # The list of servers to be monitored. This list is consistent with the servers in oceanbase-ce.
  servers:
  - 127.0.0.1
  # Set dependent components for the component.
  # When the associated configurations are not done, OBD will automatically get the these configurations from the dependent components.
  depends:
  - oceanbase-ce
  global:
    # The working directory for obagent. obagent is started under this directory. This is a required field.
    home_path: /root/obagent
    # The port that pulls and manages the metrics. The default port number is 8088.
    server_port: 8088
    # Debug port for pprof. The default port number is 8089.
    pprof_port: 8089
    # Log level. The default value is INFO.
    log_level: INFO
    # Log path. The default value is log/monagent.log.
    log_path: log/monagent.log
    # Encryption method. OBD supports aes and plain. The default value is plain.
    crypto_method: plain
    # Path to store the crypto key. The default value is conf/.config_secret.key.
    # crypto_path: conf/.config_secret.key
    # Size for a single log file. Log size is measured in Megabytes. The default value is 30M.
    log_size: 30
    # Expiration time for logs. The default value is 7 days.
    log_expire_day: 7
    # The maximum number for log files. The default value is 10.
    log_file_count: 10
    # Whether to use local time for log files. The default value is true.
    # log_use_localtime: true
    # Whether to enable log compression. The default value is true.
    # log_compress: true
    # Username for HTTP authentication. The default value is admin.
    http_basic_auth_user: admin
    # Password for HTTP authentication. The default value is root.
    http_basic_auth_password: root
    # Username for debug service. The default value is admin.
    pprof_basic_auth_user: admin
    # Password for debug service. The default value is root.
    pprof_basic_auth_password: root
    # Monitor username for OceanBase Database. The user must have read access to OceanBase Database as a system tenant. The default value is root.
    # monitor_user: root
    # Monitor password for OceanBase Database. The default value is empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the root_password in oceanbase-ce.
    # monitor_password:
    # The SQL port for observer. The default value is 2881. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the mysql_port in oceanbase-ce.
    # sql_port: 2881
    # The RPC port for observer. The default value is 2882. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the rpc_port in oceanbase-ce.
    # rpc_port: 2882
    # Cluster name for OceanBase Database. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the appname in oceanbase-ce.
    cluster_name: obcluster
    # Cluster ID for OceanBase Database. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the cluster_id in oceanbase-ce.
    # cluster_id: 1
    # Zone name for your observer. The default value is zone1. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the zone name in oceanbase-ce.
    # zone_name: zone1
    # Monitor status for OceanBase Database.  Active is to enable. Inactive is to disable. The default value is active. When you deploy an cluster automatically, OBD decides whether to enable this parameter based on depends.
    ob_monitor_status: active
    # Monitor status for your host. Active is to enable. Inactive is to disable. The default value is active.
    host_monitor_status: active
    # Whether to disable the basic authentication for HTTP service. True is to disable. False is to enable. The default value is false.
    disable_http_basic_auth: true
    # Whether to disable the basic authentication for the debug interface. True is to disable. False is to enable. The default value is false.
    disable_pprof_basic_auth: true

2.6 查看集群信息

使用obd cluster list可以查看集群相关信息

[root@ca2033465098 ~]# obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
[root@ca2033465098 ~]# obd cluster display obcluster
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A
 
+------------------------------------------------+
|                    obagent                     |
+------------+-------------+------------+--------+
| ip         | server_port | pprof_port | status |
+------------+-------------+------------+--------+
| 172.17.0.2 | 8088        | 8089       | active |
+------------+-------------+------------+--------+
 
-- 查看资源信息,注意all_unit_config前要有两个 __
obclient [oceanbase]> select * from oceanbase.__all_unit_config;
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+---------------+----------+----------+-------------+
| gmt_create                 | gmt_modified               | unit_config_id | name            | max_cpu | min_cpu | memory_size | log_disk_size | max_iops | min_iops | iops_weight |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+---------------+----------+----------+-------------+
| 2022-12-08 15:38:38.613115 | 2022-12-08 15:38:38.613115 |              1 | sys_unit_config |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
| 2022-12-08 15:38:55.145011 | 2022-12-08 15:38:55.145011 |           1001 | test_unit       |      15 |      15 |  3221225472 |    3221225472 |   150000 |   150000 |          15 |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+---------------+----------+----------+-------------+
2 rows in set (0.007 sec)

image.png

三、验证测试

3.1 登录OB实例

-- 登陆OB集群后台
-- 根据容器OB集群config.yaml配置文件信息,提示root口令密码为空,才用如下方式登陆OB实例
[root@ca2033465098 ~]# obclient -h 127.0.0.1 -uroot -P2881 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487619
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)
 
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
7 rows in set (0.008 sec)
 
obclient [oceanbase]>
 
-- 测试
obclient [oceanbase]> use test;
Database changed
obclient [test]> show tables;
Empty set (0.007 sec)
obclient [test]> create table student
    ->   (sno char(9) primary key,
    ->    sname char (20) unique,
    ->    ssex char(2),
    ->    sage smallint,
    ->    sdept char(20)
    ->   );
Query OK, 0 rows affected (0.508 sec)
 
obclient [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| student        |
+----------------+
1 row in set (0.004 sec)
 
obclient [test]> insert into student(sno,sname,ssex,sage,sdept) values('20221208','张三','男','20','OB');
Query OK, 1 row affected (0.074 sec)
 
obclient [test]> commit;
Query OK, 0 rows affected (0.000 sec)
 
obclient [test]> select * from student;
+----------+--------+------+------+-------+
| sno      | sname  | ssex | sage | sdept |
+----------+--------+------+------+-------+
| 20221208 | 张三 | 男  |   20 | OB    |
+----------+--------+------+------+-------+
1 row in set (0.004 sec)

image.png

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尚雷5580

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值