OceanBase数据库是金融级的分布式关系型数据库,本文简要介绍其整体架构,并安装部署一套OceanBase集群环境。
OceanBase数据库是金融级的分布式关系型数据库,产品高度兼容Oracle/MySQL,具有云原生、强一致等特性。具体如下:
了解OceanBase集群架构前需要知道几个基本的术语:
上图是OceanBase官网上介绍的整体架构图,包括3个zone,其中ZONE-1中有总控服务主其它ZONE为总控服务备,每个ZONE中又有OBServer数据库服务和分区服务。
1)总控服务RootService
总控服务负责整个集群的资源调度、资源分配、数据分布信息管理以及Schema管理等功能。其中:
2)分区服务PartitionService
负责每个OBServer上各个分区的管理和操作
3)数据分区高可用
OceanBase数据库是基于Paxos的分布式选举算法来实现分区数据的高可用。集群中数据的一个分区会被保存到所有的Zone上,整个系统中该副本的多个分区之间通过Paxos协议进行日志同步。每个分区和它的副本构成一个独立的Paxos复制组,其中一个分区为主分区(Leader),其它分区为备分区(Follower)。所有针对这个副本的写请求,都会自动路由到对应的主分区上进行。主分区可以分布在不同的OBServer上,这样对于不同副本的写操作也会分布到不同的数据节点上,从而实现数据多点写入,提高系统性能。
OceanBase存储引擎采用基于LSM-tree的架构,基线数据保存在磁盘SSTable中、增量数据保存在内存中,每天定时将增量数据合并持久化到磁盘中保存。DML的操作是在内存中进行的,读的时候数据在内存中可能会有更新的版本,需要将存量版本和基线版本进行合并获得一个最新的版本。
在LSM-Tree里面,核心的数据结构就是SSTable,全称是Sorted String Table。SSTable是一种拥有持久化,有序且不可变的的键值存储结构,它的key和value都是任意的字节数组,并且了提供了按指定key查找和指定范围的key区间迭代遍历的功能。SSTable内部包含了一系列可配置大小的Block块,典型的大小是64KB,关于这些Block块的index存储在SSTable的尾部,用于帮助快速查找特定的Block。当一个SSTable被打开的时候,index会被加载到内存,然后根据key在内存index里面进行一个二分查找,查到该key对应的磁盘的offset之后,然后去磁盘把响应的块数据读取出来。当然如果内存足够大的话,可以直接把SSTable直接通过MMap的技术映射到内存中,从而提供更快的查找。
在LSM-Tree里,SSTable有一份在内存里面,其他的多级在磁盘上,如下图所示:
来源:https://blog.csdn.net/u010454030/article/details/90414063
OceanBase的SQL引擎分为分为解析器、优化器、执行器三部分。当 SQL 引擎接受到了 SQL 请求后,经过语法解析、语义分析、查询重写、查询优化等一系列过程后,再由执行器来负责执行。
OceanBase Database Proxy(简称 ODP)是OceanBase数据库专用的代理服务器。OceanBase 数据库的用户数据以多副本的形式存放在各个OBServer上,ODP接收用户发出的SQL请求,并将SQL请求转发至最佳目标OBServer,最后将执行结果返回给用户。
1)查看操作系统
[root@tango-centos01 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
2)查看内核
[root@tango-centos01 ~]# uname -r
3.10.0-693.el7.x86_64
OceanBase数据库要求操作系统为3.10.0及以上
安装OceanBase集群,需要保证集群内各机器的时间同步,否则集群无法启动,服务在运行时也会出现异常。
1)在每台服务器安装NTP
yum install ntp ntpdate -y
2)开启NTP服务器服务,以192.168.112.10作为server端
#编辑/etc/ntp.conf
server 192.168.112.10
#重启NTP服务
service ntpd restart
#查看NTP是否启动成功
[root@tango-01 ~]# ps -ef | grep -i ntpd
ntp 6789 1 0 13:58 ? 00:00:00 /usr/sbin/ntpd -u ntp:ntp –g
#设置 NTP 服务开机自启动
[root@tango-01 ~]# chkconfig ntpd on
Note: Forwarding request to 'systemctl enable ntpd.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
3)查看服务器的NTP连接
[root@tango-01 ~]# ntpq -4p
remote refid st t when poll reach delay offset jitter
==============================================================================
tango-01 .INIT. 16 u - 64 0 0.000 0.000 0.000
当服务器与时钟服务器的时间误差在50ms以内时,系统即认为时钟是同步的
1)关闭防火墙
[root@tango-01 ~]# systemctl disable firewalld
[root@tango-01 ~]# systemctl stop firewalld
[root@tango-01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2)关闭seniux
[root@tango-01 ~]# setenforce 0
setenforce: SELinux is disabled
1)下载OBD安装包
https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/
2)在中控机tango-01执行命令安装OBD
[root@tango-01 oceanbase]# yum install ob-deploy-1.1.2-1.el7.x86_64.rpm -y
1)下载OBClient安装包
https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/
2)在中控机tango-01执行命令安装OBClient
[root@tango-01 oceanbase]# yum install libobclient-2.0.0-2.el7.x86_64.rpm -y
[root@tango-01 oceanbase]# yum install -y obclient-2.0.0-2.el7.x86_64.rpm
1)从OceanBase官网下载OceanBase数据库、OBLibs和ODP,并复制到中控机上
[root@tango-01 oceanbase]# ll
total 111328
-rw-r--r-- 1 root root 658620 Dec 19 14:35 libobclient-2.0.0-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 41916564 Dec 19 14:35 obclient-2.0.0-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 14620416 Dec 19 14:35 ob-deploy-1.1.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 8179432 Dec 19 14:35 obproxy-3.2.0-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 48457956 Dec 19 14:35 oceanbase-ce-3.1.1-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 158876 Dec 19 14:35 oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm
2)删除远程仓库
[root@tango-01 oceanbase]# rm -fr ~/.obd/mirror/remote/*.repo
3)将安装包添加至本地镜像
[root@tango-01 oceanbase]# 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.2
release:1.el7
arch: x86_64
md5: 75e2f1921ae7760e4bc80777b4cb3b9b2b4e9c96
add ob-deploy-1.1.2-1.el7.x86_64.rpm to local mirror
name: obproxy
version: 3.2.0
release:1.el7
arch: x86_64
md5: 8d5c6978f988935dc3da1dbec208914668dcf3b2
add obproxy-3.2.0-1.el7.x86_64.rpm to local mirror
name: oceanbase-ce
version: 3.1.1
release:4.el7
arch: x86_64
md5: f19f8bfb67723712175fb0dfd60579196b3168f1
add oceanbase-ce-3.1.1-4.el7.x86_64.rpm to local mirror
name: oceanbase-ce-libs
version: 3.1.1
release:4.el7
arch: x86_64
md5: 58384f7ab4ee736e9d530f4bdd63c20ced0e7aba
add oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm to local mirror
4)查看镜像列表
[root@tango-01 oceanbase]# 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.2 | 1.el7 | x86_64 | 75e2f1921ae7760e4bc80777b4cb3b9b2b4e9c96 |
| obproxy | 3.2.0 | 1.el7 | x86_64 | 8d5c6978f988935dc3da1dbec208914668dcf3b2 |
| oceanbase-ce | 3.1.1 | 4.el7 | x86_64 | f19f8bfb67723712175fb0dfd60579196b3168f1 |
| oceanbase-ce-libs | 3.1.1 | 4.el7 | x86_64 | 58384f7ab4ee736e9d530f4bdd63c20ced0e7aba |
+-------------------+---------+---------+--------+------------------------------------------+
5)下载配置文件并修改
## Only need to configure when remote login is required
user:
username: root
password: xxxx
oceanbase-ce:
servers:
- name: z1server1
# Please don't use hostname, only IP can be supported
ip: 192.168.112.101
- name: z2server1
ip: 192.168.112.102
- name: z3server1
ip: 192.168.112.103
global:
# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
home_path: /usr/local/oceanbase/observer
device_name: ens33
memory_limit: 200M
system_memory: 100M
……
z1observer1:
zone: zone1
z2observer1:
zone: zone2
z3observer1:
zone: zone3
obproxy:
depends:
- oceanbase-ce
servers:
- 192.168.112.10
global:
# The working directory for obproxy. Obproxy is started under this directory. This is a required field.
home_path: /usr/local/oceanbase/obproxy
1)部署 OceanBase 集群
[root@tango-01 oceanbase]# obd cluster autodeploy obtest -c distributed-with-obproxy-example.yaml
Update OceanBase-community-stable-el7 ok
Update OceanBase-development-kit-el7 ok
Download oceanbase-ce-3.1.1-4.el7.x86_64.rpm (46.21 M): 100% [##################################################################################] Time: 0:00:19 2.46 MB/s
Package oceanbase-ce-3.1.1 is available.
Download obproxy-3.2.0-1.el7.x86_64.rpm (7.80 M): 100% [########################################################################################] Time: 0:00:04 1.96 MB/s
Package obproxy-3.2.0 is available.
install oceanbase-ce-3.1.1 for local ok
install obproxy-3.2.0 for local ok
Cluster param config check ok
Open ssh connection ok
Open ssh connection ok
Generate observer configuration ok
Generate obproxy configuration ok
oceanbase-ce-3.1.1 already installed.
obproxy-3.2.0 already installed.
+-----------------------------------------------------------------------------+
| Packages |
+--------------+---------+---------+------------------------------------------+
| Repository | Version | Release | Md5 |
+--------------+---------+---------+------------------------------------------+
| oceanbase-ce | 3.1.1 | 4.el7 | f19f8bfb67723712175fb0dfd60579196b3168f1 |
| obproxy | 3.2.0 | 1.el7 | 8d5c6978f988935dc3da1dbec208914668dcf3b2 |
+--------------+---------+---------+------------------------------------------+
Repository integrity check ok
Parameter check ok
Open ssh connection ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository install ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository lib check !!
[WARN] z1server1(192.168.112.101) oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 require: libmariadb.so.3
[WARN] z2server1(192.168.112.102) oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 require: libmariadb.so.3
[WARN] z3server1(192.168.112.103) oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 require: libmariadb.so.3
Remote obproxy-3.2.0-8d5c6978f988935dc3da1dbec208914668dcf3b2 repository install ok
Remote obproxy-3.2.0-8d5c6978f988935dc3da1dbec208914668dcf3b2 repository lib check ok
Try to get lib-repository
Download oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm (155.15 K): 100% [############################################################################] Time: 0:00:00 722.31 kB/s
Package oceanbase-ce-libs-3.1.1 is available.
install oceanbase-ce-libs-3.1.1 for local ok
Use oceanbase-ce-libs-3.1.1-58384f7ab4ee736e9d530f4bdd63c20ced0e7aba for oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1
Remote oceanbase-ce-libs-3.1.1-58384f7ab4ee736e9d530f4bdd63c20ced0e7aba repository install ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository lib check ok
Cluster status check ok
Initializes observer work home ok
Initializes obproxy work home ok
obtest deployed
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer x
[WARN] (192.168.112.101) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] (192.168.112.101) The recommended number of open files is 655350 (Current value: 65536)
[ERROR] (192.168.112.101) not enough memory. (Free: 160.4M, Need: 1.0G)
[WARN] (192.168.112.101) clog and data use the same disk (/)
[ERROR] (192.168.112.101) / not enough disk space for clog. Use `redo_dir` to set other disk for clog, or reduce the value of `datafile_size`
[WARN] (192.168.112.102) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] (192.168.112.102) The recommended number of open files is 655350 (Current value: 65536)
[ERROR] (192.168.112.102) not enough memory. (Free: 156.3M, Need: 1.0G)
[WARN] (192.168.112.102) clog and data use the same disk (/)
[WARN] (192.168.112.103) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] (192.168.112.103) The recommended number of open files is 655350 (Current value: 65536)
[ERROR] (192.168.112.103) not enough memory. (Free: 164.9M, Need: 1.0G)
[WARN] (192.168.112.103) clog and data use the same disk (/)
Check before start obproxy ok
2)查看OceanBase集群
[root@tango-01 oceanbase]# obd cluster list
+------------------------------------------------------+
| Cluster List |
+--------+---------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+--------+---------------------------+-----------------+
| obtest | /root/.obd/cluster/obtest | deployed |
+--------+---------------------------+-----------------+
1)使用 edit-config 命令进入编辑模式,修改集群配置
[root@tango-01 oceanbase]# obd cluster edit-config obtest
oceanbase-ce-3.1.1 already installed.
obproxy-3.2.0 already installed.
Search param plugin and load ok
Parameter check ok
Save deploy "obtest" configuration
2)重新启动obtest
[root@tango-01 oceanbase]# obd cluster start obtest
执行以下命令安装MySQL开发包:
[root@tango-01 oceanbase]# yum install mariadb -y
[root@tango-01 oceanbase]# yum install mariadb-libs –y
[root@tango-01 oceanbase]# yum install mariadb-devel -y
运行以下命令,使用 OBClient 客户端连接 OceanBase 数据库:
obclient –h192.168.112.10 -P2883 –uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 3221546072
Server version: 5.7.25 OceanBase 3.1.0 (r1-) (Built Apr 7 2021 08:14:49)
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)]>
IP为OceanBase实例所在的机器IP地址。ODP默认使用端2883连接OBClient
要使用OceanBase数据库,需要创建普通租户,业务数据必须在普通租户下运行。登录到数据库创建租户
create tenant obtest;
以上OceanBase集群环境部署完毕!
参考资料:
转载请注明原文地址:https://blog.csdn.net/solihawk/article/details/122224753
文章会同步在公众号“牧羊人的方向”更新,感兴趣的可以关注公众号,谢谢!