Longda's Interesting World

分布式数据库与 AI Agent 工程实践

OceanBase-4.2.x 体验记录(1)

总结

2023年11月16号, ob 发布了年度发布会, 正式对外公布了4.2.1 LTS 版本, 从4.2.1 开始, 4.2.x 将会是一个 Long Time Support 版本, 后续持续发版4.2.2, 4.2.3, 4.2.4, 4.2.5 等等, 对用户会非常友好, 用户的系统未来升级, 可以滚动升级, 不用担心应用层做改造升级, 数据也可以本地升级, 甚至平滑升级不断服务, 更为关键的是, 后续用户都会迁移到4.2.x 上, 随着用户的增多, 稳定性也会不断强化.

内核版本, 基本稳定后, 工具体系比如obd, ocp, oms 框架和流程方面页基本稳定下来, 做一次全面的测试, 找出一些易用性上面的问题, 帮助后续用户能够更方便的接入.

测试大纲

  1. obd 的安装部署
  2. obd 巡检优化
  3. tpcc 测试
  4. sysbench 测试
  5. tpch 测试
  6. obdiag 日志收集
  7. 基于obd, 单节点 扩容成集群模式
  8. 基于obd, 集群垂直扩容 (单副本内增加机器)
  9. 基于obd, 集群水平扩容(增加副本)
  10. 基于obd, 集群水平缩容(减少副本)
  11. 基于obd, 集群垂直缩容 (单副本内减少机器)
  12. failover test, when running sysbench, restart one server.
  13. ocp 安装部署
  14. ocp 接管 obd 部署集群
  15. ocp 安装ob 集群 (单节点主备库模式)
  16. 基于obd, 单节点 扩容成集群模式
  17. 基于obd, 主集群垂直扩容 (单副本内增加机器)
  18. 基于obd, 主集群水平扩容(增加副本)
  19. 基于obd, 主集群水平缩容(减少副本)
  20. 基于obd, 主集群垂直缩容 (单副本内减少机器)
  21. 基于nfs, 主集群备份, 备集群恢复
  22. 基于nfs, 备集群备份, switchover 后, 原主集群进行恢复
  23. oms 的安装部署
  24. tpch 数据同步至mysql
  25. binlog service 安装
  26. 基于sysbench 测试下, binlog service 配置同步至MySQL

软件版本

内核版本: 4.2.1_CE_BP1_HF1
OBD版本: 2.4.0
OCP版本: 4.2.1
OMS版本: 4.2.0
obdiag诊断工具: 1.4.0
OBLogProxy(binlog service): v2.0.0

硬件配置

运行observer 的机器配置(因为仅仅做功能测试, 机器硬件配置并没有选择更高配置)
aliyun ecs:
4c/32g amd 机型
磁盘3块

部署模式

在本例采用经典的三幅本部署模式, 使用4台机器:

  • 1台机器 部署 OBProxy – 推荐客户端应用和OBProxy 部署一起, 减少第一次网络时延.
  • 1-1-1 部署3副本OceanBase 集群, 每个zone 表示一个副本, 在本例中, 一个zone 只包含一台机器. 3个zone 可以生产环境中常常部署两地三中心模式, 三个机房三个副本, 每个机房一个副本, 其中两个机房距离较近.

软硬件要求

项目 描述
系统 Red Hat Enterprise Linux Server 7.x 版本(内核 Linux 3.10.0 版本及以上)
CentOS Linux 7.x 版本(内核 Linux 3.10.0 版本及以上)
Anolis OS 8.x 版本(内核 Linux 3.10.0 版本及以上)
CPU 企业级用户最低要求16核, 推荐32核及以上
个人测试最低要求2核, 推荐8核及以上
内存 企业级应用最低要求64G, 推荐256G 及以上
个人测试最低要求8G, 推荐64G 及以上
磁盘类型 推荐SSD
磁盘空间 内存大小的4倍及以上
文件系统 ext4或xfs, 当数据量超过16TB时, 使用xfs
网卡 千兆互联及以上

设置无密码SSH 登录

