OceanBase企业版单机部署:obd命令行方式

OceanBase企业版单机部署:obd命令行方式

本文介绍了如何通过命令行方式部署OceanBase企业版单机环境。

数据库版本:OceanBase V4.2.5

OceanBase企业版单机支持图形化部署和命令行部署:

  • 图形化部署:需要使用obd工具部署OCP平台,再通过OCP平台部署数据库。
  • 命令行部署:直接使用obd工具部署数据库。

安装包准备

🐘 单机版 V4.2.5支持通过以下统一的安装包部署:

部署方式 安装包名称
obd工具部署 oceanbase-standalone-all-in-one.tar.gz
OCP平台部署 oceanbase-ocp-standalone-all-in-one.tar.gz

服务器准备

最低资源配置

🐘 单机版 V4.2.5部署服务器应满足的最低配置如下:

组件 服务器数量 最低配置 推荐磁盘类型
OceanBase集群和obd 1台 4U8G SSD存储、推荐万兆网卡
OCP和MetaDB(图形化部署) 1台 16U32G SSD存储、推荐万兆网卡

⚠️ :命令行部署无需安装OCP和MetaDB组件。

是否部署ODP组件?

OceanBase数据库代理ODP(OceanBase Database Proxy,又称OBProxy)是OceanBase数据库专用的代理服务器,OceanBase数据库用户的数据会以多副本的形式存放在各个 OBServer节点上,ODP接收用户发出的SQL请求,并将SQL请求转发至最佳目标OBServer节点,最后将执行结果返回给用户。

🐘 单机版 V4.2.5部署无需部署ODP组件。

仲裁服务器

🐘 单机版 V4.2.5部署无需仲裁服务器。

服务器配置

操作系统

OceanBase数据库支持的主流操作系统及版本信息如下:

操作系统 版本 架构
KylinOS V10 x86_64(包括海光),ARM_64(鲲鹏、飞腾)
CentOS / Red Hat Enterprise Linux 7.x、8.x x86_64(包括海光),ARM_64(鲲鹏、飞腾)
Debian 8.3 及以上 x86_64(包括海光)
openEuler 20.03 LTS SP1/SP2 和 22.10 LTS x86_64(包括海光),ARM_64(鲲鹏、飞腾)

更多支持的操作系统及其版本请参考官方文档。

⭐️ 需要进行一些特殊的操作系统配置如下:

  1. 在Intel x86架构的环境中:建议修改配置文件/etc/sysctl.conf,添加配置vm.swappiness = 0
  2. 在AMD或者ARM架构的环境中,建议开启Numa
  3. 在ARM和海光架构的环境中,建议修改配置文件/etc/sysctl.conf,添加以下配置:
bash 复制代码
kernel.numa_balancing = 0
vm.zone_reclaim_mode = 0
vm.swappiness = 0

内核参数

OceanBase服务器推荐的内核参数配置如下:

内核参数 推荐值 说明
vm.max_map_count 655360 用于设置一个进程可拥有的最大内存映射区域数量
vm.min_free_kbytes 2097152 用于设置系统保留的最小空闲内存量,以防止内存碎片化。如果服务器物理内存小于等于8GB时,建议保持默认值,无需修改
vm.overcommit_memory 0 用于控制内存过量提交机制,指定当内存不足时是否允许过量提交内存
ulimit.open files hard/soft nofile 655300 用于设置用户可同时打开的最大文件描述符数
ulimit.max_user_processes hard/soft nproc 655300 用于设置用户可以创建的最大进程数
ulimit.core file size hard/soft core unlimited 用于设置核心转储文件(core dump)的最大大小
ulimit.stack hard/soft stack unlimited 用于设置系统的栈大小的参数
current_clocksource tsc 用于显示当前系统使用的时钟源

BIOS设置

BIOS需要关闭以下配置:

  • Cstate
  • Pstate
  • EIST
  • Power saving

