ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

看完就会!OceanBase 三节点集群最便捷搭建指南

看完就会!OceanBase 三节点集群最便捷搭建指南 前面两篇文章分别介绍了使用 ocp 部署和纯命令部署三节点 OceanBase 集群这篇我们来介绍一下如何用最简单的方式部署 OceanBase 集群—— 通过 obd 部署。OBD 全称为 OceanBase Deployer是 OceanBase 集群安装部署工具通过命令行部署或白屏界面部署的方式obd web将复杂配置流程标准化降低集群部署难度。OBD 除了自动化安装部署 OceanBase 数据库外还提供了组件检查、参数修改、启停管理及软件包管理等常用运维操作。核心功能有一键部署通过单条命令完成多节点集群的安装与初始化。依赖分发自动将所需的 RPM 安装包分发到各台服务器。环境检查自动检测各节点的主机资源、网络和内核参数。生命周期管理支持集群的启动、停止、重启、升级和销毁。1. 集群规划依旧规划三个节点选择第一台机器作为中控机OBD 所在的机器第二台机器部署 obclient 客户端 第三台机器部署 OBProxy。主机名IP 地址配置大小部署角色OceanBase1192.168.182.218C16G120gOBServer,中控机OceanBase2192.168.182.228C16G120gOBServer,obclientOceanBase3192.168.182.238C16G120gOBServer,OBProxy2. 环境准备以下操作无说明均在三台机器使用 root 用户操作。2.1 创建 admin 用户useradd -U admin -d /home/admin -s /bin/bash echo admin|passwd --stdin admin echo admin ALL(ALL) NOPASSWD: ALL | sudo tee -a /etc/sudoers /dev/null2.2 内核参数设置cat /etc/sysctl.conf EOF net.core.somaxconn 2048 net.core.netdev_max_backlog 10000 net.core.rmem_default 16777216 net.core.wmem_default 16777216 net.core.rmem_max 16777216 net.core.wmem_max 16777216 net.ipv4.ip_local_port_range 3500 65535 net.ipv4.ip_forward 0 net.ipv4.conf.default.rp_filter 1 net.ipv4.conf.default.accept_source_route 0 net.ipv4.tcp_syncookies 1 net.ipv4.tcp_rmem 4096 87380 16777216 net.ipv4.tcp_wmem 4096 65536 16777216 net.ipv4.tcp_max_syn_backlog 16384 net.ipv4.tcp_fin_timeout 15 net.ipv4.tcp_tw_reuse 1 net.ipv4.tcp_slow_start_after_idle0 net.ipv4.ip_local_reserved_ports 62881-63881 vm.swappiness 0 kernel.core_pattern /data/1/core-%e-%p-%t kernel.numa_balancing 0 kernel.sched_migration_cost_ns 0 vm.zone_reclaim_mode 0 # vm.min_free_kbytes 2097152 vm.overcommit_memory 0 fs.aio-max-nr1048576 vm.max_map_count655360 vm.nr_hugepages 0 fs.file-max6573688 EOF2.3 关闭防火墙和 NetworkManagerCentos 7 及以下版本建议关闭 NetworkManager使用 networksystemctl stop NetworkManager firewalld.service systemctl disable NetworkManager firewalld.service2.4 yum 源配置本地 VMware 虚拟机可以连公网因此使用 阿里云 的 Centos 源。sudo wget -O /etc/yum.repos.d/CentOS-Base.repo HTTPS://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache2.5 禁用 selinuxsed -i s/SELINUXenforcing/SELINUXdisabled/ /etc/selinux/config2.6 关闭透明大页和 NUMA#禁用透明大页 sed -i s/GRUB_CMDLINE_LINUX/GRUB_CMDLINE_LINUXtransparent_hugepagenever /g /etc/default/grub #禁用 NUMA Intel 环境建议关闭 Hygon、AMD、ARM 环境中建议打开 NUMA sed -i s/GRUB_CMDLINE_LINUX/GRUB_CMDLINE_LINUXnumaoff /g /etc/default/grub grub 2-mkconfig -o /boot/grub 2/grub.cfg #重启生效 reboot # 显示如下表示关闭成功 [rootoceanbase1 ob4x]# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never] [rootoceanbase1 ob4x]# dmesg | grep -i numa [ 0.000000] NUMA turned off2.7 配置时间同步# 在集群中的第一个节点安装chrony并配置为服务节点 yum -y install chrony vi /etc/chrony.conf 修改以下参数并保存 server 127.127.1.0 allow 192.168.182.0/24 #指定各节点的IP网段 local stratum 10 #提供的公网NTP服务器不可用时采用本地时间作为同步标准 # 启动chronyd: systemctl enable chronyd.service systemctl restart chronyd.service systemctl status chronyd.service # 集群其它节点安装并配置chrony yum -y install chrony mv /etc/chrony.conf /etc/chrony.conf.bak vim /etc/chrony.conf server 192.168.182.21 iburst rtcsync local stratum 10 # 启动chronyd服务 systemctl enable chronyd.service systemctl restart chronyd.service systemctl status chronyd.service # 查看时间同步活动 chronyc activity # 查看时间服务器 chronyc sources # 查看同步状态 chronyc sources -v # 校准时间服务器 chronyc tracking3. 准备部署3.1 下载 oceanbase-all-in-one 安装包bash -c $(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/oceanbase-all-in-one/installer.sh) source ~/.oceanbase-all-in-one/bin/env.sh # 出现如下界面表示安装成功 ######################################################################################### Install Finished Setup Environment: source ~/.oceanbase-all-in-one/bin/env.sh Quick Start: obd demo Quick Start (performance): obd perf Interactive install: obd cluster deploy -i Use Web Service to install: obd web Use Web Service to upgrade: obd web upgrade More Details: obd -h [rootoceanbase1 ~]# source ~/.oceanbase-all-in-one/bin/env.sh3.2 编辑集群配置文件## 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: - name: server1 # Please dont use hostname, only IP can be supported ip: 192.168.2.21 - name: server2 ip: 192.168.2.22 - name: server3 ip: 192.168.2.23 global: # Starting from observer version 4.2, the network selection for the observer is based on the local_ip parameter, and the devname parameter is no longer mandatory. # If the local_ip parameter is set, the observer will first use this parameter for the configuration, regardless of the devname parameter. # If only the devname parameter is set, the observer will use the devname parameter for the configuration. # If neither the devname nor the local_ip parameters are set, the local_ip parameter will be automatically assigned the IP address configured above. # devname: eth0 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: 1G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G. datafile_size: 10G # Size of the data file. datafile_next: 2G # the auto extend step. Please enter an capacity, such as 2G datafile_maxsize: 50G # the auto extend max size. Please enter an capacity, such as 20G log_disk_size: 40G # The size of disk space used by the clog files. cpu_count: 8 production_mode: false enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true. 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 obproxys cluster_name appname: obcluster # root_password: # root user password, can be empty # proxyro_password: # proxyro user pasword, consistent with obproxys observer_sys_password, can be empty server1: 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. # 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/1 # The directory for clog, ilog, and slog. The default value is the same as the data_dir value. redo_dir: /data/log1 zone: zone1 server2: 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. # 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/1 # The directory for clog, ilog, and slog. The default value is the same as the data_dir value. redo_dir: /data/log1 zone: zone2 server3: 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. # 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/1 # The directory for clog, ilog, and slog. The default value is the same as the data_dir value. redo_dir: /data/log1 zone: zone3 obproxy-ce: # Set dependent components for the component. # When the associated configurations are not done, OBD will automatically get the these configurations from the dependent components. depends: - oceanbase-ce servers: - 192.168.182.23 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. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. # rs_list: 192.168.1.2:2881;192.168.1.3:2881;192.168.1.4:2881 enable_cluster_checkout: false # observer cluster name, consistent with oceanbase-ces appname. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. # cluster_name: obcluster skip_proxy_sys_private_check: true enable_strict_kernel_release: false # obproxy_sys_password: # obproxy sys user password, can be empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. # observer_sys_password: # proxyro user pasword, consistent with oceanbase-ces proxyro_password, can be empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.3.3 查看可安装的包[rootoceanbase1 ~]# obd mirror list --------------------------------------------------------------------------------- | Mirror Repository List | ----------------------------------------------------------------------------- | SectionName | Type | Enabled | Avaiable | Update Time | ----------------------------------------------------------------------------- | local | local | - | True | 2026-08-01 14:27 | | oceanbase.community.stable.al8 | remote | False | False | 1970-01-01 08:00 | | oceanbase.development-kit.al8 | remote | False | False | 1970-01-01 08:00 | | oceanbase.community.stable.el | remote | False | False | 1970-01-01 08:00 | | oceanbase.development-kit.el | remote | False | False | 1970-01-01 08:00 | ----------------------------------------------------------------------------- Use obd mirror list section name for more details Trace ID: 12ec66b6-8d72-11f1-aa39-000c29c9f372 If you want to view detailed obd logs, please run: obd display-trace 12ec66b6-8d72-11f1-aa39-000c29c9f3723.4 初始化相关软件目录obd 会通过 YAML 文件里提供的用户密码ssh 到每台机器初始化目录初始化完成后可以看到 /home/admin 下会生成 observer、obproxy 安装目录软连接/data/ 下面会生成 /data/1 数据目录/data/log1 日志目录。[rootoceanbase1 ~]# obd cluster deploy obcluster -c obcluster.yaml ------------------------------------------------------------------------------------------------ | Packages | --------------------------------------------------------------------------------------------- | Repository | Version/Tag | Release | Hash | --------------------------------------------------------------------------------------------- | oceanbase-ce | 4.5.0.0 | 100000012025112711.el7 | ea2a91329c00190d20c01dd73da81b2f081abd4e | | obproxy-ce | 4.3.5.0 | 3.el7 | f17b277b681adb1c86bfc3cfda369ad88896da9d | --------------------------------------------------------------------------------------------- Repository integrity check ok Load param plugin ok Open ssh connection ok Initializes observer work home ok Initializes obproxy work home ok Parameter check ok Remote oceanbase-ce-4.5.0.0-100000012025112711.el7-ea2a91329c00190d20c01dd73da81b2f081abd4e repository install ok Remote oceanbase-ce-4.5.0.0-100000012025112711.el7-ea2a91329c00190d20c01dd73da81b2f081abd4e repository lib check ok Remote obproxy-ce-4.3.5.0-3.el7-f17b277b681adb1c86bfc3cfda369ad88896da9d repository install ok Remote obproxy-ce-4.3.5.0-3.el7-f17b277b681adb1c86bfc3cfda369ad88896da9d repository lib check ok obcluster deployed Please execute obd cluster start obcluster to start Trace ID: 0f8e2918-8d73-11f1-8299-000c29c9f372 If you want to view detailed obd logs, please run: obd display-trace 0f8e2918-8d73-11f1-8299-000c29c9f372 #3.5 启动集群按照上面的提示执行 start 操作。[rootoceanbase1 ~]# obd cluster start obcluster Get local repositories ok Load cluster param plugin ok Open ssh connection ok [WARN] OBD-1007: (192.168.182.21) The recommended number of stack size is unlimited (Current value: 10240) [WARN] OBD-1007: (192.168.182.22) The recommended number of stack size is unlimited (Current value: 10240) [WARN] OBD-1007: (192.168.182.23) The recommended number of stack size is unlimited (Current value: 10240) [WARN] OBD-2000: (192.168.182.21) not enough memory. (Free: 3G, Need: 8G) [WARN] OBD-1012: (192.168.182.21) clog and data use the same disk (/) [WARN] OBD-1012: (192.168.182.22) clog and data use the same disk (/) [WARN] OBD-1012: (192.168.182.23) clog and data use the same disk (/) cluster scenario: htap Start observer ok observer program health check ok Connect to observer 192.168.182.21:2881 ok oceanbase bootstrap ok obshell start ok obshell program health check ok obshell bootstrap ok start obproxy ok obproxy program health check ok Connect to obproxy ok Connect to observer 192.168.182.21:2881 ok Wait for observer init ok -------------------------------------------------- | oceanbase-ce | ---------------------------------------------- | ip | version | port | zone | status | ---------------------------------------------- | 192.168.182.21 | 4.5.0.0 | 2881 | zone1 | ACTIVE | | 192.168.182.22 | 4.5.0.0 | 2881 | zone2 | ACTIVE | | 192.168.182.23 | 4.5.0.0 | 2881 | zone3 | ACTIVE | ---------------------------------------------- obclient -h192.168.182.21 -P2881 -urootsys -pOeJAl2GIe8t51BVe67mW -Doceanbase -A cluster unique id: a1f2042b-cd30-51f4-b291-562dd98a84db-19fbc12a830-00000504 obshell program health check ok display obshell dashboard ok --------------------------------------------------------------------- | obshell Dashboard | ------------------------------------------------------------------ | url | user | password | status | ------------------------------------------------------------------ | http://192.168.182.21:2886 | root | OeJAl2GIe8t51BVe67mW | active | ------------------------------------------------------------------ Connect to obproxy ok -------------------------------------------------------------------- | obproxy-ce | ---------------------------------------------------------------- | ip | port | prometheus_port | rpc_listen_port | status | ---------------------------------------------------------------- | 192.168.182.23 | 2883 | 2884 | 2885 | active | ---------------------------------------------------------------- obclient -h192.168.182.23 -P2883 -urootproxysys -ptmcxN1RGp0 -Doceanbase -A obcluster running Trace ID: 7d43a3c4-8d74-11f1-b66b-000c29c9f372 If you want to view detailed obd logs, please run: obd display-trace 7d43a3c4-8d74-11f1-b66b-000c29c9f372 [rootoceanbase1 ~]#3.6 登录集群# 根据上面的提示登录集群 端口是 2881 [rootoceanbase1 admin]# obclient -h192.168.182.21 -P2881 -urootsys -pOeJAl2GIe8t51BVe67mW -Doceanbase -A Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221516672 Server version: OceanBase_CE 4.5.0.0 (r100000012025112711-0e8d5ad012baf0953b2032a35a88bdf8886e9a7a) (Built Nov 27 2025 12:06:16) Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved. Type help; or \h for help. Type \c to clear the current input statement. obclient(rootsys)[oceanbase] SELECT * FROM oceanbase.DBA_OB_ZONES; -------------------------------------------------------------------------------------------------------------- | ZONE | CREATE_TIME | MODIFY_TIME | STATUS | IDC | REGION | TYPE | -------------------------------------------------------------------------------------------------------------- | zone1 | 2026-08-01 14:46:05.704904 | 2026-08-01 14:47:11.744709 | ACTIVE | default_idc | deault_region | ReadWrite | | zone2 | 2026-08-01 14:46:05.704904 | 2026-08-01 14:47:11.764566 | ACTIVE | default_idc | deault_region | ReadWrite | | zone3 | 2026-08-01 14:46:05.704904 | 2026-08-01 14:47:11.787405 | ACTIVE | default_idc | deault_region | ReadWrite | -------------------------------------------------------------------------------------------------------------- 3 rows in set (0.071 sec) # 登录 OBProxy 端口是 2883 obclient(rootproxysysproxysys)[oceanbase] Bye [rootoceanbase1 admin]# obclient -h192.168.182.23 -P2883 -urootproxysys -ptmcxN1RGp0 -Doceanbase -A Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 5 Server version: 5.6.25 Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved. Type help; or \h for help. Type \c to clear the current input statement. obclient(rootproxysysproxysys)[oceanbase] show proxysession; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | server_protocol | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | 0 | 5 | obcluster | proxysys | root | 192.168.182.21:61040 | NULL | 0 | 0 | MCS_ACTIVE_READER | 10363 | 10363 | 0 | MySQL | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 1 row in set (0.004 sec)3.7 登录 obshell DashBoard# 根据如上信息打开网址并登录 --------------------------------------------------------------------- | obshell Dashboard | ------------------------------------------------------------------ | url | user | password | status | ------------------------------------------------------------------ | http://192.168.182.21:2886 | root | OeJAl2GIe8t51BVe67mW | active | ------------------------------------------------------------------可以看到集群资源租户等信息。4. obd 常用命令4.1 查看与检查命令# 查看已部署的集群 [rootoceanbase1 ~]# obd cluster list ------------------------------------------------------------ | Cluster List | ---------------------------------------------------------- | Name | Configuration Path | Status (Cached) | ---------------------------------------------------------- | obcluster | /root/.obd/cluster/obcluster | running | ---------------------------------------------------------- Trace ID: bb49493c-8d77-11f1-9660-000c29c9f372 If you want to view detailed obd logs, please run: obd display-trace bb49493c-8d77-11f1-9660-000c29c9f372 #查看指定集群的**详细运行状态**、各组件Observer、OBProxy、OBAgent的 IP、端口和进程 ID [rootoceanbase1 ~]# obd cluster display obcluster Get local repositories and plugins ok Open ssh connection ok Connect to observer 192.168.182.21:2881 ok Wait for observer init ok -------------------------------------------------- | oceanbase-ce | ---------------------------------------------- | ip | version | port | zone | status | ---------------------------------------------- | 192.168.182.21 | 4.5.0.0 | 2881 | zone1 | ACTIVE | | 192.168.182.22 | 4.5.0.0 | 2881 | zone2 | ACTIVE | | 192.168.182.23 | 4.5.0.0 | 2881 | zone3 | ACTIVE | ---------------------------------------------- obclient -h192.168.182.21 -P2881 -urootsys -pOeJAl2GIe8t51BVe67mW -Doceanbase -A cluster unique id: a1f2042b-cd30-51f4-b291-562dd98a84db-19fbc12a830-00000504 obshell program health check ok display obshell dashboard ok --------------------------------------------------------------------- | obshell Dashboard | ------------------------------------------------------------------ | url | user | password | status | ------------------------------------------------------------------ | http://192.168.182.21:2886 | root | OeJAl2GIe8t51BVe67mW | active | ------------------------------------------------------------------ Connect to obproxy ok -------------------------------------------------------------------- | obproxy-ce | ---------------------------------------------------------------- | ip | port | prometheus_port | rpc_listen_port | status | ---------------------------------------------------------------- | 192.168.182.23 | 2883 | 2884 | 2885 | active | ---------------------------------------------------------------- obclient -h192.168.182.23 -P2883 -urootproxysys -ptmcxN1RGp0 -Doceanbase -A Trace ID: 1a8d12ca-8d78-11f1-8ec0-000c29c9f372 If you want to view detailed obd logs, please run: obd display-trace 1a8d12ca-8d78-11f1-8ec0-000c29c9f3724.2 集群控制命令# 启动整个集群的所有组件。 obd cluster start 集群名 # 停止整个集群的所有组件。 obd cluster stop 集群名 #重启整个集群 obd cluster restart 集群名 #在不重启进程的情况下在线重载修改后的配置文件适用于部分支持动态生效的参数 obd cluster reload 集群名如果 启动集群时出现如下报错[rootoceanbase1 ~]# obd cluster start obclusterGet local repositories okLoad cluster param plugin okOpen ssh connection ok[WARN] OBD-1007: (192.168.182.21) The recommended number of stack size is unlimited (Cur value: 10240)[WARN] OBD-1007: (192.168.182.22) The recommended number of stack size is unlimited (Cur value: 10240)[WARN] OBD-1007: (192.168.182.23) The recommended number of stack size is unlimited (Cur value: 10240)[ERROR] oceanbase-ce-py_script_resource_check-4.2.1.5 RuntimeError: cannot access local able server where it is not associated with a valueSee https://www.oceanbase.com/product/ob-deployer/error-codes .Trace ID: ebc2e8e8-8ed0-11f1-955b-000c29c9f372If you want to view detailed obd logs, please run: obd display-trace ebc2e8e8-8ed0-11f1--000c29c9f372在 其他两个节点执行一下 chronyc makestep 立刻解决时间不同步的问题。4.3 配置修改与资源调优# 在线编辑该集群的 YAML 配置文件需要配合以下命令生效 obd cluster edit-config 集群名 # 应用新的配置参数 obd cluster upgrade 集群名 -c 新配置文件这里是《实战派K8SDB》更多干货敬请关注公众号。如果本文对你有所帮助欢迎点赞、推荐和转发也欢迎关注后续文章一起考证、一起学习Oceanbase分布式数据库。
返回列表