在安装前, 需要对每台机器的环境进行设置, 这些设置都需在超级管理员下操作, 建议打通 主控机器 到OBServer 和OBProxy 机器的信任登陆(即无密码登录), 如何设置无密码SSH 登录, 详情参考 https://open.oceanbase.com/docs/community/oceanbase-database/V3.1.0/optional-set-password-free-ssh-logon

推荐2个脚本, 方便在集群中批量执行命令和拷贝文件
批量拷贝文件, 可以将host list 换成自己实际机器列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#/usr/bin/bash


hosts=(
"ob001"
"ob002"
"ob003"
"obdriver"
)
for host in "${hosts[@]}"
do

echo "begin to scp " $@ " on " $host
scp -r $1 $host:$2
done

批量执行命令, 可以将host list 换成自己实际的机器列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/usr/bin/bash



hosts=(
"ob001"
"ob002"
"ob003"
"obdriver"
)
for host in "${hosts[@]}"
do
echo "begin to run " $@ " on " $host
ssh $host $@
done

创建使用用户

对于个人测试用户, 可以直接使用root 账号, 对于企业用户, 推荐创新普通用户, 避免对系统照成安全冲击. 在本例中, 使用admin 作为示范, 企业用户可以根据自己需要, 使用自己常用的账户

1
2
3
useradd -U admin -d /home/admin -s /bin/bash
mkdir -p /home/admin
sudo chown -R admin:admin /home/admin

设置密码

1
passwd admin

设置sudo 权限
vi /etc/sudoers #添加oceanbase一行内容

1
2
3
4

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
admin ALL=(ALL) NOPASSWD: ALL

磁盘规划

OceanBase 数据库服务器依赖3个目录, 当个人测试使用时, 可以将所有数据放到1块盘下, 但在企业级用户中, 必须分别挂载3块磁盘: 数据盘, 事务日志盘, OBServer 安装盘. 当机器上没有3块盘时或者使用RAID 磁盘阵列时, 需要对磁盘或者磁盘阵列的逻辑卷进行分区, 分3块分区, 分区大小参考下面说明:

  • 数据盘

    • 配置参数为data_dir. 要根据业务需要,做好数据盘的规划. 数据盘承载了基线数据,物理上只有一个基线数据文件 block_file,在安装目录 store/sstable 下。通过 OBServer 进程启动时一 次性创建,大小根据启动参数 datafile_disk_percentage 采用磁盘预分 配策略,默认值为 95%,创建后无法调整大小。OceanBase 的扩容缩 容采用加减机器的策略,目前不支持单机的磁盘级扩容和缩容。
  • 事务日志盘

    • 配置参数为redo_dir. 推荐大小为OBServer 内存3到4倍或以上. 事务日志盘包含多个固定大小的小文件,位于安装目录 store/{clog,ilog,slog},按需自动创建和清除,磁盘写到 80%会触发自 清除逻辑,但前提是这部分日志数据对应的内存数据已经通过合并融 合到了基线数据中,才能被删除。同等数据量, 事务日志的大小约为内存数据大小的三倍。所以事务日志盘所需空间 上限与两次合并操作间的业务数据总量成正比,经验公式是:事务日 志文件大小 = 增量数据内存上限的 3 到 4 倍。
  • OBServer 安装盘

    • 配置参数home_path. 推荐200G 或以上(保存7天或以上的日志量). OceanBase 的 rpm 包安装目录在/home/admin/oceanbase 下,其中 基线数据文件和事务日志文件会通过软连接指向上述的两个独立磁 盘,还有另外一个不断增长的文件是 OB 运行日志,在安装目录 log 下。OB 进程本身无法自删除运行日志,需要定时任务或运维脚本完 成删除逻辑。

      磁盘划分后, 可以通过df -h 命令检查, 结果如下:


在本示例中: /data 为数据磁盘, 大小1TB, /redo 存放 redo 日志, /home/admin/oceanbase 存放oceanbase binary 和运行日志

检查目录权限

