社区版OceanBase部署流程
安装OceanBase的部署⼯具
OceanBase Deploy (简称 OBD)是 OceanBase 开源软件的安装部署⼯具。OBD 同时也是包管理器,可以⽤来管理 OceanBase 所有的开源软件。在下⾯⼀节我们⼿动编译OceanBase的产物,就需要OBD来真正部署。
⽅案1:使⽤ RPM 包(Centos 7 及以上)安装
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo mirrors.aliyun/po
sudo yum install -y ob-deploy
source /etc/profile.d/obd.sh
⽅案2:使⽤源码安装
使⽤源码安装 OBD 之前,请确认您已安装以下依赖:
gcc
wget
python-devel
openssl-devel
xz-devel
mysql-devel
Python2 使⽤以下命令安装:
pip install -
sh build.sh
source /etc/profile.d/obd.sh
Python3 使⽤以下命令安装:
pip install -
sh build.sh
source /etc/profile.d/obd.sh
编译源码
⾸先保证已经安装了以下软件
Fedora based (, including CentOS, Fedora, OpenAnolis, RedHat, etc.)
yum install git wget rpm* cpio make glibc-devel glibc-headers binutils
Debian based (, including Debian, Ubuntu, etc.)
apt-get install git wget rpm rpm2cpio cpio make build-essential binutils
SUSE based (, including SUSE, openSUSE, etc.)
zypper install git wget rpm cpio make glibc-devel binutils
进⼊下载的oceanbase源码根⽬录下,然后以debug模式编译OB
bash build.sh debug --init --make -j16
这样会在当前⽬录下⽣成⼀个⼦⽬录:build_debug,进⼊该⼦⽬录
cd build_debug
以本地⽬录为基础创建⼀个镜像。此命令主要⽤于使⽤ OBD 启动⾃⾏编译的 OceanBase 开源软件,您可以通过此命令将编译产物加⼊本地仓库,之后就可以使⽤ obd cluster 相关的命令启动它
make DESTDIR=./ install && obd mirror create -n oceanbase-ce -V 3.1.0 -p ./usr/local -t my-oceanbase
使⽤
obd mirror list
命令查看是否成功⽣成镜像,如果显⽰有type为local的镜像,则成功
+------------------------------------------------------------+
| Mirror Repository List |
+--------------------------------+--------+------------------+
| name | type | update time |
+--------------------------------+--------+------------------+
| OceanBase-community-stable-el7 | remote | 2021-06-18 13:42 |
mysql社区版国内镜像下载| OceanBase-development-kit-el7 | remote | 2021-06-18 13:42 |
| local | local | 2021-06-18 16:35 |
+--------------------------------+--------+------------------+
使⽤部署OceanBase
选择配置⽂件
使⽤OBD部署OceanBase有很多配置参数,这边提供⼀个本地单节点配置样例:mini-local-example.y
aml,注意下⾯的tag要与刚刚⽣成镜像时`-t`指定的tag⼀致,下⾯的home_path也指定为你有权限的⽬录
oceanbase-ce:
tag: my-oceanbase
servers:
# Please don't use hostname, only IP can be supported
- 127.0.0.1
global:
home_path: /root/observer
# 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: lo
mysql_port: 2881
rpc_port: 2882
zone: zone1
cluster_id: 1
# please set memory limit to a suitable value which is matching resource.
memory_limit: 8G
system_memory: 4G
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
sys_bkgd_migration_retry_num: 3
minor_freeze_times: 10
enable_separate_sys_clog: 0
enable_merge_by_turn: FALSE
datafile_disk_percentage: 20
syslog_level: INFO
enable_syslog_recycle: true
max_syslog_file_count: 4
部署和启动数据库
# 此命令会检查 home_path 和 data_dir 指向的⽬录是否为空。
# 若⽬录不为空,则报错。此时可以加上 -f 选项,强制清空。
obd cluster deploy lo -c mini-local-example.yaml
# 此命令会检查系统参数 fs.aio-max-nr 是否不⼩于 1048576。
# 通常情况下⼀台机器启动⼀个节点不需要修改 fs.aio-max-nr。
# 当⼀台机器需要启动 4 个及以上的节点时,请务必修改 fs.aio-max-nr。
obd cluster start lo
查看集状态
# 参看obd管理的集列表
obd cluster list
# 查看 lo 集状态
obd cluster display lo
⾄此,我们⾃⼰编译的OceanBase已经以单节点的⽅式部署并启动好了。
使⽤连接部署好的OceanBase
什么是 OceanBase Client
OceanBase Client(简称 OBClient) 是⼀个基于 MariaDB 开发的客户端⼯具。您可以使⽤ OBClient 访问 OceanBase 数据库的集。OBClient 采⽤ GPL 协议。
OBClient 依赖 libobclient。libobclient 是⼀个基于 MariaDB 的 mariadb-connector-c 开发的 OceanBase C API Lib 库。libobclient 允许 C/C++ 程序以⼀种较为底层的⽅式访问 OceanBase 数据库集。libobclient ⽀持使⽤ OceanBase 数据库的最新数据模型。libobclient 采⽤ LGPL 协议。
安装 OBClient
⽅案1:使⽤ RPM 包(Centos 7 及以上)安装
# 添加 yum 源
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
mirrors.aliyun/po
# 安装 OBClient
sudo yum install obclient
⽅案2:使⽤源码安装
打包obclient的rpm包
sh obclient-build.sh
进⼊到libobclient的仓库
cd rpm
#打包libobclient的rpm 这⾥⾯主要是so和头⽂件
sh libobclient-build.sh
#安装,需要先安装libobclient的rpm,再安装obclient的rpm
笔者使⽤⽅案⼀的安装⽅式进⾏安装时,发现obclient被安装在了/u01/obclient下,这个也是很奇怪,导致安装后,⽆法直接使⽤obclient命令,先将obclient的执⾏路径加⼊PATH环境变量中
export PATH="$PATH:/u01/obclient/bin"
连接OceanBase
运⾏以下命令,使⽤ OBclient 客户端连接 OceanBase 数据库:
obclient -h<your_ip> -P<observer_mysql_port> -uroot
其中,<your_ip> 为您的机器 IP。observer 默认使⽤端⼝ 33331 连接 MySQL。如果您对端⼝做了更改,此处使⽤您实际的端⼝号。如obclient -h127.0.0.1 -P2881 -uroot
返回以下信息:
Welcome to the OceanBase. Commands end with ; or \g.
Your MySQL connection id is 3221487629
Server version: 5.7.25 OceanBase 3.1.0 (r-524427c4555e2c4a9e81992d60a6ad01e7903fc8) (Built Jun 18 2021 11:10:57)
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)]>
验证OceanBase
运⾏以下命令验证OceanBase正常运⾏:
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 __all_server;
返回以下结果:
+----------------------------+----------------------------+-----------+----------+----+-------+------------+-----------------+--------+----------------------+
| gmt_create | gmt_modified | svr_ip | svr_port | id | zone | inner_port | with_rootserver | status | block_migrate_in_time| +----------------------------+----------------------------+-----------+----------+----+-------+------------+-----------------+--------+----------------------+
| 2021-06-18 14:27:37.564943 | 2021-06-18 14:28:25.367106 | 127.0.0.1 | 2882 | 1 | zone1 | 28
81 | 1 | active | 0| +----------------------------+----------------------------+-----------+----------+----+-------+------------+-----------------+--------+----------------------+
1 row in set (0.00
2 sec)
停⽌集
obd cluster stop lo
销毁集
# 启动集时失败,可以能会有⼀些进程停留。
# 此时可⽤ -f 选项强制停⽌并销毁集
obd cluster destroy lo
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论