5 分钟玩转 OceanBase 社区版 Docker 部署

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: ## 简介本文是个人把 OceanBase 社区版 3.1 做了一个 Docker 镜像,仅用于学习研究。只要你有一个 4C10G的笔记本可以联公网,你就可以在5分钟内将 OceanBase 社区版跑起来。OceanBase 社区版是今年 6月1日开源的,只兼容 MySQL,可以理解为分布式的MySQL。其核心功能跟内部业务在用的OceanBase 企业版基本一致。核心功能包含:**多副

简介

本文是个人把 OceanBase 社区版 3.1 做了一个 Docker 镜像,仅用于学习研究。只要你有一个 4C10G的笔记本可以联公网,你就可以在5分钟内将 OceanBase 社区版跑起来。

OceanBase 社区版是今年 6月1日开源的,只兼容 MySQL,可以理解为分布式的MySQL。其核心功能跟内部业务在用的OceanBase 企业版基本一致。核心功能包含:多副本高可用强一致同步在线弹性伸缩多租户等。

OceanBase 社区版跟外部其他同类开源数据库不一样的地方是,OceanBase 先有大企业级业务案例(蚂蚁业务、外部金融、运营商、央企等),再面向广大中小企业用户和个人用户。目前阶段估计主要是互联网业务公司。欢迎大家对外推荐OceanBase。

OceanBase 跟其他大部分分布式数据库产品最大的不同就是架构简单清爽,本质上是个单进程软件。集群里的每个机器部署启动一个 observer 进程,外加部分机器启动一个 obproxy 进程。每个机器角色一样,计算存储不分离。(3.2版本新增计算和存储分离功能,有2个角色,依然是单进程软件,内部测试中)。

OceanBase集群可以跨机房、跨城市部署,能做两地三中心(机房)级别的容灾或多活能力。OceanBase 软件可以部署在物理机(x86或arm)、虚拟机(ECS、VMWare等)。OceanBase 可以在公有云、专有云或者云上云下混合部署,也可以跨云厂商部署。

前提条件

请确保宿主机的可用资源满足下面要求:

  • 逻辑 CPU 不少于4个
  • 可用内存不少于 10G,并且 docker 容器内存限制不少于10G
  • 空间不少于10G

安装

笔记本需要安装 Docker,并且在 Docker 的设置里将容器使用的内存上限调整到 10 G 。下面是 Mac 版本的 Docker 容器设置。

下载镜像和启动容器

下载镜像,文件大概 2.3G 不到。具体时间取决于连接 https://hub.docker.com/repository/docker/obpilot/oceanbase-ce 网站的网速。

docker pull obpilot/oceanbase-ce:latest

docker images
REPOSITORY                                            TAG                     IMAGE ID            CREATED             SIZE
obpilot/oceanbase-ce                                  latest                  0017baaa9d87        23 minutes ago      2.24GB

docker run -itd -m 10G --name oceanbase-ce  obpilot/oceanbase-ce:latest

docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                                                                     NAMES
e5dd6da0aa8d        obpilot/oceanbase-ce:latest   "/bin/bash"              40 minutes ago      Up 40 minutes                                                                                 oceanbase-ce

启动容器的时候,可选的是如果有独立盘目录 /data,可以加上 -v /data:/data 参数。

登录容器,启动 OB 集群

容器内已经部署了 OB 社区版自动化部署工具 OBD 。使用 OBD 启动集群,第一次会初始化集群,时间需要2-3分钟(取决于宿主机性能)。

docker exec -it oceanbase-ce bash

obd cluster list

obd cluster start obdemo

下面是启动输出。

