实践:OBD部署源码编译OceanBase社区版本

2024年 5月 7日 86.1k 0

本文主要描述了

1. 单机环境下如何用OBD 源码编译部署。

2. OBD一键压测优化。

3. 安装部署过程遇到问题。

注意:该方法不使用生产上的版本升级问题 【没有验证】

如果是作为开发变更代码,OBD 定制组件方式部署后 【验证没有问题】

  然后make install /cp observer进程方式 ,然后obd直接重启集群。

obd 升级部署 obd mirror update 和直接make install /cp observer 有什么区别,

有清楚麻烦留言告知告知。

一、前言

之前公司分配服务器被回收,没有足够资源部署。结合 OceanBase 数据库社区版部署概述快速体验 OceanBase 数据库这2篇文章,本次进行了编译部署实践。

本次采用 mac, Docker 镜像, obd 方式源码 ,部署进行单机部署,体验OceanBase 4.1。并没使用“方案三:部署 OceanBase 容器环境”,主要原因就是Docker 镜像当作一个centos系统来使用,为后续开发作准备。

另外,用sysbench做了简单的测试MySQL、OceanBase 、TiDB 在体系架构上的差别非常大,很多方面都很难找到一个共同的基准点,尤其是单机情况下,所以大家不要消耗过多精力在这类基准测试上,应该更多关注在应用程序使用场景上的区别。

Docker资源设置 :

实践:OBD部署源码编译OceanBase社区版本-1

满足最低要求

实践:OBD部署源码编译OceanBase社区版本-2

二、使用源码构建 OceanBase 数据库

2.1 编译