1
2
3
4
5
6
7
8
ls –al #执行该命令
drwxr-xr-x 2 admin admin 4096 2 月 9 18:43
drwxr-xr-x 2 admin admin 4096 2 月 9 18:43 log1

若 admin 用户无权限,则以 root 用户执行如下命令
chown -R admin:admin /data
chown -R admin:admin /redo
chown -R admin:admin /home/admin

预检查

企业级用户建议运行OBServer 所有机器硬件配置和软件配置(操作系统, 操作系统内核, glibc, python 等软件包) 一致, OBProxy 机器和OBServer 机器软件配置一致(操作系统, 操作系统内核, glibc, python等软件包).

检查操作系统

当前支持的操作系统为:

Red Hat Enterprise Linux Server 7.x 版本(内核 Linux 3.10.0 版本及以上)
CentOS Linux 7.x 版本(内核 Linux 3.10.0 版本及以上)

  1. 以root 用户登录服务器
  2. 查看os 版本

RedHat7 系统显示如下

1
2
[root@redhat-04 /root]#cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)

CentOS7 系统显示如下:

1
2
[root@centos-01 /root]#cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

在anolis 系统上:

1
2
3
4
5
6
7
8
9
10
[root@anolis ~]# cat /etc/os-release
NAME="Anolis OS"
VERSION="8.2"
ID="anolis"
ID_LIKE="rhel fedora centos"
VERSION_ID="8.2"
PLATFORM_ID="platform:an8"
PRETTY_NAME="Anolis OS 8.2"
ANSI_COLOR="0;31"
HOME_URL="https://openanolis.org/"

其他系统, 如Debian9 系统显示如下:

1
2
3
4
5
6
7
8
9
10
root@ob001:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

在unbutu 系统上:

1
2
3
4
5
6
7
8
9
10
11
12
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

对于一些系统, 如Ubuntu/Debian, 需要安装yum:

1
2
3
4
5
6
7
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install yum -y
sudo apt install yum-utils -y
sudo ln -s /bin/bash /bin/sh
apt-get install alien -y
apt-get install rpm
	3. 查看内核版本, 要求操作系统3.10.0 及以上
1
2
[root@centos-01 /root]#uname -r 
3.10.0-327.el7.x86_64

检查内存

1
free -g

企业级应用最低要求64G, 推荐256G 及以上
如果free -g

显示的free列的内存小于配置文件中的memory_limit配置, 需要清理缓存或者修改配置memory_limit, 将memory_limit修改小于free 列的值. 清理缓存操作如下

1
# echo 3 > /proc/sys/vm/drop_caches

检查磁盘

确保配置文件中, data_dir, redo_dir, home_path, 对应的磁盘已经完成挂载, data_dir和redo_dir 对应目录为空, data_dir 对应目录的磁盘已经使用率必须低于4%.

检查网卡名称


配置文件中, 有一个配置项”devname” 需要指定网卡. 在启动 OBServer 服务时,需要通过“-i”参数指定网卡,服务器有 可能有多个网卡以及多个 IP,OBServer 之间通信依赖指定的网卡和 IP。可以通过 ifconfig 命令查看网卡名称 (需要先安装 net-tools 依赖 包),确保存在有效的网卡即可。
在本例中:

配置limits.conf

ulimit 用于限制 shell 启动进程所占用的资源。个人测试使用,可以不用设置, 但企业用户必须设置.
有两种方法可以修 改资源限制,一种是通过启动时 session 级别指定,另外一种是修改 /etc/security/limits.conf 配置文件,全局生效。
OBServer 进程涉及的几个限制包括线程最大栈空间大小(stack), 最大文件句柄数(open files),core 文件大小(core file size)。
如下在启动 OBServer 进程时,session 级别设置最大栈空间大小 为 unlimited,最大文件句柄数为 655350,core 文件大小为 unlimited

1
2
3
4
5
6
7
8
9
10
11
$vi /etc/security/limits.conf 添加
root soft nofile 655350
root hard nofile 655350
* soft nofile 655350
* hard nofile 655350
* soft stack 20480
* hard stack 20480
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited
	退出当前session, 重新登录