[admin@e5dd6da0aa8d ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
[admin@e5dd6da0aa8d ~]$ obd cluster start obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
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.0   | 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 用户的密码是 : adminPWD123 . 您可以使用 sudo yum 安装软件包。

创建 OB 实例(租户)

默认初始化的 OB 集群还没有创建业务实例。需要手动建一个。

obclient -h127.1 -uroot@sys#obdemo -P2883 -prootPWD123 -c -A oceanbase

alter resource unit sys_unit_config min_cpu=5;
-- 创建资源单元规格
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'; 

-- 创建资源池(分配资源)
CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;

-- 创建实例(mysql类型)
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';

exit;

登录使用 OB 实例

默认创建的 OB 实例,连接密码是空。 登录后可以导入 bmsql.sql 中的建库建表语句。

obclient -h 127.1 -uroot@obmysql#obdemo -P2883 -p -c -A test

empty password.

show databases;

source bmsql.sql

成功后,输出

MySQL [tpccdb]> show tables;
+------------------+
| Tables_in_tpccdb |
+------------------+
| bmsql_config     |
| bmsql_customer   |
| bmsql_district   |
| bmsql_history    |
| bmsql_item       |
| bmsql_new_order  |
| bmsql_oorder     |
| bmsql_order_line |
| bmsql_stock      |
| bmsql_warehouse  |
+------------------+
10 rows in set (0.003 sec)

MySQL [tpccdb]> show tablegroups;
+-----------------+------------------+---------------+
| Tablegroup_name | Table_name       | Database_name |
+-----------------+------------------+---------------+
| oceanbase       | NULL             | NULL          |
| tpcc_group      | bmsql_customer   | tpccdb        |
| tpcc_group      | bmsql_district   | tpccdb        |
| tpcc_group      | bmsql_history    | tpccdb        |
| tpcc_group      | bmsql_new_order  | tpccdb        |
| tpcc_group      | bmsql_oorder     | tpccdb        |
| tpcc_group      | bmsql_order_line | tpccdb        |
| tpcc_group      | bmsql_stock      | tpccdb        |
| tpcc_group      | bmsql_warehouse  | tpccdb        |
+-----------------+------------------+---------------+
9 rows in set (0.008 sec)

附录1:Docker 镜像制作方法

第一次使用 Dockerfile 构建镜像,还不是很娴熟,功能做的比较粗糙。下面是 Dockerfile

cat Dockerfile

FROM centos:latest
MAINTAINER obpilot
COPY ./obdemo.yaml /tmp/

VOLUME ["/data"]

RUN yum -y install tree net-tools vim sudo passwd \
    && yum -y install mariadb-connector-c \
    && yum install -y yum-utils \
    && yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo \
    && yum install -y ob-deploy obclient \
    && useradd admin && echo 'admin:adminPWD123' | chpasswd \
    && sed -i '$a\admin    ALL=(ALL)    ALL' /etc/sudoers \
    && mkdir -p /data/1 /data/log1  \
    && chown -R admin.admin /data/ /tmp/ \
    && su admin -c  "obd cluster deploy obdemo -c /tmp/obdemo.yaml"

USER admin
WORKDIR /home/admin
COPY ./bmsql.sql /home/admin/
COPY ./readme.md /home/admin/

附录2: OBD 集群初始化配置文件

OBD 是 OB 社区版推出的自动化部署工具,现在功能也越来越成熟好用了。开源网站(https://github.com/oceanbase/obdeploy/tree/master/example)提供了几个配置模板文件。这里是修改后的配置文件。部署的是单机版 OB,监听本地 IP。

## Only need to configure when remote login is required
# user:
#   username: your username
#   password: your password if need
#   key_file: your ssh-key file path if need
#   port: your ssh port, default 22
#   timeout: ssh connection timeout (second), default 30
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: /home/admin/oceanbase-ce
    # The directory for data storage. The default value is $home_path/store.
    # data_dir: /data/1
    # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
    redo_dir: /data/log1
    # Please set devname as the network adaptor's name whose ip is  in the setting of severs.
    # if set severs as "127.0.0.1", please set devname as "lo"
    # if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
    devname: lo
    mysql_port: 2881 # External port for OceanBase Database. The default value is 2881.
    rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.
    zone: zone1
    cluster_id: 1
    # please set memory limit to a suitable value which is matching resource.
    memory_limit: 8G # The maximum running memory for an observer
    system_memory: 4G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
    stack_size: 512K
    cpu_count: 16
    cache_wash_threshold: 1G
    __min_full_resource_pool_memory: 268435456
    workers_per_cpu_quota: 10
    schema_history_expire_time: 1d
    # The value of net_thread_count had better be same as cpu's core number.
    net_thread_count: 4
    major_freeze_duty_time: Disable
    minor_freeze_times: 10
    enable_separate_sys_clog: 0
    enable_merge_by_turn: FALSE
    #datafile_disk_percentage: 20 # The percentage of the data_dir space to the total disk space. This value takes effect only when datafile_size is 0. The default value is 90.
    datafile_size: 5G
    syslog_level: ERROR # 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.
    # observer cluster name, consistent with obproxy's cluster_name
    appname: obdemo
    root_password: rootPWD123 # root user password, can be empty
    proxyro_password:  proxyROPWD123 # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty
obproxy:
  servers:
    - 127.0.0.1
  global:
    listen_port: 2883 # External port. The default value is 2883.
    prometheus_listen_port: 2884 # The Prometheus port. The default value is 2884.
    home_path: /home/admin/obproxy
    # oceanbase root server list
    # format: ip:mysql_port,ip:mysql_port
    rs_list: 127.0.0.1:2881
    enable_cluster_checkout: false
    # observer cluster name, consistent with oceanbase-ce's appname
    cluster_name: obdemo
    obproxy_sys_password:  proxySYSPWD123 # obproxy sys user password, can be empty
    observer_sys_password: proxyROPWD123 # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be empty
    automatic_match_work_thread: false
    work_thread_num: 12
    xflush_log_level: ERROR
    monitor_log_level: ERROR
    syslog_level: ERROR
    log_dir_size_threshold: 1G
    enable_compression_protocol: false

里面的 datafile_size 写的很小(5G)。如果你磁盘空间很大,可以后期对 OB集群里数据文件扩容。

其他参考

有问题欢迎留言,或者登录 OB 社区版官网问答区(https://open.oceanbase.com/answer) ,或者 OB社区版钉钉群直接跟开发和其他用户沟通交流。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
13天前
|
运维 网络安全 持续交付
IDEA+Docker 远程一键部署项目:技术干货分享
【10月更文挑战第4天】在现代软件开发中,快速、可靠、自动化的部署流程是提升开发效率和运维质量的关键。IDEA(IntelliJ IDEA)作为Java开发者首选的IDE,结合Docker这一轻量级容器化技术,能够实现远程一键部署项目,极大地简化了开发到生产的流程。今天,我将和大家分享这一组合在工作学习中的实际应用和技术干货。
76 3
|
8天前
|
JSON JavaScript 测试技术
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
【10月更文挑战第9天】使用Docker部署PPTist在线演示文稿应用
15 1
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
|
10天前
|
存储 前端开发 测试技术
【Docker项目实战】使用Docker部署Calcium网页计算器
【10月更文挑战第7天】使用Docker部署Calcium网页计算器
20 1
【Docker项目实战】使用Docker部署Calcium网页计算器
|
13天前
|
存储 测试技术 Linux
【Docker项目实战】使用Docker部署Radicale日历和联系人应用
【10月更文挑战第4天】使用Docker部署Radicale日历和联系人应用
53 2
【Docker项目实战】使用Docker部署Radicale日历和联系人应用
|
7天前
|
Web App开发 前端开发 测试技术
【Docker项目实战】使用docker部署tabler后台模版
【10月更文挑战第10天】使用docker部署tabler后台模版
20 0
【Docker项目实战】使用docker部署tabler后台模版
|
9天前
|
消息中间件 编解码 Docker
【Docker项目实战】Docker部署RabbitMQ消息中间件
【10月更文挑战第8天】Docker部署RabbitMQ消息中间件
22 0
【Docker项目实战】Docker部署RabbitMQ消息中间件
|
12天前
|
SQL 监控 数据库
OceanBase社区版可以通过Zabbix监控
【10月更文挑战第5天】随着OceanBase社区版的广泛应用,企业纷纷采用这一高性能、高可用的分布式数据库系统。为了确保系统的稳定运行,使用成熟的Zabbix监控工具进行全面监控至关重要。本文通过具体示例介绍了如何配置Zabbix监控OceanBase,包括安装配置、创建监控模板和监控项、编写脚本、设置触发器及图形展示等步骤,帮助读者快速上手,及时发现并解决问题,确保业务始终处于最佳状态。
22 2
|
15天前
|
定位技术 文件存储 网络架构
Docker部署PhotoPrism、Immich图片管理应用,无需公网IP远程访问教程
除了Synology、QNAP、TerraMaster等品牌的NAS设备内置图库功能,市面上还有多种备受欢迎的第三方应用,如PhotoPrism、Immich、LibrePhotos、Piwigo、Photoview等。这些应用不仅提供强大的图片管理能力,还可通过Docker轻松部署。借助贝锐花生壳服务,即使没有公网IP也能实现远程访问,突破地理限制,提升数据可访问性和安全性,让用户随时随地管理私人图库。
58 1
|
3天前
|
运维 Kubernetes 监控
掌握Docker容器化技术:构建、部署与管理的高效实践
【10月更文挑战第14天】掌握Docker容器化技术:构建、部署与管理的高效实践
12 0
|
4天前
|
关系型数据库 数据库 PostgreSQL
在docker上部署postgresSQL主从
通过以上步骤,我们完成了在Docker环境中部署PostgreSQL主从复制的基本配置。请注意,实际生产环境中还需考虑安全性增强(如SSL加密)、监控、自动故障切换等高级配置。此外,根据具体的业务需求和规模,可能还需要考虑使用更专业的解决方案或工具,如Patroni、PgBouncer等,来进一步提升数据库集群的稳定性和效率。
11 0