OceanBase离线安装
总结
将8月份写的离线安装文档, share 出来. 后续可能会发一系列的使用文档.
本文将以线上业务运行OceanBase为目标, 部署分布式版本, 如果想简单测试和试用OceanBase, 请参考https://open.oceanbase.com/quickStart
安装流程
安装前准备
安装前, 均使用root 进行操作, 安装过程中, 可以使用对应的普通用户
名词解释
- OBD: OceanBase Deployer, OceanBase 部署工具
- 主控机: 运行OBD 安装包机器
- OBServer : 每台安装 OceanBase 的物理机上面运行的 OceanBase 数据库进程/服务,称为 OBServer
- OBProxy : OceanBase Proxy, 是 OceanBase 高性能反向代理服务器,具有防连接闪断、 屏蔽后端异常(宕机、升级、网络抖动)、MySQL 协议兼容、强校 验、支持热升级和多集群等功能
部署模式
在本例采用经典的三幅本部署模式, 使用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
done1
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 | useradd -U admin -d /home/admin -s /bin/bash |
设置密码 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 进程本身无法自删除运行日志,需要定时任务或运维脚本完 成删除逻辑。
在本示例中: /data 为数据磁盘, 大小1TB, /redo 存放 redo 日志, /home/admin/oceanbase 存放oceanbase binary 和运行日志
检查目录权限 1
2
3
4
5
6
7
8ls –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 版本及以上)
- 以root 用户登录服务器
- 查看os 版本
RedHat7 系统显示如下 1
2[root@redhat-04 /root]#cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)1
2[root@centos-01 /root]#cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)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
10root@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/"1
2
3
4
5
6
7
8
9
10
11
12NAME="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
7sudo 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 | [root@centos-01 /root]#uname -r |
检查内存
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
检查配置是否生效 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21ulimit -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
1 | # 配置生效 |
关闭防火墙和 SELinux
个人测试可以不用设置, 但企业用户建议进行设置
firewalld关闭
1 | #依次执行这 3 条命令 |
selinux关闭
vi /etc/selinux/linux 1
2
SELINUX=disabled1
2
3setenforce 0
#查看配置已生效
cat /etc/selinux/config
设置时钟同步
当下面任一状况时, 可以跳过设置时钟同步:
- 若 NTP 时钟已经处于同步状态
- 部署为单机版
- 个人测试
OceanBase 集群中各服务器的时间需保持一致,否则会导致 OceanBase 集群无法启动,运行时也会出现故障。对于企业用户来说, 时钟同步是非常非常重要, 物理机与时钟服务器的误差在 50ms 以下可认为时钟是同步状态 , 最大容忍误差不能超过200ms. 当超过200ms, 会出现无主状况, 恢复时钟同步后, 重启observer, 可以恢复状态.
检查时钟同步
1 | sudo clockdiff $IP |
配置时钟同步
安装
安装包组件
从https://open.oceanbase.com/softwareCenter/community 上下载所有的安装包, 本文展示的安装包的版本,可能已经过期, 麻烦从开源OceanBase官网下载最新版本的安装包. 如您的机器可以访问公网,并能够添加三方 YUM 软件源,您可以运行以下命令,使用 OceanBase 的官方软件源安装 OBD:
1
2
3sudo 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
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
1
alien -i oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm
安装OBServer & OBProxy
切换到admin 用户下
将OceanBase数据库的离线软件包加入本地镜像
1 | admin@obdriver:/data/rpm$ obd mirror clone *.rpm |
1 | admin@obdriver:~$ obd mirror list local |
下载配置文件
到https://github.com/oceanbase/obdeploy/tree/master/example/autodeploy 上将所有配置文件下载下来 当前有几个配置文件:
- distributed-example.yaml : 分布式example
- distributed-with-obproxy-example.yaml : 分布式带obproxy的example
- single-example.yaml : 单机example
- single-with-obproxy-example.yaml : 单机example
在本例中, 我们使用分布式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 | ## Only need to configure when remote login is required |
修改用户名和密码
通常这几个变量需要人肉设置一下, 每台机器的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
16oceanbase-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
6obproxy:
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
8admin@obdriver:~$ obd cluster list
+------------------------------------------------------------+
| Cluster List |
+--------+---------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+--------+---------------------------------+-----------------+
| obtest | /home/admin/.obd/cluster/obtest | running |
+--------+---------------------------------+-----------------+
1 | admin@obdriver:~$ obd cluster display obtest |
修改配置
OceanBase 数据库有数百个配置项,有些配置是耦合的,在您熟悉 OceanBase 数据库之前,不建议您修改示例配件文件中的配置。此处示例用来说明如何修改配置,并使之生效。
所有的参数介绍请参考 1
https://github.com/oceanbase/obdeploy/blob/master/plugins/oceanbase/3.1.0/parameter.yaml
1 | # 使用 edit-config 命令进入编辑模式,修改集群配置 |
验证
安装obclient
通常在主控机器上安装obclient, 需要切换到root 账号
在线安装
1 | yum install -y libobclient |
本地安装
centos或redhat或anolis 1
2yum install libobclient-2.0.0-2.el7.x86_64.rpm
yum install obclient-2.0.0-2.el7.x86_64.rpm1
2alien -i libobclient-2.0.0-2.el7.x86_64.rpm
alien -i obclient-2.0.0-2.el7.x86_64.rpm1
export PATH=/app/mariadb/bin:$PATH
在ubuntu下需要把路径设置到系统环境变量中 1
export PATH=/u01/obclient/bin:$PATH
安装mysql 开发包
如果需要运行sysbench, 或者tpch 等程序, 需要安装mysql 开发包
centos或redhat或anolis 1
2
3yum install mariadb
yum install mariadb-libs
yum install mariadb-devel1
apt-get install mariadb-server
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
24admin@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块分区
时钟依赖
OceanBase 集群中各服务器的时间需保持一致,否则会导致 OceanBase 集群无法启动,运行时也会出现故障。对于企业用户来说, 时钟同步是非常非常重要, 物理机与时钟服务器的误差在 50ms 以下可认为时钟是同步状态 , 最大容忍误差不能超过200ms. 当超过200ms, 会出现无主状况, 恢复时钟同步后, 重启observer, 可以恢复状态.
网络时延
server间的网络时延不能超过200ms,否则同步会严重滞后, 并且可能影响选举 网卡设置 建议配置2块万兆网卡,bond模式取名bond0,mode1或mode4均可以,推荐使用mode4,如果是mode4,交换机需要配置802.3ad。网卡名建议使用eth0,eth1。建议使用network服务,不要使用NetworkManager。
参数设置
当系统写入tps 过高时, 超过系统支撑能力时, 为防止系统停止响应
1
alter system set writing_throttling_trigger_percentage=75 tenant=all(或者具体tenantname);
除非业务应用有配置重连尝试,否则建议关闭轮转合并, 切主也不能保证不杀事务
1
ALTER SYSTEM SET enable_merge_by_turn = 'False';
内存设置
- 租户的cpu和内存规格比建议不低于1:4,否则容易oom;
- 普通租户最小内存规格暂定5G以上;
- 租户内存太小时建议调大ob_sql_work_area_percentage,默认值5%,租户内存小于10G建议配20%左右;
- partition 个数限制, 单机建议不要超过10万个分区, 另外partition 数量会受内存限制, 每个副本预留内存为168KB,因此10000个副本至少需要预留1.68G内存,或者说1G的租户最多能建6k左右个partition,需要根据partition数的规划设置租户内存;另外单机.
- 物理内存使用限制,默认为80,memstore内存可用百分比,建议服务器内存256G以上配置调整为90,256G以下保持默认50
1
ALTER SYSTEM SET memstore_limit_percentage = '90';
slow query阈值调整 trace_log_slow_query_watermark 默认100ms,可以根据业务特点调整。如果阈值设置的太小,打印大量trace日志会影响性能.MySQL 默认值是1s. 大查询时间为10s
1
2
3
ALTER SYSTEM SET trace_log_slow_query_watermark = '1s';
ALTER SYSTEM SET large_query_threshold = '10s';cpu 并发度调整
1
2
3
4
5-- CPU并发度参数,建议配置为4,arm系统为2
ALTER SYSTEM SET cpu_quota_concurrency = '4';
-- 资源软负载开关,控制资源均衡水位,默认为50%,即CPU内存使用超过50%就进行unit均衡,线上建议调整为100,达到手工控制unit分布的效果
ALTER SYSTEM SET resource_soft_limit = '100';转储合并相关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23-- 配置转储50次
ALTER SYSTEM SET minor_freeze_times = 50;
-- 转储触发水位百分比,建议256G以上配置调整为70,256G以下调整为60
ALTER SYSTEM SET freeze_trigger_percentage = '60';
-- 数据拷贝并发为100
ALTER SYSTEM SET data_copy_concurrency = 100;
-- 服务器上数据传出并发为10
ALTER SYSTEM SET server_data_copy_out_concurrency = 10;
-- 服务器上数据传入并发为10
ALTER SYSTEM SET server_data_copy_in_concurrency = 10;
-- 转储预热时间,默认30s,设置了会延后转储释放的时间,改成0s
ALTER SYSTEM SET minor_warm_up_duration_time = '0s';
-- 配置chunk内存大小(建议保持默认值0,ob自行分配)
ALTER SYSTEM SET memory_chunk_cache_size = 0;
-- 最大包括版本数量,影响磁盘可用空间,默认为2,将多保留一个版本的数据在数据盘中,需调整为1
ALTER SYSTEM SET max_kept_major_version_number = '1';
ALTER SYSTEM SET max_stale_time_for_weak_consistency = '2h';事务相关
1
2
3
4
5ALTER SYSTEM SET clog_sync_time_warn_threshold = '1s';
ALTER SYSTEM SET trx_try_wait_lock_timeout = '0ms';(默认就是 0ms,无需修改)
-- 建议关闭一阶段提交,该参数值默认是false
ALTER SYSTEM SET enable_one_phase_commit='False';分区迁移速度控制, 若是集群负载很低,可以通过加大并发任务数加快 partition迁移速度, 调大迁移并发数
1
2
3alter system set data_copy_concurrency=40;
alter system set server_data_copy_out_concurrency=20;
alter system set server_data_copy_in_concurrency=20;压缩相关
1
2-- (默认就是 zstd_1.0,无需修改), 不过系统支持多种压缩算法
ALTER SYSTEM SET default_compress_func = 'zstd_1.0';cache 刷新相关
1
ALTER SYSTEM SET autoinc_cache_refresh_interval = '43200s';
prepare statement, server端ps受_ob_enable_prepared_statement开关控制,除了objdbc和oci的用户可以按照文档提供的说明使用server端ps,其他情况不建议用了;
1
2-- Prepared Statement参数,不用java建联的配置建议设为0
ALTER SYSTEM SET _ob_enable_prepared_statement = 0;系统相关
1
2
3
4
5ALTER SYSTEM SET server_permanent_offline_time = '7200s';
-- (公有云建议5M,外部环境建议5M,否则建议默认值30M)
ALTER SYSTEM SET syslog_io_bandwidth_limit = '5M';集群升级策略, 在进行版本升级,机器临时上下线,可以先进行一次转储,可以减少启动observer时候恢复时间
批量导入大量数据最佳策略, 如果集群是多租户的,如果某个租户要大批量导入数据,为避免影响其他租户, 导完数据后可以恢复以上两个参数:
- 1.调整 cpu_quota_concurrency =1 ,防止租户间cpu抢占
- 开启多轮转储减少合并触发,这样可以提高导入速度
- 租户primary_zone配置,
- primar_zone配置到具体某个zone中, 适用场景:业务使用单表、zone_name1与应用在同机房、zone_name2和zone_name3作为从副本平时无业务流量,具体zone顺序需按机房优先级、按应用和ob的机房配置。
1
ALTER TENANT SET PRIMARY_ZONE = 'zone_name1;zone_name2,zone_name3';
- 打散primary_zone到所有全功能zone中, 使用场景:业务使用分区表、集群中所有副本都在同一机房或不同zone机房间网络延迟在1ms内,需要所有副
1
ALTER TENANT SET PRIMARY_ZONE = 'zone_name1,zone_name2,zone_name3';
- primar_zone配置到具体某个zone中, 适用场景:业务使用单表、zone_name1与应用在同机房、zone_name2和zone_name3作为从副本平时无业务流量,具体zone顺序需按机房优先级、按应用和ob的机房配置。
租户设置
并发度设置
1
2
3
4
5
6
7
8
9
10
11
12
13-- 最大并发度,默认32,有大查询业务的建议调整为128
SET GLOBAL ob_max_parallel_degree = 128;
/*
parallel_max_servers 推荐设置为测试租户分配的 resource unit cpu 数的 10 倍
如测试租户使用的 unit 配置为:create resource unit $unit_name max_cpu 26
那么该值设置为 260
parallel_server_target 推荐设置为 parallel_max_servers * 机器数*0.8
那么该值为 260*3*0.8=624
*/
set global parallel_max_servers=260;
set global parallel_servers_target=624;回收站设置
1
2
3
4
5-- 回收站参数,ddl执行频率过大的场景一定要关闭,避免ddl执行过多引起租户性能异常
SET GLOBAL recyclebin = 0;
-- truncate回滚参数,truncate执行频率过大的场景一定要关闭
SET GLOBAL ob_enable_truncate_flashback = 0;客户端命令长度, OB客户端可发的命令长度受限于租户系统变量_max_allowed_packet_的限制(缺省4M),可以酌情调大;
obproxy配置
- obproxy探活
1
2
3
4
5alter proxyconfig set sock_option_flag_out = 2; -- 2代表keepalive
alter proxyconfig set server_tcp_keepidle = 5; -- 启动keepalive探活前的idle时间,5秒。
alter proxyconfig set server_tcp_keepintvl = 5; -- 两个keepalive探活包之间的时间间隔,5秒
alter proxyconfig set server_tcp_keepcnt = 2; -- 最多发送多少个keepalive包,2个。最长5+5*2=15秒发现dead_socket。
alter proxyconfig set server_tcp_user_timeout = 5; -- 等待TCP层ACK确认消息的超时时长,5秒。