社区版OceanBase部署流程

安装OceanBase的部署工具obdeploy

OceanBase Deploy (简称 OBD)是 OceanBase 开源软件的安装部署工具。OBD 同时也是包管理器,可以用来管理 OceanBase 所有的开源软件。在下面一节我们手动编译OceanBase的产物,就需要OBD来真正部署。

 

方案1: 使用 RPM 包(Centos 7 及以上)安装

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
source /etc/profile.d/obd.sh

 

方案2:使用源码安装

使用源码安装 OBD 之前,请确认您已安装以下依赖:

  • gcc
  • wget
  • python-devel
  • openssl-devel
  • xz-devel
  • mysql-devel

Python2 使用以下命令安装:

pip install -r requirements.txt
sh build.sh
source /etc/profile.d/obd.sh

Python3 使用以下命令安装:

pip install -r requirements3.txt
sh build.sh
source /etc/profile.d/obd.sh


编译OceanBase源码

 

首先保证已经安装了以下软件

  • 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 |
| OceanBase-development-kit-el7  | remote | 2021-06-18 13:42 |
| local                          | local  | 2021-06-18 16:35 |
+--------------------------------+--------+------------------+


使用obdeploy部署OceanBase

选择配置文件

使用OBD部署OceanBase有很多配置参数,这边提供一个本地单节点配置样例:mini-local-example.yaml,注意下面的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已经以单节点的方式部署并启动好了。

 

使用obclient连接部署好的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 \
  https://mirrors.aliyun.com/oceanbase/OceanBase.repo
   
# 安装 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 |       2881 |               1 | active |                     0|
+----------------------------+----------------------------+-----------+----------+----+-------+------------+-----------------+--------+----------------------+
1 row in set (0.002 sec)

 

停止集群

obd cluster stop lo

销毁集群

# 启动集群时失败,可以能会有一些进程停留。
# 此时可用 -f 选项强制停止并销毁集群
obd cluster destroy lo

 

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值