BIOS需要开启以下配置:

  • Automatic Power on After Power Loss: Always on
  • Intel Virtualization Technology
  • Hyper-threading
  • Hardware prefetcher
  • VT-d
  • SR-IOV
  • Turbo Mode
  • Energy performance:开启最大performance

磁盘挂载

OCP节点的磁盘挂载要求如下:

挂载点 容量 格式 说明
/home 100 GB~300 GB 建议 ext4 或 xfs 各组件运行日志盘
/data/log1 内存大小的 3~4 倍 建议 ext4 或 xfs OCP元数据库日志盘
/data/1 取决于所需存储的数据大小 建议 ext4 或 xfs OCP元数据库数据盘
/docker 200 GB~500 GB 建议 ext4 或 xfs Docker根目录

:如果是通过命令行部署(oatcli或obd工具),可以不安装OCP和MetaDB组件。

OBServer节点的磁盘挂载要求如下:

挂载点 容量 格式 说明
/oceanbase 100 GB~300 GB 建议 ext4 或 xfs observer安装和运行日志盘
/obredo 内存大小的 3~4 倍 建议 ext4 或 xfs observer事务日志盘
/obdata 取决于所需存储的数据大小 建议 ext4 或 xfs observer数据盘

网卡设置

建议配置2块万兆网卡

  • bond模式取名bond0,绑定的模式可以选择mode1mode4,但建议选择mode4。对于mode4模式,交换机需要配置802.3ad协议。
  • 网卡名建议使用eth0eth1

obd部署前配置

  1. 检查操作系统和资源信息。
bash 复制代码
# 操作系统版本
cat /etc/os-release
cat /etc/redhat-release
nkvers

# 内核版本为 3.10.0 及以上
uname -r 

# 内存
free -g

# 磁盘
df -Th

# 网卡
ifconfig
  1. 配置时钟源。

通过OCP部署单机版、或者部署多节点集群,需要配置时钟源。

如果通过命令行方式部署单机版,则可以跳过时钟源配置。

  1. 配置内核参数。

在所有节点的/etc/sysctl.conf配置文件中添加以下内容:

复制代码
# for oceanbase
## 修改内核异步 I/O 限制
fs.aio-max-nr = 1048576

## 网络优化
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_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_slow_start_after_idle=0

vm.swappiness = 0
vm.min_free_kbytes = 2097152
vm.overcommit_memory = 0

fs.file-max = 6573688
fs.pipe-user-pages-soft = 0

# 修改进程可以拥有的虚拟内存区域数量
vm.max_map_count = 655360

# 此处为 OceanBase 数据库的 data 目录
kernel.core_pattern = /obdata/core-%e-%p-%t

最后通过sysctl -p命令使得配置修改生效。

  1. 配置用户资源限制。

在所有节点的/etc/security/limits.conf配置文件中添加以下内容:

复制代码
root soft nofile 655350
root hard nofile 655350
* soft nofile 655350
* hard nofile 655350
* soft stack unlimited
* hard stack unlimited
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited

检查/etc/security/limits.d/20-nproc.conf文件中是否存在nproc的配置,若存在需同步修改该文件中nproc的值。

  1. 关闭防火墙和SELinux。

关闭防火墙:

bash 复制代码
systemctl disable firewalld 
systemctl stop firewalld
systemctl status firewalld

关闭SELinux:

bash 复制代码
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
sestatus
  1. 磁盘规划。

OceanBase数据库的服务器依赖数据盘、事务日志盘和OceanBase数据库的安装盘。建议将数据分别挂载至三块磁盘。

  • OceanBase数据库安装盘的路径由配置参数home_path指定。
  • OceanBase数据库的运行日志位于${home_path}/log下。运行日志会不断增长,并且OceanBase数据库无法自动删除运行日志,因此需要定时删除运行日志。
  • 事务日志盘的路径由配置参数redo_dir指定。建议将事务日志盘的大小设置为OceanBase数据库内存的3倍到4倍及以上。
  • 数据盘用来存储基线数据,路径由配置参数data_dir指定。在首次启动OceanBase集群时,将自动创建${data_dir}/{sstable,slog}

示例(在obd部署时通过yaml文件配置):

