诸岳
#1
引言
-
Zeabur 是一个开箱即用、功能强大的自动化部署平台,不仅可以快速部署各类应用,还可以一键部署 MySQL、PostgreSQL 等数据库服务。
- Zeabur 在国内外有大量用户,除了 AFFiNE、Bytebase 等企业客户之外,大部分都是全栈和独立开发者。如果能将 OceanBase 集成到 Zeabur 的 第三方服务市场,可以有效降低 OceanBase 的使用门槛,提升与开发者现有技术栈和研发流程的集成效率。
Zeabur 模板
- 简单来说,Zeabur 模板 通过 YAML 配置来声明和编排服务,类似于 Docker Compose 和 Kubernetes Object 的能力。并且 Zeabur 还提供 CLI 工具来快速部署、创建和管理模板。
- 目前 Zeabur 支持两种类型的服务: Docker 镜像和 Git 代码。因此,只需要按照 Zeabur 的 模板语法,声明 OceanBase 服务的部署逻辑即可。
OceanBase 部署模板
# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
name: OceanBase
spec:
description: An enterprise distributed relational database with high availability, high performance, horizontal scalability, and compatibility with SQL standards.
coverImage: https://mdn.alipayobjects.com/huamei_fhnyvh/afts/img/A*qI5lT4lL1PEAAAAAAAAAAAAAemfOAQ/original
icon: https://avatars.githubusercontent.com/u/82347605
tags:
- Database
readme: |
An enterprise distributed relational database with high availability, high performance, horizontal scalability, and compatibility with SQL standards.
## Environment Variables
When you deploy the OceanBase service, Zeabur will automatically inject the relevant environment variables into other services.
- `OB_HOST`: The hostname of the OceanBase service.
- `OB_PORT`: The port of the OceanBase service.
- `OB_TENANT`: The tenant of the OceanBase service.
- `OB_USERNAME`: The username for the OceanBase service.
- `OB_PASSWORD`: The password for the OceanBase service.
- `OB_URI` or `OB_CONNECTION_STRING`: The connection string for the OceanBase service.
services:
- name: oceanbase
icon: https://avatars.githubusercontent.com/u/82347605
template: PREBUILT
spec:
source:
image: oceanbase/oceanbase-ce:4.3.5.0-100000202024123117
ports:
- id: database
port: 2881
type: TCP
volumes:
- id: data
dir: /data/1
- id: log
dir: /data/log1
instructions:
- type: TEXT
title: Command to connect to your OceanBase
content: mysql -h${PORT_FORWARDED_HOSTNAME} -P${DATABASE_PORT_FORWARDED_PORT} -u${OB_USERNAME}@${OB_TENANT} -p${OB_PASSWORD}
- type: TEXT
title: OceanBase host
content: ${PORT_FORWARDED_HOSTNAME}
category: Hostname & Port
- type: TEXT
title: OceanBase port
content: ${DATABASE_PORT_FORWARDED_PORT}
category: Hostname & Port
- type: TEXT
title: OceanBase tenant
content: ${OB_TENANT}
category: Credentials
- type: TEXT
title: OceanBase username
content: ${OB_USERNAME}
category: Credentials
- type: PASSWORD
title: OceanBase password
content: ${OB_PASSWORD}
category: Credentials
env:
# custom env in zeabur
OB_HOST:
default: ${CONTAINER_HOSTNAME}
expose: true
readonly: true
OB_PORT:
default: ${DATABASE_PORT}
expose: true
readonly: true
OB_TENANT:
default: ${OB_TENANT_NAME}
expose: true
readonly: true
OB_USERNAME:
default: root
expose: true
readonly: true
OB_PASSWORD:
default: ${OB_TENANT_PASSWORD}
expose: true
readonly: true
# oceanbase-ce docker built-in env
OB_SYS_PASSWORD:
default: ${PASSWORD}
expose: true
readonly: true
OB_TENANT_PASSWORD:
default: ${PASSWORD}
expose: true
readonly: true
OB_TENANT_NAME:
default: test
expose: true
readonly: true
localization:
zh-CN:
description: 为现代数据架构打造的分布式数据库。
readme: |
为现代数据架构打造的分布式数据库。
## 环境变量
当您部署 OceanBase 服务时,Zeabur 会自动将相关的环境变量注入到其他服务中。
- `OB_HOST`:OceanBase 服务的主机名。
- `OB_PORT`:OceanBase 服务的端口。
- `OB_TENANT`:OceanBase 服务的租户。
- `OB_USERNAME`:OceanBase 服务的用户名。
- `OB_PASSWORD`:OceanBase 服务的密码。
- `OB_URI` 或 `OB_CONNECTION_STRING`:OceanBase 服务的连接字符串。
zh-TW:
description: 為現代數據架構打造的分散式資料庫。
readme: |
為現代數據架構打造的分散式資料庫。
## 環境變數
當您部署 OceanBase 服務時,Zeabur 會自動將相關的環境變數注入到其他服務中。
- `OB_HOST`:OceanBase 服務的主機名稱。
- `OB_PORT`:OceanBase 服務的連接埠。
- `OB_TENANT`:OceanBase 服務的租戶。
- `OB_USERNAME`:OceanBase 服務的使用者名稱。
- `OB_PASSWORD`:OceanBase 服務的密碼。
- `OB_URI` 或 `OB_CONNECTION_STRING`:OceanBase 服務的連線字串。
一键部署 OceanBase
添加独立服务器
注意: 服务器的可用内存 >= 6G,否则 OceanBase 会启动失败,可通过 free -h
命令查看。
- 在 Zeabur 上 添加独立服务器 (如果没有服务器,也可以在 Zeabur 上直接购买,这里我选择阿里云的 ECS):
部分用户可能对于 ECS 的端口访问有安全要求,如果不想全网开放、只针对 Zeabur 开放访问,需要针对 Zeabur 所在网段进行配置。可以参考 这个案例 在 Discord 上提单咨询,Zeabur 的技术支持人员会提供解决方案。
部署 OceanBase 服务
- 在新建的项目上「添加服务 → 从模板部署 → 搜索并选择 OceanBase」:
- 如果是国内的服务器,则可能会遇到镜像拉取失败的问题,可以选择「更换国内镜像源」:
连接 OceanBase
- 使用 MySQL 命令行连接 OceanBase:
环境变量
- 目前仅透出以下环境变量 (如有更多诉求,
欢迎留言评论):
5 个赞