//参考:https://www.oceanbase.com/docs/community-observer-cn-0000000000160092
cat /etc/*-release
CentOS Linux release 7.9.2009 (Core)

git clone git@github.com:watchpoints/oceanbase.git
# 进入代码根目录
cd oceanbase/
# DEBUG 构建
bash build.sh debug --init --make -j4  //稍微等待
cd build_debug/src/observerbuild_debug/src/observer

查看编译后版本:OceanBase_CE 4.2.0.

## 环境变量
make install  # 默认安装到/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

## 查看版本
[root@3346da816048 observer]# observer --version
observer --version
observer (OceanBase_CE 4.2.0.0)

## 必须设置环境变量设置环境变量 不然出现libaio.so错误。
ldd ~/oceanbase/build_debug/src/observer/observer              
            linux-vdso.so.1 =>  (0x00007ffc6ef37000)
            librt.so.1 => /lib64/librt.so.1 (0x00007fbe2d1bf000)
            libdl.so.2 => /lib64/libdl.so.2 (0x00007fbe2cfbb000)
            libm.so.6 => /lib64/libm.so.6 (0x00007fbe2ccb9000)
            libaio.so.1 => not found
            libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbe2ca9d000)
            libc.so.6 => /lib64/libc.so.6 (0x00007fbe2c6cf000)
            /lib64/ld-linux-x86-64.so.2 (0x00007fbe6c361000

2.2 下载 OBD

下载安装oceanbase-all-in-one ,主要获取obd(也可以直接安装obd)

bash -c "$(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/oceanbase-all-in-one/installer.sh)"
Install Finished 
=====================================================================
Setup Environment:     source ~/.oceanbase-all-in-one/bin/env.sh 
Start Web Service:     obd web 
Quick Start:           obd demo 
More Details:          obd -h 
=====================================================================
which obd
/root/.oceanbase-all-in-one/obd/usr/bin/obd
obd --version
OceanBase Deploy: 2.0.1

obd工具说明

  • obd 安装使用目录
cd ~/obd 
ls 
cluster obd 集群部署目录
mirror 
remote和local 2个目录
optimize 集成测试自动调优
plugins 
相关阅读:
分析obd日志了解其部署集群过程
https://zhuanlan.zhihu.com/p/464512232

  • https://gitee.com/oceanbase/obdeploy目录结构

├── config_parser 配置解析器

├── docs 文档

├── example 样例

├── optimize 集成测试自动调优

├── plugins 业务插件

├── profile 命令行自动补齐

├── rpm RPM打包配置

├── service 白屏后端

└── web 白屏前端

  • 关键文件

├── _cmd.py 命令层入口

├── core.py 核心编排

├── _deploy.py 配置管理

├── _environ.py 环境变量管理

├── _mirror.py 远程镜像仓库管理

├── _optimize.py 自动调优管理

├── _plugin.py 插件管理

├── _repository.py 仓库管理

├── ssh.py SSH客户端

└── _stdio.py 命令行IO

2.3 制作本地镜像

参考:https://gitee.com/oceanbase/obdeploy
# 离线安装部署,禁用远程仓库(之前版本obd默认下载远程,不是本地)
obd mirror disable remote

[root@3346da816048 ~]# obd mirror disable remote
Disable remote ok

#obd mirror create
使用该命令可以以本地目录为基础创建一个镜像。
此命令主要用于使用 OBD 启动自行编译的 OceanBase 开源软件,
您可以通过此命令将编译产物加入本地仓库

make DESTDIR=./ install && 
obd mirror create -n oceanbase-ce -V 4.2.0.0 -p /usr/local -t my-oceanbase
package ok
name: oceanbase-ce
version: 4.2.0.0  // observer --version 查询最新版本号
release:20230514112232
arch: x86_64
md5: 630917f3350b447488c3fdce9c7967d5 

# 细心你发现 -p /usr/local 和文档上有区别

# 记住这个hash值或者 my-oceanbase名字

2.4 配置文件启动

mini-local-example.yaml

https://github.com/oceanbase/obdeploy/blob/master/example/mini-local-example.yaml
ceanbase-ce:
  package_hash:630917f3350b447488c3fdce9c7967d5
  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: /root/observer //修改自己存储路径
    # The directory for data storage. The default value is $home_path/store.
    data_dir: /data/observer/data //修改自己存储路径
    # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
    redo_dir: /root/observer/redo //修改自己存储路径
     # please set memory limit to a suitable value which is matching resource. 
    memory_limit: 4G # The maximum running memory for an observer //observer进程占用内存,设置设置4G,因为新增租户增加到5G,在后续压测中还是内存提示租户内存不足,建议为至少6G。
    system_memory: 1G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
.
    cpu_count: 16
    production_mode: false //这个参数一定设置为fasel,代表非生产环境。
      
//启动 
obd cluster deploy watchpoints -c ./mini-local-example.yaml
//修改配置:如果后续配置发现变动,不是修改mini-local-example.yaml配置文件。
obd cluster edit-config  watchpoints 
obd cluster redeploy watchpoints  
obd cluster start watchpoints
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.2.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
    
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A

这里提出一个疑问:每次代码变动怎么办?正在看文章的你也可以想想

如何升级部署自己通过源码编译的observer(v3.1.2)到已运行的observer集群?我之前采用tag 声明后,make install 或者cp是 observer进程可以的,但是通过 obd mirror update 并没有尝试,这方面不清楚。

  • Q: 如何指定使用特定版本的组件?

A: 在部署配置文件中使用 package_hash 或 tag 声明。 如果您给自己编译的 OceanBase-CE 设置了 tag,您可以使用 tag 来指定。如:

oceanbase-ce:

tag: my-oceanbase

你也可以通过 package_hash 来指定特定的版本。当您使用 obd mirror 相关命令时会打印出组件的 md5值,这个值即为 package_hash。

oceanbase-ce:

package_hash: 929df53459404d9b0c1f945e7e23ea4b89972069

三. OceanBase性能测试:

采用Sysbench进行测试,利用obd 插件提供参数优化。

在OceanBase 入门到实战教程 实践练习六(必选):查看 OceanBase 执行计划 介绍三个测试工具

OLTP

  • TPC-C(Transaction Processing Performance Council)是针对 OLTP 的基准测试模型
  • Sysbench 是一个基于 LuaJIT 的可编写脚本的多线程基准测试工具,可以用于数据库性能(OLTP 基准测试)

OLAP

  • TPC-H可以说是世界上最为流行的OLAP workload的benchmark程序,是评估OLAP数据库最常见的工具

这里采用Sysbench

3.1 创建普通测试租户

obclient -uroot@sys -h127.0.0.1 -P2881 oceanbase  # 这里没有obproxy,因此端口不是2883

#1. 修改最新规格为1G (可选)
在分配资源池时,普通租户的内存的最小规格由隐藏配置项 __min_full_resource_pool_memory 控制,默认值为 5G,社区版本默认2g

alter system __min_full_resource_pool_memory=1073741824;
SELECT * FROM oceanbase.__all_virtual_sys_parameter_stat WHERE name='__min_full_resource_pool_memory'\G;

#2. 创建资源单元(1c/1g/2G):UNIT=sysbench_unit_1c1g
 CREATE RESOURCE UNIT sysbench_unit_1c1g MAX_CPU 1, MEMORY_SIZE '1g',LOG_DISK_SIZE '2G';

#3. 查看新创建的资源单元:sysbench_unit_1c1g
SELECT * FROM __all_unit_config where name='sysbench_unit_1c1g' \G;
unit_config_id: 1006
          name: sysbench_unit_1c1g
       max_cpu: 1
       min_cpu: 1
   memory_size: 1073741824
 log_disk_size: 2147483648
      max_iops: 10000
      min_iops: 10000
   iops_weight: 1

#4. 创建资源池:POOL=sysbench_pool
create resource pool sysbench_pool unit = 'sysbench_unit_1c1g', unit_num = 1;
# 查看资源池
SELECT * FROM __all_resource_pool \G;
*************************** 2. row ***************************
        gmt_create: 2023-05-20 14:59:15.650372
      gmt_modified: 2023-05-20 14:59:15.650372
  resource_pool_id: 1007
              name: sysbench_pool
        unit_count: 1
    unit_config_id: 1006
         zone_list: zone1
         tenant_id: -1
      replica_type: 0
is_tenant_sys_pool: 0


# 5 创建租户:tenant=tpctest
drop TENANT tpctest;
CREATE TENANT tpctest resource_pool_list=('sysbench_pool') set variables ob_compatibility_mode='mysql', ob_tcp_invited_nodes='%';
# 查看创建成功的租户
select tenant_id,tenant_name,primary_zone from __all_tenant;

## 创建数据库
obclient -uroot@tpctest -h127.0.0.1 -P2881
create database sysbench_test;

遇到错误1

现象:创建内存不足导致创建租户失败

ERROR 4733 (HY000): zone 'zone1' resource not enough to hold 1 unit. You can check resource info by views: DBA_OB_UNITS, GV$OB_UNITS, GV$OB_SERVERS.
server '"127.0.0.1:2882"' MEMORY resource not enough

尝试解决的: 默认普通租户的内存的最小规2G改为1G
在分配资源池时,普通租户的内存的最小规格由隐藏配置项 __min_full_resource_pool_memory 控制,默认值为 5G,社区版本默认2g

alter system __min_full_resource_pool_memory=1073741824;
SELECT * FROM oceanbase.__all_virtual_sys_parameter_stat WHERE name='__min_full_resource_pool_memory'\G;

查询资料 https://gw.alipayobjects.com/os/bmw-prod/5b8f5011-e3ae-441d-ba0e-e8fea1e90508.pdf

实践:OBD部署源码编译OceanBase社区版本-3

实践:OBD部署源码编译OceanBase社区版本-4

memory_limit 参数可用于调整 OceanBase 数据库的最大可使用内存数

system_memory 参数用于配置租户 ID 为 500 的租户的内存,即程序运行内存。

需要增加memory_limit大小。

解决方法是增加 observer内存上限5g

obd cluster edit-config watchpoints
memory_limit 改为5g
obd cluster reload watchpoints

3.2 Sysbench 测试

  • 通过 OBD test 命令一键进行 Sysbench 测试。
  • ./ob_sysbench.sh
 yum install ob-sysbench
./ob_sysbench.sh
#!/bin/bash
export ENABLE_PROTOCOL_OB20=0
echo "run oltp_read_only test"
obd test sysbench watchpoints --tenant=tpctest --script-name=oltp_read_only.lua --table-size=1000 --threads=1 --rand-type=uniform
echo "run oltp_write_only test"
obd test sysbench watchpoints  --tenant=tpctest --script-name=oltp_write_only.lua --table-size=1000 --threads=1 --rand-type=uniform
echo "run oltp_read_write test"
obd test sysbench watchpoints --tenant=tpctest --script-name=oltp_read_write.lua --table-size=1000 --threads=1--rand-type=uniform

遇到错误2

  • obclient [oceanbase]> alter system set _trace_control_info='%s' tenant='tpctest';

ERROR 4179 (HY000): alter the parameter _trace_control_info not allowed

  • https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001697458

实践:OBD部署源码编译OceanBase社区版本-5

  • 如何关闭改参数优化

https://github.com/oceanbase/obdeploy/blob/master/optimize/oceanbase/4.1.0/sysbench.yaml

 /root/.obd/optimize/oceanbase-ce/4.1.0/sysbench.yaml 去掉 _trace_control_info参数。

3.3 测试结果

下面测试结果:是mac docker 4C8G,1千个记录,租户1c1g,1个线程。

目的学习使用,不作为性能对比参考依据。请看官方测试报告

https://www.oceanbase.com/docs/common-oceanbase-database-cn-0000000001954653

# run oltp_read_only test
 10s ] thds:  1 tps: 47.09 qps: 754.89 (r/w/o: 660.60/0.00/94.29) lat (ms,95%): 46.63 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 61.90 qps: 989.33 (r/w/o: 865.53/0.00/123.80) lat (ms,95%): 38.25 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 79.09 qps: 1265.72 (r/w/o: 1107.53/0.00/158.19) lat (ms,95%): 24.83 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 1 tps: 77.40 qps: 1238.17 (r/w/o: 1083.36/0.00/154.81) lat (ms,95%): 24.38 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 1 tps: 75.20 qps: 1203.97 (r/w/o: 1053.58/0.00/150.40) lat (ms,95%): 22.28 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 1 tps: 78.40 qps: 1254.53 (r/w/o: 1097.73/0.00/156.80) lat (ms,95%): 20.37 err/s: 0.00 reconn/s: 0.00
SQL statistics:
# run oltp_write_only test
[ 10s ] thds: 1 tps: 121.18 qps: 727.59 (r/w/o: 0.00/485.13/242.46) lat (ms,95%): 17.95 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 180.70 qps: 1084.11 (r/w/o: 0.00/722.71/361.40) lat (ms,95%): 8.90 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 179.20 qps: 1075.00 (r/w/o: 0.00/716.60/358.40) lat (ms,95%): 8.58 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 1 tps: 167.80 qps: 1006.72 (r/w/o: 0.00/671.11/335.61) lat (ms,95%): 9.56 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 1 tps: 167.50 qps: 1004.99 (r/w/o: 0.00/669.99/335.00) lat (ms,95%): 8.90 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 1 tps: 147.10 qps: 882.98 (r/w/o: 0.00/588.78/294.19) lat (ms,95%): 10.65 err/s: 0.00 reconn/s: 0.0

# run oltp_read_write test
Threads started!
[ 10s ] thds: 1 tps: 16.70 qps: 334.75 (r/w/o: 234.47/66.79/33.50) lat (ms,95%): 87.56 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 22.90 qps: 458.40 (r/w/o: 321.00/91.60/45.80) lat (ms,95%): 64.47 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 23.50 qps: 468.91 (r/w/o: 327.91/94.00/47.00) lat (ms,95%): 66.84 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 1 tps: 23.40 qps: 468.49 (r/w/o: 328.09/93.60/46.80) lat (ms,95%): 64.47 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 1 tps: 23.80 qps: 476.91 (r/w/o: 334.11/95.20/47.60) lat (ms,95%): 63.32 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 1 tps: 22.60 qps: 451.97 (r/w/o: 316.38/90.39/45.20) lat (ms,95%): 65.65 err/s: 0.00 reconn/s: 0.00

四、其他测试

OB(分布式),TiDB 与 MySQL (偏向单机)在体系架构上的差别非常大,很多方面都很难找到一个共同的基准点,所以大家不要消耗过多精力在这类基准测试上,应该更多关注 在应用程序使用场景上的区别.

4.1 TIDB

  • window+虚拟机 环境部署

实践:OBD部署源码编译OceanBase社区版本-6

实践:OBD部署源码编译OceanBase社区版本-7

手动进行Sysbench 测试

# Building and Installing From Source
https://github.com/akopytov/sysbench#rhelcentos
./configure --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/lib64/mysql/ --with-mysql
# 压测时用到的 lua 脚本
/usr/local/share/sysbench/
# 测试类型 
oltp_read_only
oltp_write_only
oltp_read_write

# 准备配置文件:config
mysql-host=127.0.0.1
mysql-port=4000
mysql-user=root
mysql-password=BW07-+5vE36q@b*9RA
mysql-db=sbtest
db-driver=mysql
# 开始导入数据,config 文件为上一步中配置的文件 1w记录
sysbench --config-file=config oltp_point_select --tables=5 --table-size=10000 prepare

# 数据预热与统计信息收集
sysbench --config-file=config oltp_point_select --tables=5 --table-size=10000 prewarm

Read-only 测试命令

sysbench --config-file=config oltp_read_only --tables=5 --table-size=10000  --db-ps-mode=auto  --report-interval=10 --threads=1 --rand-type=uniform run

实践:OBD部署源码编译OceanBase社区版本-8

Write-only 测试命令

sysbench --config-file=config oltp_write_only --tables=5 --table-size=10000 --db-ps-mode=auto --report-interval=10 --rand-type=uniform run

实践:OBD部署源码编译OceanBase社区版本-9

混合 测试命令

sysbench --config-file=config oltp_read_write --tables=5 --table-size=10000 --db-ps-mode=auto --report-interval=10 --rand-type=uniform run

实践:OBD部署源码编译OceanBase社区版本-10

4.2 Mysql

  • mysql 版本
# 查找以前是否装有MySQL
rpm -qi mysql-server
Name        : mysql-server
Version     : 8.0.26
# 启动:
service mysqld start
# 默认空密码
mysql -uroot 

mysql-host=127.0.0.1
mysql-port=3306
mysql-user=root
mysql-db=sbtest
db-driver=mysql

用上面方式同样测试

只读1个单线程

sysbench --config-file=config oltp_read_only --tables=5 --table-size=10000 --db-ps-mode=auto -- report-interval=10 --threads=1 --rand-type=uniform run

实践:OBD部署源码编译OceanBase社区版本-11

只读10个单线程

实践:OBD部署源码编译OceanBase社区版本-12

Write-only 测试命令

1个线程:

sysbench --config-file=config oltp_write_only --tables=5 --table-size=10000 --db-ps-mode=auto --report-interval=10 --threads=1 --rand-type=uniform run

实践:OBD部署源码编译OceanBase社区版本-13

10个线程:

实践:OBD部署源码编译OceanBase社区版本-14

五、总结

1. 单机环境下 源码源码后,OBD如何部署替换参见https://gitee.com/oceanbase/obdeploy

2. OBD 插件机制 提供压测前优化:https://gitee.com/oceanbase/obdeploy/blob/master/plugins/sysbench/4.0.0.0/run_test.py

3. 如何调整observer进程最大占用内存和关闭全链路检测参数: https://gitee.com/oceanbase/obdeploy/blob/master/optimize/oceanbase/4.0.0.0/sysbench.yaml

4. 通过虚拟机单机测试发现  MySQL、OceanBase、TiDB 架构是有区别的,由于篇幅问题,下一篇文章继续介绍,敬请期待。

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论