复制代码
home_path: /oceanbase
redo_dir: /obredo
data_dir: /obdata
  1. 创建部署用户。

推荐使用obadmin用户部署OceanBase数据库。

创建obadmin用户:

bash 复制代码
groupadd obadmin
useradd -U obadmin -d /home/obadmin -s /bin/bash
chown -R obadmin:obadmin /home/obadmin
passwd obadmin

为obadmin用户添加sudo权限:

bash 复制代码
echo 'obadmin   ALL=(ALL)   NOPASSWD: ALL' >> /etc/sudoers

授予obadmin用户对数据库相关目录的权限:

bash 复制代码
chown -R obadmin:obadmin /oceanbase
chown -R obadmin:obadmin /obdata
chown -R obadmin:obadmin /obredo

obd部署单机版

  • ⭐️ 部署环境:CentOS Linux 7.9 x86_64
  • ⭐️ 安装包:oceanbase-standalone-all-in-one.tar.gz
  • ⭐️ 部署用户:obadmin用户(需要有sudo权限)

安装obd

解压安装包:

bash 复制代码
tar -xzf oceanbase-standalone-all-in-one.tar.gz

安装obd和OBClient:

bash 复制代码
cd standalone-all-in-one/
sudo bash bin/install_obd.sh

该脚本会安装obd和obclient,并将安装目录下rpms目录中的所有安装包复制到obd的本地镜像库中,同时关闭远程镜像库。执行成功后输出如下,需要复制并执行输出中的 source命令来应用环境配置。

bash 复制代码
Disable remote ok
Trace ID: 7bd73a1a-0e08-11f0-b275-00163e49899d
If you want to view detailed obd logs, please run: obd display-trace 7bd73a1a-0e08-11f0-b275-00163e49899d

add auto set env logic to profile: /root/.bash_profile

Execute this command to apply the environment config:` source ~/.oceanbase-all-in-one/bin/env.sh `

配置obd

  1. 创建yaml格式的配置文件obtest.yaml
yaml 复制代码
user:
  username: obadmin
  # password: ********
  key_file: /home/obadmin/.ssh/id_rsa
oceanbase-standalone:
  servers:
    - ip: 10.10.10.1
  global:
    cluster_id: 1
    # please set memory limit to a suitable value which is matching resource. 
    memory_limit: 64G # The maximum running memory for an observer
    system_memory: 30G # The reserved system memory. system_memory is reserved for general tenants.
    datafile_size: 192G # Size of the data file. 
    datafile_next: 200G
    datafile_maxsize: 1T
    log_disk_size: 192G # The size of disk space used by the clog files.
    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 obproxy's cluster_name
    appname: obtest
    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 working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
    home_path: /oceanbase
    # The directory for data storage. The default value is $home_path/store.
    data_dir: /obdata
    # The directory for clog. The default value is the same as the data_dir value.
    redo_dir: /obredo
    root_password: ****** # root user password, can be empty
    zone: zone1