检查配置是否生效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ulimit -a
# 执行该命令,资源限制详情如下 (blocks, -c) 0
core file size
data seg size scheduling priority file size
pending signals max locked memory
(kbytes, -d) unlimited (-e) 0
(blocks, -f) unlimited (-i) 772861
(kbytes, -l) 64
max memory size
open files
pipe size
POSIX message queues real-time priority
stack size
cpu time
max user processes virtual memory file locks
(kbytes, -m) unlimited (-n) 1024
(512 bytes, -p) 8
(bytes, -q) 819200
(-r) 0 (kbytes, -s) 8192
(seconds, -t) unlimited (-u) 655360
(kbytes, -v) unlimited (-x) unlimited

配置“sysctl.conf”文件

为保证 OceanBase 正常运行,请在安装 OceanBase 前修改所有物理机的“/etc/sysctl.conf”配置(用以提高 Linux 的系统性能)。

有一些参数, 操作系统已经提前设置了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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_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 = 0
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_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_slow_start_after_idle=0

vm.swappiness = 0
vm.min_free_kbytes = 2097152

# 此处为oceanbase 的data 目录
kernel.core_pattern = /data/core-%e-%p-%t

其中, “kernel.core_pattern = /data/core-%e-%p-%t ”, /data 为 oceanbase的data 目录, 另外如果是个人测试, 也可以只设置 “fs.aio-max-nr=1048576”

1
2
# 配置生效
sysctl -p

关闭防火墙和 SELinux

个人测试可以不用设置, 但企业用户建议进行设置

firewalld关闭

1
2
3
4
#依次执行这 3 条命令 
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

selinux关闭

vi /etc/selinux/linux

1
2

SELINUX=disabled

执行该命令

1
2
3
setenforce 0
#查看配置已生效
cat /etc/selinux/config

设置时钟同步

当下面任一状况时, 可以跳过设置时钟同步:

  1. 若 NTP 时钟已经处于同步状态
  2. 部署为单机版
  3. 个人测试

OceanBase 集群中各服务器的时间需保持一致,否则会导致 OceanBase 集群无法启动,运行时也会出现故障。对于企业用户来说, 时钟同步是非常非常重要, 物理机与时钟服务器的误差在 50ms 以下可认为时钟是同步状态 , 最大容忍误差不能超过200ms. 当超过200ms, 会出现无主状况, 恢复时钟同步后, 重启observer, 可以恢复状态.

检查时钟同步

1
sudo clockdiff  $IP

配置时钟同步

https://open.oceanbase.com/docs/community/oceanbase-database/V3.1.0/optional-configuring-clock-sources

安装

安装包组件

https://open.oceanbase.com/softwareCenter/community 上下载所有的安装包, 本文展示的安装包的版本,可能已经过期, 麻烦从开源OceanBase官网下载最新版本的安装包.

如您的机器可以访问公网,并能够添加三方 YUM 软件源,您可以运行以下命令,使用 OceanBase 的官方软件源安装 OBD:

1
2
3
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
sudo yum install -y ob-deploy

将所有的软件包, scp至 主控机器上

安装OBD

当前使用root 用户, 当前操作只在主控机器上进行操作

在线安装

1
yum install -y ob-deploy

本地安装

centos或redhat

1
yum install ob-deploy-1.1.0-1.el7.x86_64.rpm

Ubuntu/Debian

1
alien -i ob-deploy-1.1.0-1.el7.x86_64.rpm

安装OBLibs

当前使用root 用户, 需要在每台机器上执行,

在线安装

1
yum install -y oceanbase-ce-libs

本地安装

先将oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm 拷贝到每台机器下

centos或redhat或anolis

1
yum install oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm

Ubuntu/Debian

1
alien -i oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm

安装OBServer & OBProxy

切换到admin 用户下

