暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

第二章:如何部署 OceanBase 社区版 2.6 如何使用 OBD 自动化部署单节点集群

395

2.6 如何使用 OBD 自动化部署单节点集群

OBD 对 OceanBase 数据库的管理权限很高,所以 OBD 需部署在数据库服务器的中控机上,需要 DBA 有完全的控制权限。


部署规划

本文以使用一台机器部署为例进行操作。


机器信息

机器类型云主机 ECS
IP172.20.249.50
网卡名eth0
OSCentOS Linux release 8.4.2105
CPU4C
内存总内存 14G,可用内存 11G
磁盘1云盘 /dev/vda 100G
磁盘2云盘 /dev/vdb 100G

机器和角色划分

角色机器备注
OBD172.20.249.50中控机,自动化部署软件
OBServer 节点172.20.249.50OceanBase 数据库
ODP172.20.249.50OceanBase 访问反向代理
OBClient172.20.249.50OceanBase 命令行客户端

磁盘划分

这里使用 LVM 技术对 /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=0        0 0
/dev/obvg/lvdata             /data         ext4            defaults,noatime,nodiratime,nodelalloc,barrier=0        0 0

# 挂载文件系统
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


编辑 OBD 配置文件

OBD 针对不同的部署场景提供了不同的配置文件。这些配置文件示例放在 OceanBase 数据库开源项目地址中,您可访问链接查看:https://github.com/oceanbase/obdeploy/tree/master/example

如果是部署单节点版本,您可下载其中两个配置文件:

简单起见,这里只部署单节点 observer 进程,所以下载第一个配置文件。

注意

后续版本的配置文件格式可能会变化,具体情况请参考 配置文件说明