📖 obd配置参数介绍:

  • username:OceanBase集群部署用户。部署前需要确保该用户已存在。
  • password:password和key_file均用于验证用户,通常只需要填写一个。
  • servers:每台机器都需要使用- ip:的格式指定。
  • memory_limit:observer进程能从环境中获取的最大内存,未配置的情况下以memory_limit_percentage配置项为准。默认值是0。
  • system_memory:保留的系统内存,该参数值会占用memory_limit的内存,未配置的情况下OceanBase数据库会自适应。默认值是0M。
  • datafile_size:指定对应节点数据文件(block_file)大小,未配置的情况下以datafile_disk_percentage配置项为准。默认值是0。
  • datafile_next:控制磁盘空间的增长步长,用于设置自动扩容。默认值是0。
  • datafile_maxsize:限制磁盘空间的最大可用上限,用于设置自动扩容。
  • log_disk_size:用于设置Redo日志磁盘的大小,未配置的情况下以log_disk_percentage配置项为准。默认值是0。
  • enable_syslog_wf:设置是否把WARN以上级别的系统日志打印到一个单独的日志文件中。默认值是true。
  • max_syslog_file_count:设置在回收日志文件之前可以容纳的日志文件数量。值为0时表示不自动清理。默认值是0。
  • appname:OceaBase集群名称,默认是obcluster
  • mysql_port:设置SQL服务协议端口号,默认为2881
  • rpc_port:设置远程访问的协议端口号,是observer进程跟其他节点进程之间的RPC通信端口,默认为2882。
  • obshell_port:设置OceanBase数据库运维端口,默认为2886。
  • home_path:OceanBase数据库安装路径,需确保部署用户拥有该目录的读写权限。
  • data_dir:设置存储SSTable 等数据的目录,需确保部署用户拥有该目录的读写权限。建议配置为独立的磁盘。默认为$home_path/store
  • redo_dir:clog事务日志的目录,默认与data_dir值相同,需确保部署用户拥有该目录的读写权限。建议配置为独立的磁盘。
  • root_password:OceanBase集群的超级管理员(root@sys)的密码,建议设置复杂的密码。
  1. 如果需要添加监控,增加下面的监控配置:
yaml 复制代码
obagent:
  depends:
    - oceanbase-standalone
  servers:
    - ip: 10.10.10.1
  global:
    home_path: /oceanbase/obagent
    monagent_http_port: 8088
    mgragent_http_port: 8089
prometheus:
  depends:
    - obagent
  servers:
    - 10.10.10.1
  global:
    # The working directory for prometheus. prometheus is started under this directory. This is a required field.
    home_path: /oceanbase/prometheus
    port: 9090
grafana:
  depends:
    - prometheus
  servers:
    - 10.10.10.1
  global:
    home_path: /oceanbase/grafana
    login_password: '********' # Grafana login password.
    port: 3000

注意obagentoceanbase-standalone保持相同的行前缩进。

📖 监控配置参数介绍

  • servers:每台机器都需要使用- ip:的格式指定。obagent组件下的servers配置需和oceanbase组件下保持一致。
  • home_path:组件的安装路径。
  • monagent_http_port:OBAgent监控服务端口。默认为8088。
  • mgragent_http_port:OBAgent管理服务端口。默认为8089。
  • prometheus.port:Prometheus监听端口。默认为9090。
  • grafana.port:访问Grafana要使用的http端口。默认为3000。
  • login_password:Grafana的登录密码。

部署OB集群

  1. 部署OceanBase集群(单节点)。
bash 复制代码
# obd cluster deploy <deploy_name> -c <yaml_path>
obd cluster deploy obtest -c obtest.yaml
  1. 启动OceanBase集群(单节点)。
bash 复制代码
# obd cluster start <deploy_name>
obd cluster start obtest

部署后检查

使用OBClient客户端连接数据库集群:

bash 复制代码
# obclient -h<IP> -P<PORT> -u<user_name>@<tenant_name> -p -c -A
obclient -h10.10.10.1 -P2881 -uroot@sys -p -c -A
  • -h:OBServer节点IP。
  • -u:连接用户。
  • -P:连接端口,对应mysql_port配置项。
  • -p:连接密码。
  • -c:表示在OBClient运行环境中不要忽略注释(不影响Hint)。
  • -A:表示在OBClient连接数据库时不自动获取统计信息。

检查集群:

bash 复制代码
# 查看集群列表
obd cluster list

# 查看集群状态
# obd cluster display <deploy_name>
obd cluster display obtest

环境清理与集群销毁

在清理旧的单机版环境之前,建议先进行数据备份。

  1. 查看单机版的状态。
bash 复制代码
obd cluster list
  1. 查看是否存在备租户。
bash 复制代码
# obd cluster tenant show <deploy_name> -g
obd cluster tenant show obtest -g
  1. 主备租户解耦(可选)。

若单机版中的租户存在备租户,销毁单机版时会报错,此时可以选择为主备租户解耦,也可以选择强制执行销毁命令,单机版销毁后备租户将无法使用。

执行如下命令查看备租户的主备关系:

bash 复制代码
obd cluster tenant show clusterC -g

# 假设输出如下
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                     tenant base info                                                                                    |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
| tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
| sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
| C_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | STANDBY     |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                   standby tenant standby info                                                                   |
+---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
| standby_tenant_name | tenant_status | sync_status | sync_scn_timestamp         | err_code | error_comment | switchover_status | switchover_epoch | log_mode     |
+---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
| C_a                 | NORMAL        | NORMAL      | 2023-09-14 09:39:32.423752 | 0        |               | NORMAL            | 0                | NOARCHIVELOG |
+---------------------+---------------+-------------+----------------------------+----------+---------------+-------------------+------------------+--------------+
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                         standby tenant`s primary info                                                                             |
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| standby_tenant_name | primary_tenant_info                                                                                                                                                         |
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| C_a                 | IP_LIST=10.10.10.1:3881;10.10.10.2:3881;10.10.10.3:3881,USER=standbyro@B_a,PASSWORD=******,TENANT_ID=1002,CLUSTER_ID=1694681525,COMPATIBILITY_MODE=MYSQL,IS_ENCRYPTED=false |
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
query primary-standby relation ok

primary-standby relation topology graph

clusterA:A_a
└── clusterB:B_a
    └── clusterC:C_a

为备租户C_a执行解耦:

bash 复制代码
obd cluster tenant decouple clusterC C_a --tenant-root-password=******

执行Decouple操作后,对应的备租户会和主租户解耦,备租户角色会变换为PRIMARY。

再次查看原备租户的主备关系:

bash 复制代码
obd cluster tenant show clusterC -g

# C_a 租户的tenant_role变为PRIMARY
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                     tenant base info                                                                                    |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
| tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops            | min_iops            | log_disk_size | iops_weight | tenant_role |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
| sys         | SYS         | MYSQL              | RANDOM       | 1.0     | 1.0     | 2.0G        | 9223372036854775807 | 9223372036854775807 | 2.0G          | 1           | PRIMARY     |
| C_a         | USER        | MYSQL              | RANDOM       | 2.0     | 2.0     | 4.0G        | 10000               | 10000               | 5.0G          | 2           | PRIMARY     |
+-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+
query primary-standby relation ok
  1. 销毁单机版数据库。

destroy命令不可逆,会在停止OBServer进程的同时清除数据库文件。因此执行以下命令前,请先确认单机版已经不再使用,并且需要备份的数据已经完成备份。

bash 复制代码
# obd cluster destroy <deploy_name> -f [--igs]
obd cluster destroy obtest -f [--igs]
  • -f:表示检查到工作目录下有运行中的进程时,会强制停止进程,销毁单机版。
  • --igs:表示检查到单机版中租户在其他单机版中存在备租户时,强制执行obd cluster destroy命令。
相关推荐
Gadus_1 小时前
MySQL:InnoDB
数据库·mysql
孙同学_4 小时前
【MySQL】001.MySQL安装
数据库·mysql·adb
不剪发的Tony老师6 小时前
SQLite + Redis = Redka
数据库·redis·sqlite
樽酒ﻬق7 小时前
PostgreSQL、MariaDB和MySQL的异同及应用:企业级数据库选型指南
数据库·postgresql·mariadb
chat2tomorrow8 小时前
SQL2API是什么?SQL2API与BI为何对数据仓库至关重要?
数据库·数据仓库·低代码·bi·数据中台·sql2api
せいしゅん青春之我9 小时前
【MYSQL从入门到精通】数据库基础操作、数据类型
数据库·mysql
Miketutu9 小时前
Mysql -- 基础
数据库
Mcband9 小时前
MySQL 用 limit 影响性能的优化方案
数据库·mysql
✿ ༺ ོIT技术༻11 小时前
MySQL:事务的理解
数据库·mysql
DragonnAi12 小时前
猫咪如厕检测与分类识别系统系列【五】信息存储数据库改进+添加猫咪页面制作+猫咪躯体匹配算法架构更新
数据库·算法·分类