将OceanBase数据库的离线软件包加入本地镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
admin@obdriver:/data/rpm$ obd mirror clone *.rpm
name: libobclient
version: 2.0.0
release:2.el7
arch: x86_64
md5: f73cae67e2ff5be0682ac2803aba33a7ed26430e
add libobclient-2.0.0-2.el7.x86_64.rpm to local mirror
name: obclient
version: 2.0.0
release:2.el7
arch: x86_64
md5: 1d2c3ee31f40b9d2fbf97f653f549d896b7e7060
add obclient-2.0.0-2.el7.x86_64.rpm to local mirror
name: ob-deploy
version: 1.1.0
release:1.el7
arch: x86_64
md5: c01dbbebc7f44b700833ce6846df09f20033675c
add ob-deploy-1.1.0-1.el7.x86_64.rpm to local mirror
name: obproxy
version: 3.1.0
release:1.el7
arch: x86_64
md5: 0b17cf0459a3b53c5a2febb6572894d183154c64
add obproxy-3.1.0-1.el7.x86_64.rpm to local mirror
name: oceanbase-ce
version: 3.1.0
release:3.el7
arch: x86_64
md5: b73bcd531bdf3f087391991b290ff2cbcdaa0dc9
add oceanbase-ce-3.1.0-3.el7.x86_64.rpm to local mirror
name: oceanbase-ce-libs
version: 3.1.0
release:3.el7
arch: x86_64
md5: 528144ec7ff0194a8b326491a396b8f5c87b1eaa
add oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm to local mirror


1
2
3
4
5
6
7
8
9
10
11
12
13
admin@obdriver:~$ obd mirror list local
+-------------------------------------------------------------------------------------------+
| local Package List |
+-------------------+---------+---------+--------+------------------------------------------+
| name | version | release | arch | md5 |
+-------------------+---------+---------+--------+------------------------------------------+
| libobclient | 2.0.0 | 2.el7 | x86_64 | f73cae67e2ff5be0682ac2803aba33a7ed26430e |
| obclient | 2.0.0 | 2.el7 | x86_64 | 1d2c3ee31f40b9d2fbf97f653f549d896b7e7060 |
| ob-deploy | 1.1.0 | 1.el7 | x86_64 | c01dbbebc7f44b700833ce6846df09f20033675c |
| obproxy | 3.1.0 | 1.el7 | x86_64 | 0b17cf0459a3b53c5a2febb6572894d183154c64 |
| oceanbase-ce | 3.1.0 | 3.el7 | x86_64 | b73bcd531bdf3f087391991b290ff2cbcdaa0dc9 |
| oceanbase-ce-libs | 3.1.0 | 3.el7 | x86_64 | 528144ec7ff0194a8b326491a396b8f5c87b1eaa |
+-------------------+---------+---------+--------+------------------------------------------+

下载配置文件

https://github.com/oceanbase/obdeploy/tree/master/example/autodeploy 上将所有配置文件下载下来
当前有几个配置文件:

在本例中, 我们使用分布式example, 我们将分布式配置文件 scp到 主控机器上.

修改配置文件

