首页 > 数据库 > > 一文读懂 | 如何快速部署 OceanBase 开源版
observer 。可以通过 RPM 包安装,也可以通过源码直接编译安装。本课程都是通过 RPM 包方式安装。软件包下载地址有:
官网下载:
open.oceanbase.com/softwareCenter/community
GitHub 下载:
github.com/oceanbase/oceanbase/releases/
阿里云 Yum 源:
mirrors.aliyun.com/oceanbase/OceanBase.repo

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

observer 进程,所以一台机器就对应一个节点。学习环境,一个机器可以启动多个 observer 进程,模拟多个节点。每个节点的监听端口(默认是 2881 和 2882 )、数据总目录是独立的,互不冲突。每个节点进程启动的最小内存是 10G ,空间需要至少 10G 。observer 进程。如果可用内存在10G ~ 20G 之间,则只可以启动一个 observer 进程。如果可用内存在 20G ~ 30G 之间,可以启动 2 个 observer 进程。如果可用内存超过 30G ,则可以启动 3个 observer 进程。当然,内存充足的时候,也可以调大每个 observer 进程能获取的内存。内存越大,节点的资源能力就越大。如果有三台机器,就没必要在一个机器上模拟多个节点了。observer 进程,还需要部署 obproxy 。 obproxy 也是单进程软件,是访问 OceanBase 的反向代理。虽然 observer 节点都可以直接访问,生产环境还是建议通过 obproxy 访问 OceanBase 集群。obproxy 进程部署位置没有要求。可以部署在应用服务器上,也可以部署在独立的机器上,或者部署在 OceanBase 机器上。obproxy 可以部署多个,生产环境建议至少部署两个。/home/admin/ 下,生产环境默认也是安装在用户 admin 下。社区版的软件 RPM 包也是这个特点,支持部署在任意用户的任意目录下。root 用户下直接部署。所以后面都以部署在用户 admin 下为前提。在部署之前初始化环境的时候,可能需要修改操作系统的配置,或者设置目录的权限等,这些操作需要 root 用户权限。不同客户内部主机登录规范不一样,可以通过 su 切换到 root 用户,或者给 admin 用户增加 sudo 权限。observer 有关的目录有好几个:admin ,并被自动安装在目录 /home/admin/oceanbase 下。[root@obce00 ~]# useradd admin
[root@obce00 ~]# rpm -ivh rpm/*
准备中... ################################# [100%]
正在升级/安装...
1:oceanbase-ce-libs-3.1.0-1.el7 ################################# [ 33%]
2:oceanbase-ce-3.1.0-1.el7 ################################# [ 67%]
3:obproxy-3.1.0-1.el7 ################################# [100%]
[root@obce00 ~]# rpm -ql oceanbase-ce-3.1.0-1.el7.x86_64
/home/admin/oceanbase
/home/admin/oceanbase/bin
/home/admin/oceanbase/bin/import_time_zone_info.py
/home/admin/oceanbase/bin/observer
/home/admin/oceanbase/etc
/home/admin/oceanbase/etc/timezone_V1.log
[root@obce00 ~]# rpm -ql obproxy-3.1.0-1.el7
/home/admin/obproxy-3.1.0/bin
/home/admin/obproxy-3.1.0/bin/obproxy
/home/admin/obproxy-3.1.0/bin/obproxyd.sh
.obd 下,如:/.obd/repository/oceanbase-ce/3.1.0/afd11d52f83eef4b456d77969fde620c4bfba85e 。这种方式是可以同时部署多个版本。vim /etc/sysctl.conf
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 =
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route =
net.ipv4.tcp_syncookies =
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=
vm.swappiness =
vm.min_free_kbytes = 2097152
vm.max_map_count=655360
fs.aio-max-nr=1048576
sysctl -p
limits.conf 限制修改会话限制。OceanBase 数据库的进程涉及的限制包括线程最大栈空间大小(Stack)、最大文件句柄数(Open Files)和 core 文件大小 (Core File Size)。ulimit -c unlimited , 只影响当前会话。如果会话断开重连了,则又是默认配置。/etc/security/limits.conf 在全局级别修改。注意修改后,已经登录的会话需要退出重登录才生效。unlimited,最大文件句柄数设置为 655350,Core 文件大小设置为 unlimited 。/etc/security/limits.conf 配置文件,如果已有设置值低于这个设置值vi /etc/security/limits.conf
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited
* soft stack unlimited
* hard stack unlimited
ulimit -a
systemctl status firewalld
inactive 那就不用管。如果是 active,那就永久关闭。systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
SELINUX 选项。vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
setenforce
chrony 服务做时间源。Chrony 是 NTP(Network Time Protocol,网络时间协议,服务器时间同步的一种协议)的另一种实现,与 ntpd 不同,它可以更快且更准确地同步系统时钟,最大程度的减少时间和频率误差。有关时间同步技术请参考时间同步产品官方介绍。admin 为例。admin 赋 sudo 权限不是必须的,只是为了某些时候方便。您可以结合企业安全规范决定是否执行。admin 用户下,执行命令:sudo date 。输入密码后能返回结果。observer 或 obproxy 进程,则不需要配置 SSH 免密登录。admin 到 OBSERVER 节点的用户 admin 的免密登录。log 目录里。主要记录进程 observer 的运行日志、选举服务的运行日志和 rootservice 的运行日志。主要读写特点是顺序写。block_file ,一次性初始化大小,后面可以在线扩容,但是不能缩容。主要读写特点是随机读、顺序写。偶尔密集的随机写。clog、ilog 和 slog 等。主要读写特点是顺序写。fdisk 或 lvm 划分为多个逻辑盘。/dev/vdb) 演示如何分盘。fdisk 直接将 /dev/vdb 划分为两个逻辑盘 (/dev/vdb1 和 /dev/vdb2 )。/dev/vdb 是云盘,后期还可以扩容,使用 fdisk 分盘后,扩容比较麻烦。/dev/vdb 使用 LVM 技术,划分出两个 LV 出来,一个给数据文件用,一个给日志文件。fdisk 或者 parted ,以及 LVM 技术都是磁盘划分组合的手段。这里就不详细描述方法。https://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/[admin@obce00 obd]$ sudo rpm -ivh ob-deploy-1.1.0-1.el8.x86_64.rpm
ob-deploy 软件默认安装在 /usr/obd 下。不同版本可能有点变化。可以通过下面命令查看位置。rpm -ql `rpm -qa|grep ob-deploy`
~/.obd/ 。熟悉下面目录结构对以后排查 OBD 问题有用。[admin@obce00 ~]$ tree ~/.obd -L 1
/home/admin/.obd
├── cluster
├── log
├── mirror
├── obd.conf
├── plugins
├── repository
└── version
5 directories, 2 files
admin 。/bin/rm -rf ~/.obd/mirror/remote/OceanBase.repo
obd mirror clone /tmp/obd/*.rpm
obd mirror list local
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
yum install -y ob-deploy

/dev/vdb 进行划分。LVM 划分 LV 大小时请根据实际磁盘大小调整参数。# lvm 分盘
pvcreate /dev/vdb
vgcreate obvg /dev/vdb
lvcreate -L 20G obvg -n lvredo
lvcreate -l 100%FREE obvg -n lvdata
# 格式化文件系统
mkfs.ext4 /dev/obvg/lvdata
mkfs.ext4 /dev/obvg/lvredo
# 修改 mount 参数文件
vim /etc/fstab
/dev/obvg/lvredo /redo ext4 defaults,noatime,nodiratime,nodelalloc,barrier=
/dev/obvg/lvdata /data ext4 defaults,noatime,nodiratime,nodelalloc,barrier=
# 挂载文件系统
mkdir -p /data /redo
vim /etc/fstab
mount /data
mount /redo
chown -R admin.admin /data /redo
# 检查
df -h
输出:
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/obvg-lvdata 59G 53M 56G 1% /data
/dev/mapper/obvg-lvredo 20G 45M 19G 1% /redo
https://github.com/oceanbase/obdeploy/tree/master/example 。observer 进程: https://github.com/oceanbase/obdeploy/blob/master/example/mini-single-example.yamlobserver 和 obproxy 进程:https://github.com/oceanbase/obdeploy/blob/master/example/mini-single-with-obproxy-example.yamlobserver 进程,所以下载第一个配置文件。[admin@obce00 ~]$ cat obce-single.yaml
## 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:
# Please don't use hostname, only IP can be supported
- 172.20.249.50
global:
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /home/admin/oceanbase-ce
# 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
# Please set devname as the network adaptor's name whose ip is in the setting of severs.
# if set severs as "127.0.0.1", please set devname as "lo"
# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
devname: eth0
mysql_port: 2881 # External port for OceanBase Database. The default value is 2881.
rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.
zone: zone1
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: 3G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
stack_size: 512K
cpu_count: 16
cache_wash_threshold: 1G
__min_full_resource_pool_memory: 268435456
workers_per_cpu_quota: 10
schema_history_expire_time: 1d
# The value of net_thread_count had better be same as cpu's core number.
net_thread_count: 4
major_freeze_duty_time: Disable
minor_freeze_times: 10
enable_separate_sys_clog:
enable_merge_by_turn: FALSE
# datafile_disk_percentage: 20 # 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_size: 50G
syslog_level: WARN # System log level. The default value is INFO.
enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.
enable_syslog_recycle: true # Enable auto system log recycling or not. The default value is false.
max_syslog_file_count: 10 # The maximum number of reserved log files before enabling auto recycling. The default value is 0.
root_password: bzNvgyhB # root user password, can be empty
这个配置文件是专门针对最小内存(可用内存大于 8G)的节点配置,里面指定了很多进程 observer 的启动参数。注意 yaml 的格式,每个配置项后面冒号(:) 跟后面的值之间必须有个空格(' ')。
下面就关键的几个参数补充说明如下:
配置项名 | 配置值 | 备注 |
servers | 172.20.249.50 | 本示例是在中控机上部署 OBSERVER,所以写中控机IP。可以写实际IP,也可以写 127.0.0.1(仅学习用)。 |
home_path | /home/admin/oceanbase-ce | 指定到普通用户(admin)的目录下,为区别于企业版,文件名叫 。 |
data_dir | /data | 指向独立的磁盘,这里使用前面分配的 LV( )。实际存储 OB 的数据文件目录( )。 |
redo_dir | /redo | 指向独立的磁盘,这里使用前面分配的LV( )。实际存储 OB 的事务日志目录( )。 |
devname | eth0 | 这个是跟 servers 里指定的 IP 对应的网卡。如果前面 IP 是 127.0.0.1 ,那么这里就填 lo 。通过 ip addr 命令可以查看 IP 和网卡对应关系。 |
mysql_port | 2881 | 进程 的连接端口,默认是 2881 。后面 OB 客户端直连这个端口可以访问该节点。 |
rpc_port | 2882 | 进程 跟其他节点进程之间的 RPC 通信端口,默认是 2882 。 |
zone | zone1 |
是逻辑机房的概念。单副本集群下只有一个 ,默认取名 。三副本集群会有三个 ,名字随意,不要重复即可。 |
cluster_id | 1 | OceanBase 集群ID 标识,不同集群不要重复即可。 |
memory_limit | 8G | 进程 能从OS 获取的最大内存,最小不少于 8G 。如果机器内存丰富的话,这个参数可以大一些。 |
system_memory | 4G | 进程 留给集群内部用的保留内存,这个会占用上面 的内存,留给业务租户的就更少。 |
datafile_size | datafile_disk_percentage | |
syslog_level | WARN 或 ERROR | 运行日志的日志级别,有 INFO 、WARN、 ERROR 等几个级别。级别越低,日志量越大。进程 的日志量非常大,如果磁盘空间不大的话,就调整为 WARN 或 ERROR 吧。 |
enable_syslog_recycle | TRUE | 指定运行日志是否以滚动方式输出,最多保留 指定数量的运行日志。 |
max_syslog_file_count | 10 | 根据磁盘空间大小定,这里默认保留最多 10 个历史运行日志文件。 |
root_password | 随机字符串 | OB 集群的超级管理员 的密码,默认是空,建议设置复杂的密码。 |
当上面部署成功后,OBD 会把配置文件 obce-single.yaml 复制到自己的工作目录里(~/.obd/cluster/obce-single/config.yaml ),后期再改外面这个 obce-single.yaml 文件,是不生效的。
注意:如果你机器内存大于 64G 时,上面参数跟内存有关的参数可以不设置。
obd cluster deploy [集群名] -c 集群配置文件 。obd cluster deploy obce-single -c obce-single.yaml
obd cluster list 。obd cluster list
/store 、/data 和 /redo 的目录关系是重点。总体结构不变,后期映射关系可能会细微调整。[admin@obce00 ~]$ tree /home/admin/oceanbase-ce/
/home/admin/oceanbase-ce/
├── admin
├── bin
│ └── observer -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/bin/observer
<......>
├── log
└── store -> /data
[admin@obce00 ~]$ tree /data
/data
├── clog -> /redo/clog
├── ilog -> /redo/ilog
├── slog -> /redo/slog
└── sstable
4 directories, files
[admin@obce00 ~]$ tree /redo
/redo
├── clog
├── ilog
└── slog
3 directories, files
deploy 操作只是安装了软件和准备初始化目录,还需要启动集群节点并初始化集群,使用 obd cluster start 命令。start 会对集群进行初始化(boostrap),以后再 start 就只会启动集群中节点进程。obd cluster start obce-single
bootstrap 要几分钟。当可用内存不足 8G 或者 日志目录剩余可用空间比例不足 5% 的时候,这个 bootstrap 是很可能会失败的。obclient 需要安装使用。root@sys ,密码是前面 OBD 配置文件里指定的。[admin@obce00 ~]$ mysql -h 172.20.249.50 -uroot@sys -P2881 -pbzNvgyhB -c -A oceanbase
oceanbase 这个数据库,就表示集群初始化成功。obclient 安装和使用示例。sudo rpm -ivh /tmp/obd/obclient-2.0.0-2.el8.x86_64.rpm /tmp/obd/libobclient-2.0.0-2.el8.x86_64.rpm
obclient -h 172.20.249.50 -uroot@sys -P2881 -pbzNvgyhB -c -A oceanbase
## Only need to configure when remote login is required
user:
username: admin
# password: your password if need
key_file: /home/admin/.ssh/id_rsa.pub
port: your ssh port, default 22
# timeout: ssh connection timeout (second), default 30
oceanbase-ce:
servers:
- name: obce01
# Please don't use hostname, only IP can be supported
ip: 172.20.249.53
- name: obce02
ip: 172.20.249.55
- name: obce03
ip: 172.20.249.56
global:
# Please set devname as the network adaptor's name whose ip is in the setting of severs.
# if set severs as "127.0.0.1", please set devname as "lo"
# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
devname: bond0
cluster_id: 2
# please set memory limit to a suitable value which is matching resource.
# memory_limit: 200G # The maximum running memory for an observer
# system_memory: 30G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
minor_freeze_times: 100
minor_warm_up_duration_time:
freeze_trigger_percentage: 40
enable_merge_by_turn: FALSE
datafile_disk_percentage: 50 # 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_size: 500G
syslog_level: INFO # System log level. The default value is INFO.
enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.
enable_syslog_recycle: true # Enable auto system log recycling or not. The default value is false.
max_syslog_file_count: 50 # 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: obce-3zones
root_password: 0EI5N08d # root user password, can be empty
proxyro_password: FAKEPASSWORD02 # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty
obce01:
mysql_port: 2881 # External port for OceanBase Database. The default value is 2881.
rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /home/admin/oceanbase-ce
# 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
zone: zone1
obce02:
mysql_port: 2881 # External port for OceanBase Database. The default value is 2881.
rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /home/admin/oceanbase-ce
# 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
zone: zone2
obce03:
mysql_port: 2881 # External port for OceanBase Database. The default value is 2881.
rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /home/admin/oceanbase-ce
# 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
zone: zone3
obproxy:
servers:
- 172.20.249.53
- 172.20.249.55
- 172.20.249.56
# 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
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
rs_list: 172.20.249.53:2881;172.20.249.55:2881;172.20.249.56:2881
enable_cluster_checkout: false
# observer cluster name, consistent with oceanbase-ce's appname
cluster_name: obce-3zones
obproxy_sys_password: FAKEPASSWORD01 # obproxy sys user password, can be empty
observer_sys_password: FAKEPASSWORD02 # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be empty
obclient -h172.20.249.54 -uroot@obmysql#obce-3zones -P2883 -p123456 -c -A test
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3129098/ ,如需转载,请注明出处,否则将追究法律责任。