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

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

原创 华军 2021-12-15
1384

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:    default
 Debug 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:    default
 Debug Mode: false

Server:
 Containers: 40
  Running: 7
  Paused: 0
  Stopped: 33
 Images: 18
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-140-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 3.666GiB
 Name: k-m
 ID: 2QL5:WAWI:KZQU:BQF3:5TPQ:HYYZ:J3DX:HBKK:3O53:ACJI:ZGTB:M4QN
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry 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.626888
               gmt_modified: 2021-12-15 16:16:07.626888
                  tenant_id: 1
                tenant_name: sys
                replica_num: -1
                  zone_list: zone1
               primary_zone: zone1
                     locked: 0
             collation_type: 0
                       info: system tenant
                  read_only: 0
      rewrite_merge_version: 0
                   locality: FULL{1}@zone1
        logonly_replica_num: 0
          previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0
      default_tablegroup_id: -1
         compatibility_mode: 0
           drop_tenant_time: -1
                     status: TENANT_STATUS_NORMAL
              in_recyclebin: 0
*************************** 2. row ***************************
                 gmt_create: 2021-12-15 16:42:01.677021
               gmt_modified: 2021-12-15 16:42:01.677021
                  tenant_id: 1001
                tenant_name: obmysql
                replica_num: -1
                  zone_list: zone1
               primary_zone: RANDOM
                     locked: 0
             collation_type: 0
                       info: mysql tenant/instance
                  read_only: 0
      rewrite_merge_version: 0
                   locality: FULL{1}@zone1
        logonly_replica_num: 0
          previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0
      default_tablegroup_id: -1
         compatibility_mode: 0
           drop_tenant_time: -1
                     status: TENANT_STATUS_NORMAL
              in_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数据库。

最后修改时间:2021-12-15 18:34:15
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论