本例中, 以distributed-with-obproxy-example.yaml为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## 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: z1
# Please don't use hostname, only IP can be supported
ip: 192.168.1.2
- name: z2
ip: 192.168.1.3
- name: z3
ip: 192.168.1.4
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
# The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
# redo_dir: /redo
# External port for OceanBase Database. The default value is 2881.
# mysql_port: 2881
# Internal port for OceanBase Database. The default value is 2882.
# rpc_port: 2882
# Defines the zone for an observer. The default value is zone1.
# zone: zone1
# The maximum running memory for an observer. When ignored, autodeploy calculates this value based on the current server available resource.
# memory_limit: 58G
# The percentage of the maximum available memory to the total memory. This value takes effect only when memory_limit is 0. The default value is 80.
# memory_limit_percentage: 80
# The reserved system memory. system_memory is reserved for general tenants. The default value is 30G. Autodeploy calculates this value based on the current server available resource.
# system_memory: 22G
# The size of a data file. When ignored, autodeploy calculates this value based on the current server available resource.
# datafile_size: 200G
# The percentage of the data_dir space to the total disk space. This value takes effect only when datafile_size is 0. The default value is 90.
# datafile_disk_percentage: 90
# System log level. The default value is INFO.
# syslog_level: INFO
# Print system logs whose levels are higher than WARNING to a separate log file. The default value is true. The default value for autodeploy mode is false.
# enable_syslog_wf: false
# Enable auto system log recycling or not. The default value is false. The default value for autodeploy mode is on.
# enable_syslog_recycle: true
# The maximum number of reserved log files before enabling auto recycling. When set to 0, no logs are deleted. The default value for autodeploy mode is 4.
# max_syslog_file_count: 4
# Cluster name for OceanBase Database. The default value is obcluster. When you deploy OceanBase Database and obproxy, this value must be the same as the cluster_name for obproxy.
# appname: obcluster
# Password for root. The default value is empty.
# root_password:
# Password for proxyro. proxyro_password must be the same as observer_sys_password. The default value is empty.
# proxyro_password:
z1:
zone: zone1
z2:
zone: zone2
z3:
zone: zone3
obproxy:
servers:
- 192.168.1.5
global:
# The working directory for obproxy. Obproxy is started under this directory. This is a required field.
home_path: /root/obproxy
# External port. The default value is 2883.
# listen_port: 2883
# The Prometheus port. The default value is 2884.
# prometheus_listen_port: 2884
# rs_list is the root server list for observers. The default root server is the first server in the zone.
# The format for rs_list is observer_ip:observer_mysql_port;observer_ip:observer_mysql_port.
# Ignore this value in autodeploy mode.
# rs_list: 127.0.0.1:2881
# Cluster name for the proxy OceanBase Database. The default value is obcluster. This value must be set to the same with the appname for OceanBase Database.
# cluster_name: obcluster
# Password for obproxy system tenant. The default value is empty.
# obproxy_sys_password:
# Password for proxyro. proxyro_password must be the same with proxyro_password. The default value is empty.
# observer_sys_password:
1
2
3
4
5
6
7
## 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

修改用户名和密码

通常这几个变量需要人肉设置一下, 每台机器的ip, home_path, data_dir, redo_dir, 在本例中, 分别修改为/home/admin/oceanbase/ob, /data/ob, /redo/ob, 分别为之前挂载的磁盘.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
oceanbase-ce:
servers:
- name: z1
# Please don't use hostname, only IP can be supported
ip: 172.30.62.200
- name: z2
ip: 172.30.62.201
- name: z3
ip: 172.30.62.202
global:
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /home/admin/oceanbase/ob
# The directory for data storage. The default value is $home_path/store.
data_dir: /data/ob
# The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
redo_dir: /redo/ob

配置proxy, 修改ip 和home_path

1
2
3
4
5
6
obproxy:
servers:
- 172.30.62.203
global:
# The working directory for obproxy. Obproxy is started under this directory. This is a required field.
home_path: /home/admin/oceanbase

另外推荐一个网站https://www.bejson.com/validators/yaml_editor/, 可以对配置文件进行yaml 检测, 很多时候, 配置文件 多一个空格, 少一个空格, 极难发现,

开始安装

对于离线安装, 需要执行一步操作, 当连不上服务器, 需要把远程的repo 配置给删掉, 避免浪费时间消耗在连接远程的repo 之上.