[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: 0
    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: b******B  # root user password, can be empty

该配置文件是专门针对最小内存(可用内存大于 8G)的节点配置,指定了很多 observer 进程的启动参数。您需注意 yaml 的格式,每个配置项后面冒号(:)跟后面的值之间必须有个空格(' ')。

下面对关键的几个参数进行补充说明:

配置项名配置值备注
servers172.20.249.50本示例是在中控机上部署 OceanBase 数据库,所以写的是中控机 IP。可以写实际 IP,也可以写 127.0.0.1(仅学习用)。
home_path/home/admin/oceanbase-ce指定到普通用户(admin)的目录下,为区别于企业版,文件名叫 oceanbase-ce 。
data_dir/data指向独立的磁盘,这里使用前面分配的 LV(lvdata)。实际存储 OceanBase 的数据文件目录(sstable)。
redo_dir/redo指向独立的磁盘,这里使用前面分配的 LV(lvredo)。实际存储 OceanBase 的事务日志目录(clog、slog 和 ilog)。
devnameeth0跟 servers 里指定的 IP 对应的网卡。如果前面 IP 是 127.0.0.1 ,那么这里就填 lo 。通过 ip addr 命令可以查看 IP 和网卡对应关系。
mysql_port2881进程 observer 的连接端口,默认是 2881。后面 OceanBase 客户端直连这个端口可以访问该节点。
rpc_port2882进程 observer 跟其他节点进程之间的 RPC 通信端口,默认是 2882
zonezone1Zone 是逻辑机房的概念。单副本集群下只有一个 Zone,默认取名 zone1。三副本集群会有三个 Zone,名字随意,不要重复即可。
cluster_id1OceanBase 集群 ID 标识,不同集群不要重复即可。
memory_limit8G进程 observer 能从OS 获取的最大内存,最小不少于 8G 。如果机器内存丰富的话,这个参数可以大一些。
system_memory4G进程 observer 留给集群内部用的保留内存,这个会占用上面 memory_limit 的内存,留给业务租户的就更少。
datafile_size datafile_disk_percentage这两个参数 2 选 1。用来指定该节点数据文件(block_file)大小的。可以按大小指定,或者按磁盘空间的百分比指定。 这里示例磁盘空间很小,为精确控制,指定数据文件大小。
注意:
当数据文件和事务日志文件共用一个磁盘时,必须指定数据文件具体大小,以避免日志文件目录空间不够的情况发生。
syslog_levelWARN 或 ERROR运行日志的日志级别,有 INFO 、WARN、 ERROR 等几个级别。级别越低,日志量越大。进程 observer 的日志量非常大,如果磁盘空间不大的话,就调整为 WARN 或 ERROR 。
enable_syslog_recycleTRUE指定运行日志是否以滚动方式输出,最多保留指定数量的运行日志。
max_syslog_file_count10根据磁盘空间大小定数值,这里默认保留最多 10 个历史运行日志文件。
root_password随机字符串OceanBase 集群的超级管理员 root@sys 的密码,建议设置复杂的密码。

部署成功后,OBD 会把配置文件 obce-single.yaml 复制到自己的工作目录里(~/.obd/cluster/obce-single/config.yaml),后期再对原 obce-single.yaml 文件进行修改是不生效的。

说明

如果你机器内存大于 64G,上面和内存相关的参数可以不设置。


部署集群

配置文件准备好后,就可以部署配置文件对应的集群了,部署内容主要包含:

  • 复制软件到相应节点,并安装软件。

  • 在相应节点创建相关目录。

部署使用命令:obd cluster deploy [集群名] -c 集群配置文件

说明

这里的集群名是配置文件在 OBD 里的唯一标识,可以跟配置文件中的集群名相同,也可以跟文件名相同。

obd cluster deploy obce-single -c obce-single.yaml

输出:

[admin@obce00 ~]$ obd cluster deploy obce-single -c obce-single.yaml
oceanbase-ce-3.1.0 already installed.
+-----------------------------------------------------------------------------+
|                                   Packages                                  |
+--------------+---------+---------+------------------------------------------+
| Repository   | Version | Release | Md5                                      |
+--------------+---------+---------+------------------------------------------+
| oceanbase-ce | 3.1.0   | 3.el8   | 84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80 |
+--------------+---------+---------+------------------------------------------+
Repository integrity check ok
Parameter check ok
Open ssh connection ok
Remote oceanbase-ce-3.1.0-84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80 repository install ok
Remote oceanbase-ce-3.1.0-84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80 repository lib check ok
Cluster status check ok
Initializes cluster work home ok
obce-single deployed
[admin@obce00 ~]$

部署结果

  1. 使用命令 obd cluster list 查看部署状态。

    obd cluster list
    
    输出:
    [admin@obce00 ~]$ obd cluster list
    
    +----------------------------------------------------------------------+
    |                             Cluster List                             |
    +-------------+--------------------------------------+-----------------+
    | Name        | Configuration Path                   | Status (Cached) |
    +-------------+--------------------------------------+-----------------+
    | obce-single | /home/admin/.obd/cluster/obce-single | deployed        |
    +-------------+--------------------------------------+-----------------+

  2. 查看目录结构。

    其中 /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
    ├── etc
    ├── lib
    │   ├── libaio.so -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/lib/libaio.so
    │   ├── libaio.so.1 -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/lib/libaio.so.1
    │   ├── libaio.so.1.0.1 -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/lib/libaio.so.1.0.1
    │   ├── libmariadb.so -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/lib/libmariadb.so
    │   └── libmariadb.so.3 -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/lib/libmariadb.so.3
    ├── log
    └── store -> /data
    [admin@obce00 ~]$ tree /data
    /data
    ├── clog -> /redo/clog
    ├── ilog -> /redo/ilog
    ├── slog -> /redo/slog
    └── sstable
    
    4 directories, 0 files
    [admin@obce00 ~]$ tree /redo
    /redo
    ├── clog
    ├── ilog
    └── slog
    
    3 directories, 0 files


启动和初始化集群

上文中 deploy 操作只安装了软件和准备初始化目录,还需使用 obd cluster start 命令启动集群节点并初始化集群。

说明

第一次运行 start 命令会对集群进行初始化(bootstrap),以后再使用 start 命令就只会启动集群中节点进程。

obd cluster start obce-single

输出:
[admin@obce00 ~]$ obd cluster start obce-single
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster
Cluster bootstrap ok
Wait for observer init ok
+-------------------------------------------------+
|                     observer                    |
+---------------+---------+------+-------+--------+
| ip            | version | port | zone  | status |
+---------------+---------+------+-------+--------+
| 172.20.249.50 | 3.1.0   | 2881 | zone1 | active |
+---------------+---------+------+-------+--------+

obce-single running

该命令进行初始化需要几分钟。

注意

当可用内存不足 8G 或者日志目录剩余可用空间比例不足 5% 时,bootstrap 很可能会失败。

确认集群是否初始化成功(可选)

首次学习或生产部署时,建议执行此操作。

  • 查看启动后的集群状态

    [admin@obce00 ~]$ obd cluster list
    +----------------------------------------------------------------------+
    |                             Cluster List                             |
    +-------------+--------------------------------------+-----------------+
    | Name        | Configuration Path                   | Status (Cached) |
    +-------------+--------------------------------------+-----------------+
    | obce-single | /home/admin/.obd/cluster/obce-single | running         |
    +-------------+--------------------------------------+-----------------+
    
    [admin@obce00 ~]$ obd cluster display obce-single
    Get local repositories and plugins ok
    Open ssh connection ok
    Cluster status check ok
    Connect to observer ok
    Wait for observer init ok
    +-------------------------------------------------+
    |                     observer                    |
    +---------------+---------+------+-------+--------+
    | ip            | version | port | zone  | status |
    +---------------+---------+------+-------+--------+
    | 172.20.249.50 | 3.1.0   | 2881 | zone1 | active |
    +---------------+---------+------+-------+--------+

  • 检查数据文件大小

    进程 observer 启动后会初始化数据文件 block_file 的大小,可根据参数 datafile_size 或 datafile_disk_percentage 进行控制。

    [admin@obce00 ~]$ ls -lrth /data/sstable/block_file
    -rw-r--r-- 1 admin admin 50G Sep 11 17:31 /data/sstable/block_file

  • 检查进程

    OceanBase 数据库是单进程软件,进程名为 observer,可以使用下面命令查看这个进程。

    [admin@obce00 ~]$ ps -ef | grep observer | grep -v grep
    admin      30616       1 68 17:30 ?        00:02:54 /home/admin/oceanbase-ce/bin/observer -r 172.20.249.50:2882:2881 -o __min_full_resource_pool_memory=268435456,redo_dir=/redo,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,major_freeze_duty_time=Disable,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=10,root_password=b******B -z zone1 -p 2881 -P 2882 -c 1 -d /data -i eth0 -l WARN
    [admin@obce00 ~]$

    从进程中可以看到,可执行文件是 /home/admin/oceanbase-ce/bin/observer,实际上它是个软链接。

    [admin@obce00 oceanbase-ce]$ ll /home/admin/oceanbase-ce/bin/observer
    lrwxrwxrwx 1 admin admin 100 Sep 11 17:16 /home/admin/oceanbase-ce/bin/observer -> /home/admin/.obd/repository/oceanbase-ce/3.1.0/84bd2fe27f8b8243cc57d8a3f68b4c50f94aab80/bin/observer

    进程启动时,通过 -o 指定了很多参数,这些参数均已是在前述 OBD 集群部署配置文件中指定。

  • 检查进程监听端口

    [admin@obce00 ~]$ sudo netstat -ntlp |grep observer
    [sudo] password for admin:
    tcp        0      0 0.0.0.0:2881            0.0.0.0:*               LISTEN      30616/observer
    tcp        0      0 0.0.0.0:2882            0.0.0.0:*               LISTEN      30616/observer


连接 OceanBase 集群的内部实例(sys)

传统的 MySQL 客户端可以连接 OceanBase 社区版,前提是 MySQL 的版本是 5.5/5.6/5.7。OceanBase 数据库也提供自己的客户端工具 OBClient,需要安装后才可使用。和传统 MySQL 不同,OceanBase 数据库的连接端口是 2881, 连接用户名是 root@sys,密码需在上述的 OBD 配置文件里指定。

[admin@obce00 ~]$ mysql -h 172.20.249.50 -uroot@sys -P2881 -pb******B -c -A oceanbase
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221488586
Server version: 5.7.25 OceanBase 3.1.0 (r3-b20901e8c84d3ea774beeaca963c67d7802e4b4e) (Built Aug 10 2021 08:10:38)

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 [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set (0.002 sec)

在数据库列表里看到 oceanbase 数据库,表示集群初始化成功。

OBClient 安装和使用示例

sudo rpm -ivh /tmp/obd/obclient-*.rpm /tmp/obd/libobclient-*.rpm

obclient -h 172.20.249.50 -uroot@sys -P2881 -pb******B -c -A oceanbase
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论