10分钟让你快速部署一套OceanBase数据库

2024年 5月 7日 41.3k 0

OceanBase 社区版是一款开源分布式 HTAP(Hybrid Transactional/Analytical Processing)数据库管理系统,具有原生分布式架构,支持金融级高可用、透明水平扩展、分布式事务、多租户和语法兼容等企业级特性。OceanBase 内核通过大规模商用场景的考验,已服务众多行业客户,现面向未来持续构建内核技术竞争力。

以前考过OceanBase的OBCA认证,但OceanBase部署对机器资源要求非常高,一直没有机会亲自体验OceanBase的强大功能,最近看OceanBase 社区版入门教程发现可以快速通过 Docker部署OceanBase数据库;

本篇文件记录我用时10分钟不到就部署的OceanBase数据库的过程,让大家看到体验OceanBase数据库如此简单。

参考dockerhub网址:https://hub.docker.com/r/obpilot/oceanbase-ce

资源要求Prerequisite:

Make sure the available resources meet the requirements:

The logical CPU count is no less than 4.

The available memory is no less than 10G, and the docker container memory limit is no less than 10G.

The available disk space is no less than 10G.

我的主机环境

hhj@k-m:~$ cat /etc/issue
Ubuntu 18.04.5 LTS \n \l
hhj@k-m:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:          11701        6104        4787           0         810        5352
Swap:             0           0           0

docker版本信息

hhj@k-m:~$ docker info
Client:Context:    defaultDebug Mode: false

Server:
ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get ck: connect: permission denied
errors pretty printing info
hhj@k-m:~$ sudo docker info 
[sudo] password for hhj: 
Client:Context:    defaultDebug Mode: false

Server:Containers: 40Running: 7Paused: 0Stopped: 33Images: 18Server Version: 20.10.7Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 
 runc version: 
 init version: 
 Security Options:apparmorseccompProfile: defaultKernel Version: 4.15.0-140-genericOperating System: Ubuntu 18.04.5 LTSOSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 3.666GiBName: k-mID: 2QL5:WAWI:KZQU:BQF3:5TPQ:HYYZ:J3DX:HBKK:3O53:ACJI:ZGTB:M4QNDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors:https://b9pmyelo.mirror.aliyuncs.com/Live Restore Enabled: false

下载dockerhub的OB镜像

hhj@k-m:~$ sudo docker pull obpilot/oceanbase-ce
Using default tag: latest
latest: Pulling from obpilot/oceanbase-ce
7a0437f04f83: Pull complete 
615dc48ac9f1: Pull complete 
b10c1cdae3af: Pull complete 
4f4fb700ef54: Pull complete 
c0f6c94a6a6a: Pull complete 
792630f35e24: Pull complete 
Digest: sha256:7ac28415cf27ba19cb47acb67a55ebf9848ad73a63d80b7e2e85d653233dbaeb
Status: Downloaded newer image for obpilot/oceanbase-ce:latest
docker.io/obpilot/oceanbase-ce:latest

启动oceanbase镜像并查看容器

hhj@k-m:~$ sudo docker run -itd -m 9G --name OB  obpilot/oceanbase-ce:latest
WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
b587086e636802447bfa90b613e19627c05df94609da12501c29fd82d43e3b84
hhj@k-m:~$ sudo docker ps
CONTAINER ID   IMAGE                         COMMAND       CREATED          STATUS          PORTS                NAMES
b587086e6368   obpilot/oceanbase-ce:latest   "/bin/bash"   20 seconds ago   Up 15 seconds   2881/tcp, 2883/tcp   OB

进入oceanbase容器并启动obdemo

hhj@k-m:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:          11701         246       11040           0         414       11210
Swap:             0           0           0
hhj@k-m:~$ sudo docker exec -it OB bash
[admin@b587086e6368 ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:          11701         275       11009           0         416       11183
Swap:             0           0           0
[admin@b587086e6368 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
[admin@b587086e6368 ~]$ obd cluster start obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
[WARN] (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)

Check before start obproxy ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster
Cluster bootstrap ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 3.1.1   | 2881 | zone1 | active |
+-----------+---------+------+-------+--------+

Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize cluster
+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+
obdemo running
[admin@b587086e6368 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | running         |
+--------+---------------------------------+-----------------+

验证第一次登陆OB并查看有些什么库,好激动。

admin 用户的密码是 : adminPWD123

[admin@b587086e6368 ~]$ obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase

Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [oceanbase]> 
MySQL [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set (0.025 sec)


快速创建资源单元、资源池以及租户

MySQL [oceanbase]> CREATE resource unit S4C1G max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G'; 
Query OK, 0 rows affected (0.266 sec)

MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
Query OK, 0 rows affected (0.480 sec)

MySQL [oceanbase]> create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';

Query OK, 0 rows affected (35.438 sec)

MySQL [oceanbase]> 
MySQL [oceanbase]> select * from __all_tenant\G
*************************** 1. row ***************************gmt_create: 2021-12-15 16:16:07.626888gmt_modified: 2021-12-15 16:16:07.626888tenant_id: 1tenant_name: sysreplica_num: -1zone_list: zone1primary_zone: zone1locked: 0collation_type: 0info: system tenantread_only: 0rewrite_merge_version: 0locality: FULL{1}@zone1logonly_replica_num: 0previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0default_tablegroup_id: -1compatibility_mode: 0drop_tenant_time: -1status: TENANT_STATUS_NORMALin_recyclebin: 0
*************************** 2. row ***************************gmt_create: 2021-12-15 16:42:01.677021gmt_modified: 2021-12-15 16:42:01.677021tenant_id: 1001tenant_name: obmysqlreplica_num: -1zone_list: zone1primary_zone: RANDOMlocked: 0collation_type: 0info: mysql tenant/instanceread_only: 0rewrite_merge_version: 0locality: FULL{1}@zone1logonly_replica_num: 0previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0default_tablegroup_id: -1compatibility_mode: 0drop_tenant_time: -1status: TENANT_STATUS_NORMALin_recyclebin: 0
2 rows in set (0.093 sec)

MySQL [oceanbase]> exit
Bye

最后登录刚创建的租户

[admin@b587086e6368 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
Enter password: 
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.025 sec)

MySQL [test]> 

完美收工,今天的分享就到这里,接下来好好体验一下我的第一个OceanBase数据库。

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论