1
rm -fr ~/.obd/mirror/remote/*.repo

开始安装

1
admin@obdriver:~$ obd cluster autodeploy obtest -c distributed-with-obproxy-example.yaml 

检查安装是否成功

1
2
3
4
5
6
7
8
admin@obdriver:~$ obd cluster list
+------------------------------------------------------------+
| Cluster List |
+--------+---------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+--------+---------------------------------+-----------------+
| obtest | /home/admin/.obd/cluster/obtest | running |
+--------+---------------------------------+-----------------+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
admin@obdriver:~$ obd cluster display obtest
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+-------------------------------------------------+
| observer |
+---------------+---------+------+-------+--------+
| ip | version | port | zone | status |
+---------------+---------+------+-------+--------+
| 172.30.62.200 | 3.1.0 | 2881 | zone1 | active |
| 172.30.62.201 | 3.1.0 | 2881 | zone2 | active |
| 172.30.62.202 | 3.1.0 | 2881 | zone3 | active |
+---------------+---------+------+-------+--------+

Connect to obproxy ok
+-------------------------------------------------+
| obproxy |
+---------------+------+-----------------+--------+
| ip | port | prometheus_port | status |
+---------------+------+-----------------+--------+
| 172.30.62.203 | 2883 | 2884 | active |
+---------------+------+-----------------+--------+

修改配置

OceanBase 数据库有数百个配置项,有些配置是耦合的,在您熟悉 OceanBase 数据库之前,不建议您修改示例配件文件中的配置。此处示例用来说明如何修改配置,并使之生效。

所有的参数介绍请参考

1
https://github.com/oceanbase/obdeploy/blob/master/plugins/oceanbase/3.1.0/parameter.yaml
1
2
3
4
5
6
7
# 使用 edit-config 命令进入编辑模式,修改集群配置
obd cluster edit-config lo
# 修改 sys_bkgd_migration_retry_num 为 5
# 注意 sys_bkgd_migration_retry_num 值最小为 3
# 保存并退出后,OBD 会告知您如何使得此次改动生效
# 此配置项仅需要 reload 即可生效
obd cluster reload lo

验证​

安装obclient

通常在主控机器上安装obclient, 需要切换到root 账号

在线安装

1
2
yum install -y libobclient
yum install -y obclient

本地安装

centos或redhat或anolis

1
2
yum install libobclient-2.0.0-2.el7.x86_64.rpm
yum install obclient-2.0.0-2.el7.x86_64.rpm

Ubuntu/Debian

1
2
alien -i libobclient-2.0.0-2.el7.x86_64.rpm
alien -i obclient-2.0.0-2.el7.x86_64.rpm

在debian 下需要把路径设置到系统环境变量中

1
export PATH=/app/mariadb/bin:$PATH

在ubuntu下需要把路径设置到系统环境变量中

1
export PATH=/u01/obclient/bin:$PATH

安装mysql 开发包

如果需要运行sysbench, 或者tpch 等程序, 需要安装mysql 开发包

centos或redhat或anolis

1
2
3
yum install mariadb
yum install mariadb-libs
yum install mariadb-devel

Ubuntu

1
apt-get install mariadb-server

Debian

1
apt-get install mysql-server mysql-client libmariadbd18 libmariadbd-dev

检查租户

使用oceanbase, 需要创建租户, 用户真正应用必须运行在租户下
创建租户有2种方式:
可以使用obd 来创建租户, 使用obd 创建租户时, 会把所有的资源

1
obd cluster tenant create ${cluster_name} -n ${tenant_name}

创建租户, 请参考
https://open.oceanbase.com/docs/community/oceanbase-database/V3.1.0/create-a-user-tenant

在本例中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
admin@obdriver:~$ mysql -h${obproxy_ip} -P${obproxy_port} -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25 OceanBase 3.1.0 (r3-b20901e8c84d3ea774beeaca963c67d7802e4b4e) (Built Aug 10 2021 07:51:04)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> use oceanbase;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [oceanbase]> select * from gv$tenant;
+-----------+-------------+-------------------+-------------------+----------------+---------------+-----------+---------------------------------------------+
| tenant_id | tenant_name | zone_list | primary_zone | collation_type | info | read_only | locality |
+-----------+-------------+-------------------+-------------------+----------------+---------------+-----------+---------------------------------------------+
| 1 | sys | zone1;zone2;zone3 | zone1;zone2,zone3 | 0 | system tenant | 0 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 |
| 1001 | mytest | zone1;zone2;zone3 | RANDOM | 0 | | 0 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 |
+-----------+-------------+-------------------+-------------------+----------------+---------------+-----------+---------------------------------------------+
2 rows in set (0.00 sec)

MySQL [(none)]>

企业用户最佳实践

磁盘

ob 运行日志, 事务日志, 数据文件 必须独立开, 如果没有3块盘支持, 则可以一块盘分3块分区