首批通过分布式安全可靠测评,为关键业务系统打造
单机部署 OceanBase 集群
更新时间:2026-04-14 17:55:42
本文介绍如何使用 obd 部署单机版 OceanBase 集群。操作示例仅用于帮助了解 OceanBase 数据库,不建议生产环境中使用。
说明
使用 obd 白屏部署的操作介绍可参见 通过图形化界面部署 OceanBase 集群。
使用 obd 部署多节点集群的操作介绍可参见《OceanBase 数据库文档》中 使用命令行部署 OceanBase 数据库生产环境。
名词解释
中控机器:存储 OceanBase 数据库安装包和集群配置信息的机器。
目标机器:安装 OceanBase 集群的机器。
前提条件
在开始之前,请确保您已满足以下条件:
仅部署 OceanBase 数据库,至少需要 2vCPU、6 GB 内存、20 GB 磁盘的可用资源。
您的机器中已安装 obd,建议安装最新版本,详细信息请参考 安装 obd。
您的机器中已安装 OBClient 客户端,详细信息请参考 OBClient 文档。
说明
- 当机器无法连接到外部网络时,建议通过 OceanBase All in One 安装 obd。OceanBase All in One 中提供需要的全部组件(除 obbinlog 组件),且组件已经经过相互适配测试。
OceanBase All in One 安装时会自动安装 obd 和 OBClient 客户端,因此,若您通过 OceanBase All in One 安装 obd,可忽略前提条件中除资源要求外的其他内容。
操作步骤
步骤一:配置 obd
部署 OceanBase 集群之前,为了数据安全,建议您切换到非 root 用户。
如果机器无法连接到外部网络,且对部署所需组件版本有特别要求,可从 OceanBase 软件下载中心 页面自行下载组件对应版本安装包,复制到机器任一目录,在该目录下参考以下步骤配置 obd。
如果机器可以连接外部网络,且未禁用远程镜像仓库,您可跳过步骤 1~3,直接在配置文件中指定组件版本。
说明
通过 OceanBase All in One 安装 obd 后默认禁用远程镜像仓库,您可执行 obd mirror enable remote 命令启用远程镜像仓库。
禁用远程镜像仓库
[admin@test001 rpm]$ obd mirror disable remote禁用后可执行
obd mirror list命令进行确认,输出中 oceanbase.xxx 两行中Enabled列展示为False,说明已关闭远程镜像源。示例如下:+-----------------------------------------------------------------------------+ | Mirror Repository List | +----------------------------+--------+---------+----------+------------------+ | SectionName | Type | Enabled | Avaiable | Update Time | +----------------------------+--------+---------+----------+------------------+ | local | local | - | True | 2025-02-19 15:56 | | oceanbase.community.stable | remote | False | False | 2025-02-19 15:54 | | oceanbase.development-kit | remote | False | False | 2025-02-19 15:54 | +----------------------------+--------+---------+----------+------------------+将安装包添加至本地镜像库
[admin@test001 rpm]$ obd mirror clone *.rpm查看本地镜像库中安装包列表
[admin@test001 rpm]$ obd mirror list local
步骤二:修改配置文件
若您机器中的 obd 是通过直接下载的方式安装,则可在 /usr/obd/example 目录下查看 obd 提供的配置文件示例。
若您机器中的 obd 是通过解压 all-in-one 安装包的方式安装,则可在 ~/.oceanbase-all-in-one/obd/usr/obd/example 目录下查看 obd 提供的配置文件示例。
不同配置文件示例的区别可参见 配置文件说明 中 获取配置文件示例,请根据您的资源条件选择相应的配置文件。
说明
本文末会提供完整的单机部署 OceanBase 集群的 配置文件示例,您也可直接复制并进行修改。
此处以小规格开发模式-单机部署(mini-single-example.yaml)为例介绍配置文件。
说明
您需根据您环境的真实情况修改下述参数。
修改用户信息
## Only need to configure when remote login is required user: username: admin # password: your password if need key_file: /home/admin/.ssh/id_rsa # port: your ssh port, default 22 # timeout: ssh connection timeout (second), default 30username为登录到目标机器的用户名,确保您的用户名有下文home_path的写权限。password和key_file均用于验证用户,通常情况下只需要填写一个。注意
在配置秘钥路径后,如果您的秘钥不需要口令,请注释或者删除
password,以免password被视为秘钥口令用于登录,导致校验失败。修改机器的 IP、端口和相关目录,并配置内存相关参数及 root@sys 用户密码
oceanbase-ce: # version: 4.3.5.0 servers: - name: server1 ip: 10.10.10.1 global: # 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: eth0 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: 2G # Size of the data file. datafile_next: 2G # the auto extend step. Please enter an capacity, such as 2G datafile_maxsize: 20G # the auto extend max size. Please enter an capacity, such as 20G log_disk_size: 14G # The size of disk space used by the clog files. cpu_count: 16 scenario: htap mysql_port: 2881 # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started. rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started. obshell_port: 2886 # Operation and maintenance port for Oceanbase Database. The default value is 2886. This parameter is valid only when the version of oceanbase-ce is 4.2.2.0 or later. production_mode: false # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field. home_path: /home/admin/observer # The directory for data storage. The default value is $home_path/store. data_dir: /data # The directory for clog, ilog, and slog. The default value is the same as the data_dir value. redo_dir: /redo root_password: ****** # root user password, can be empty zone: zone1配置文件中各配置项含义可参见 配置文件说明 一文中 配置项说明 部分介绍。需注意如下三点:
配置文件中若未配置密码,obd 会自动生成随机密码,部署成功后可通过
obd cluster edit-config命令查看配置文件中对应的配置项获取密码。待部署的 OceanBase 数据库为 V4.3.0 或之后版本时,配置文件中若未配置
scenario,obd 会提供交互式选项供用户选择负载类型。如需部署单机多节点 OceanBase 集群,可在
oceanbase-ce->servers下使用同一 IP 配置多个 server,需确保不同 server 下使用不同的端口和目录。配置文件具体可参见下文 配置文件示例。
步骤三:部署 OceanBase 数据库
说明
本节中所使用命令的详细使用方法可参考 集群命令组。
部署 OceanBase 集群
[admin@test001 ~]$ obd cluster deploy obtest -c mini-single-example.yaml示例中是以部署集群名为
obtest,配置文件为mini-single-example.yaml为例,您可自定义部署集群名,并根据实际情况指定所需配置文件。此命令会检查
home_path和data_dir指向的目录是否为空,目录不为空时将报错。若您确认该目录下的内容可全部删除,可以加上-f选项,强制清空目录。启动 OceanBase 集群
[admin@test001 ~]$ obd cluster start obtest查看 OceanBase 集群状态
[admin@test001 ~]$ obd cluster display obtest
步骤四:连接 OceanBase 数据库
运行以下命令,使用 OBClient 客户端连接 OceanBase 数据库:
obclient -h<IP> -P<PORT> -uroot@sys -p
其中,IP 为 OBServer 节点的 IP 地址;PORT 为连接 OceanBase 数据库的的端口,直连时为 mysql_port 配置项的值,默认端口为 2881,如果您对端口做了修改,此处使用您实际配置的端口号。
说明
部署 OceanBase 集群之后,建议创建业务租户进行业务操作。sys 租户仅做集群管理使用,不适合在业务场景中使用。您可执行 obd cluster tenant create 命令创建租户,或连接到 OceanBase 数据库后执行 SQL 命令创建租户,obd 命令介绍可参见 集群命令组,使用 SQL 命令创建租户的详细操作可参见官网《OceanBase 数据库》文档 管理数据库/租户管理/租户常见操作/创建租户。
相关操作
您可执行如下命令对 obd 部署的集群进行管理。更多操作详见 集群命令组。
查看集群列表
obd cluster list查看集群状态,以部署名为
obtest为例obd cluster display obtest修改集群参数
OceanBase 数据库有数百个配置项,有些配置是耦合的,在您熟悉 OceanBase 数据库之前,不建议您修改示例配件文件中的配置。
执行如下命令打开配置文件,修改集群配置
obd cluster edit-config obtest修改配置并保存退出后,obd 会告知如何使得此次修改生效,复制 obd 输出的命令即可。保存修改后输出如下:
Search param plugin and load ok Search param plugin and load ok Parameter check ok Save deploy "obtest" configuration Use `obd cluster reload obtest` to make changes take effect.复制执行输出中的
obd cluster reload obtest命令即可使修改生效。创建用户租户,以为
obtest集群创建test租户为例obd cluster tenant create obtest -n test --max-cpu=2 --memory-size=2G --log-disk-size=3G --max-iops=10000 --iops-weight=2 --unit-num=1 --charset=utf8 -o htap -s 'ob_tcp_invited_nodes="%"'停止运行中的集群,以部署名为
obtest为例obd cluster stop obtest销毁已部署的集群,以部署名为
obtest为例obd cluster destroy obtest
配置文件示例
user:
username: admin
password: ********
# key_file: /home/admin/.ssh/id_rsa
oceanbase-ce:
# version: 4.3.5.0
servers:
- name: server1
ip: 10.10.10.1
global:
devname: eth0
cluster_id: 1
memory_limit: 6G
system_memory: 1G
datafile_size: 2G
datafile_next: 2G
datafile_maxsize: 20G
log_disk_size: 14G
cpu_count: 16
scenario: htap
mysql_port: 2881
rpc_port: 2882
obshell_port: 2886
production_mode: false
home_path: /home/admin/observer
data_dir: /data/date
redo_dir: /data/redo
root_password: ******
zone: zone1
user:
username: admin
password: ********
# key_file: /home/admin/.ssh/id_rsa
oceanbase-ce:
servers:
- name: server1
ip: 10.10.10.1
- name: server2
ip: 10.10.10.1
- name: server3
ip: 10.10.10.1
global:
devname: eth0
cluster_id: 1
memory_limit: 6G # The maximum running memory for an observer
system_memory: 1G # The reserved system memory. system_memory is reserved for general tenants.
datafile_size: 2G # Size of the data file.
datafile_next: 2G
datafile_maxsize: 20G
log_disk_size: 14G
production_mode: false
scenario: htap
appname: obdemo
root_password: ********
server1:
zone: zone1
mysql_port: 3881
rpc_port: 3882
obshell_port: 3886
home_path: /home/admin/observer1
data_dir: /data/data1
redo_dir: /data/redo1
server2:
zone: zone2
mysql_port: 4881
rpc_port: 4882
obshell_port: 4886
home_path: /home/admin/observer2
data_dir: /data/data2
redo_dir: /data/redo2
server3:
zone: zone3
mysql_port: 5881
rpc_port: 5882
obshell_port: 5886
home_path: /home/admin/observer3
data_dir: /data/data3
redo_dir: /data/redo3