OceanBase社区版单节点安装搭建(Docker)
ChunkWen 2024-08-26 17:37:01 阅读 87
OceanBase社区版单节点安装搭建(Docker)
文章目录
OceanBase社区版单节点安装搭建(Docker)一、环境检查及Docker配置1.1 安装docker1.2 配置docker镜像源
二、OB镜像下载三、obd部署单节点数据库四、创建业务租户、数据库、表4.1 创建租户4.2 创建数据库、表
五、参考链接
一、环境检查及Docker配置
本文采用redhat7.9作为测试环境,虚拟机安装操作系统的步骤不再列出。
官方的docker镜像要求主机资源至少为2C10G。本机主机资源配置(4c16G,磁盘100G)
<code>[root@rac04 ~]# lscpu
CPU(s): 4
[root@rac04 ~]# free -m
total used free shared buff/cache available
Mem: 15866 981 14534 12 350 14606
Swap: 8063 0 8063
[root@rac04 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 13M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/rhel-root 92G 4.2G 87G 5% /
/dev/sda1 1014M 183M 832M 19% /boot
tmpfs 1.6G 8.0K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
1.1 安装docker
#内核版本不低于3.10。
uname -a
#设置docker源仓库
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repocode>
#安装docker
yum install -y docker-ce docker-ce-cli containerd.io
#启动docker服务
systemctl start docker
#激活docker服务开机自启动
systemctl enable docker.service
#校验
[root@rac04 ~]# docker version
Client: Docker Engine - Community
Version: 25.0.3
API version: 1.44
Go version: go1.21.6
Git commit: 4debf41
Built: Tue Feb 6 21:17:10 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 25.0.3
API version: 1.44 (minimum version 1.24)
Go version: go1.21.6
Git commit: f417435
Built: Tue Feb 6 21:16:08 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
1.2 配置docker镜像源
国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务,参考Docker Hub 镜像源 - 掘金 (juejin.cn)
vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://ccr.ccs.tencentyun.com"
]
}
#重启docker服务
systemctl restart docker.service
#校验镜像源
[root@rac04 ~]# docker info |grep Mirrors -A 5
Registry Mirrors:
https://dockerproxy.com/
https://hub-mirror.c.163.com/
https://mirror.baidubce.com/
https://ccr.ccs.tencentyun.com/
Live Restore Enabled: false
二、OB镜像下载
下载地址:https://hub.docker.com/r/oceanbase/oceanbase-ce/tags,该地址可能需要使用代理访问。这里直接贴出来docker pull oceanbase/oceanbase-ce:3.1.3
找到3.1.3版本,复制拉取命令
[root@rac04 ~]# docker pull oceanbase/oceanbase-ce:3.1.3
3.1.3: Pulling from oceanbase/oceanbase-ce
13add961a70d: Pull complete
1cf396138e36: Pull complete
de207e7387d3: Pull complete
Digest: sha256:22c2d82e5e7223ee510b1c53400edd05e622d9a09bc33987bd85ce560bb0781a
Status: Downloaded newer image for oceanbase/oceanbase-ce:3.1.3
docker.io/oceanbase/oceanbase-ce:3.1.3
[root@rac04 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oceanbase/oceanbase-ce 3.1.3 66c986c2d478 23 months ago 783MB
三、obd部署单节点数据库
运行docker容器
[root@rac04 ~]# docker run -d -m 12G --cpus 4 --name oceanbase-ce oceanbase/oceanbase-ce:3.1.3
61d0ccd3ea95e36938527701c07d85f89fe950921004c4b133302dd32051dc5c
[root@rac04 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61d0ccd3ea95 oceanbase/oceanbase-ce:3.1.3 "/bin/sh -c _boot" 8 seconds ago Up 8 seconds oceanbase-ce
检查docker日志
[root@rac04 ~]# docker logs oceanbase-ce
generate boot.yaml ...
create boot dirs and deploy ob cluster ...
Package oceanbase-ce-3.1.3 is available.
install oceanbase-ce-3.1.3 for local ok
Cluster param config check ok
Open ssh connection ok
Generate observer configuration ok
oceanbase-ce-3.1.3 already installed.
+-------------------------------------------------------------------------------------------+
| Packages |
+--------------+---------+-----------------------+------------------------------------------+
| Repository | Version | Release | Md5 |
+--------------+---------+-----------------------+------------------------------------------+
| oceanbase-ce | 3.1.3 | 10000292022032916.el7 | eab08e5d473bd4884fdf2ac4d7dff6a329b68abe |
+--------------+---------+-----------------------+------------------------------------------+
Repository integrity check ok
Parameter check ok
Open ssh connection ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository install ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository lib check !!
[WARN] 127.0.0.1 oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe require: libmariadb.so.3
Try to get lib-repository
Package oceanbase-ce-libs-3.1.3 is available.
install oceanbase-ce-libs-3.1.3 for local ok
Use oceanbase-ce-libs-3.1.3-c68c3aca8a1329a360fe5d65e1c3d4fa0f93f2d5 for oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe
Remote oceanbase-ce-libs-3.1.3-c68c3aca8a1329a360fe5d65e1c3d4fa0f93f2d5 repository install ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository lib check ok
Cluster status check ok
Initializes observer work home ok
obcluster deployed
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) clog and data use the same disk (/)
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 |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 3.1.3 | 2881 | zone1 | active |
+-----------+---------+------+-------+--------+
obcluster running
Get local repositories and plugins ok
Open ssh connection ok
Connect to observer ok
Create tenant test ok
start ob cluster ...
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Cluster status check ok
Deploy "obcluster" is running
boot success!
#切换终端到docker容器
[root@rac04 ~]# docker exec -it oceanbase-ce bash
#检查集群状态
[root@61d0ccd3ea95 /]# obd cluster list
+------------------------------------------------------------+
| Cluster List |
+-----------+------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running |
docker镜像已经部署好了一个集群——obcluster,这里不再部署。附上obd操作集群的常用命令
#启动集群
obd cluster start 集群名
#停止集群
obd cluster stop 集群名
#重启集群
obd cluster restart 集群名
#查看集群状况
obd cluster list
obd cluster display 集群名
#查看集群配置,也可以根据模板,重新建一个配置文件,重新部署新集群
obd cluster edit-config 集群名
四、创建业务租户、数据库、表
连接数据库,默认root密码为空
obclient -h127.0.0.1 -P2881 -uroot@sys -p -c -A -Doceanbase
-- 修改root密码
alter user root identified by 'root';
4.1 创建租户
检查资源状况
select zone,
concat(svr_ip, ':', svr_port) observer,
cpu_capacity,
cpu_total,
cpu_assigned,
cpu_assigned_percent,
mem_capacity/1024/1024,
mem_total/1024/1024,
mem_assigned/1024/1024,
mem_assigned_percent,
disk_total/1024/1024,
disk_assigned/1024/1024,
disk_assigned_percent,
unit_Num,
round('load', 2) 'load',
round('cpu_weight', 2) 'cpu_weight',
round('memory_weight', 2) 'mem_weight',
leader_count
from __all_virtual_server_stat
order by zone, svr_ip\G
*************************** 1. row ***************************
zone: zone1
observer: 127.0.0.1:2882
cpu_capacity: 14
cpu_total: 14
cpu_assigned: 11.5
cpu_assigned_percent: 82
mem_capacity/1024/1024: 4096.00000000
mem_total/1024/1024: 4096.00000000
mem_assigned/1024/1024: 3891.20000076
mem_assigned_percent: 95
disk_total/1024/1024: 27648.00000000
disk_assigned/1024/1024: 55296.00000000
disk_assigned_percent: 200
unit_Num: 2
load: 0.00
cpu_weight: 0.00
mem_weight: 0.00
leader_count: 1318
1 row in set, 3 warnings (0.001 sec)
MySQL [oceanbase]> show parameters like 'system_memory'\G
*************************** 1. row ***************************
zone: zone1
svr_type: observer
svr_ip: 127.0.0.1
svr_port: 2882
name: system_memory
data_type: NULL
value: 4G
info: the memory reserved for internal use which cannot be allocated to any outer-tenant, and should be determined to guarantee every server functions normally. Range: [0M,)
section: OBSERVER
scope: CLUSTER
source: DEFAULT
edit_level: DYNAMIC_EFFECTIVE
1 row in set (0.002 sec)
MySQL [oceanbase]> select * from __all_unit_config;
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| gmt_create | gmt_modified | unit_config_id | name | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| 2024-03-07 14:35:29.704258 | 2024-03-07 14:35:29.704258 | 1 | sys_unit_config | 5 | 2.5 | 1288490188 | 1073741824 | 10000 | 5000 | 28991029248 | 9223372036854775807 |
| 2024-03-07 14:35:40.537529 | 2024-03-07 14:35:40.537529 | 1001 | test_unit | 9 | 9 | 3006477108 | 3006477108 | 128 | 128 | 28991029248 | 64 |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
2 rows in set (0.001 sec)
MySQL [oceanbase]> select * from gv$unit;
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| unit_id | unit_config_id | unit_config_name | resource_pool_id | resource_pool_name | zone | tenant_id | tenant_name | svr_ip | svr_port | migrate_from_svr_ip | migrate_from_svr_port | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| 1 | 1 | sys_unit_config | 1 | sys_pool | zone1 | 1 | sys | 127.0.0.1 | 2882 | | 0 | 5 | 2.5 | 1288490188 | 1073741824 | 10000 | 5000 | 28991029248 | 9223372036854775807 |
| 1001 | 1001 | test_unit | 1001 | test_pool | zone1 | 1001 | test | 127.0.0.1 | 2882 | | 0 | 9 | 9 | 3006477108 | 3006477108 | 128 | 128 | 28991029248 | 64 |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
2 rows in set (0.001 sec)
-- 剩余的资源已经不足,修改system_memory参数为2G,调小test租户的资源占用
alter system set system_memory='2G';code>
alter resource unit test_unit min_cpu=1,max_cpu=2,min_memory='1G',max_memory='1G';code>
*************************** 1. row ***************************
zone: zone1
observer: 127.0.0.1:2882
cpu_capacity: 14
cpu_total: 14
cpu_assigned: 3.5
cpu_assigned_percent: 25
mem_capacity/1024/1024: 6144.00000000
mem_total/1024/1024: 6144.00000000
mem_assigned/1024/1024: 2048.00000000
mem_assigned_percent: 33
disk_total/1024/1024: 27648.00000000
disk_assigned/1024/1024: 55296.00000000
disk_assigned_percent: 200
unit_Num: 2
load: 0.00
cpu_weight: 0.00
mem_weight: 0.00
leader_count: 1318
创建资源单元
CREATE resource unit u1 max_cpu=1, min_cpu=1, max_memory='1G', min_memory='1G', max_iops=10000,code>
min_iops=1000, max_session_num=1000000, max_disk_size='5G';code>
创建资源池
create resource pool pool1 unit='u1', unit_num=1, zone_list=('zone1') ;code>
创建mysql类型业务租户,允许所有连接,关闭回收站
create tenant yw charset='utf8mb4',zone_list=('zone1'),resource_pool_list=('pool1'),comment='业务租户1' code>
set ob_compatibility_mode=mysql,ob_tcp_invited_nodes='%',recyclebin = off;code>
检查
MySQL [oceanbase]> select * from __all_tenant where tenant_name='yw'\Gcode>
*************************** 1. row ***************************
gmt_create: 2024-03-07 15:50:54.994276
gmt_modified: 2024-03-07 15:50:54.994276
tenant_id: 1002
tenant_name: yw
replica_num: -1
zone_list: zone1
primary_zone: RANDOM
locked: 0
collation_type: 0
info: 业务租户1
read_only: 0
rewrite_merge_version: 0
locality: FULL{ -- -->1}@zone1code>
logonly_replica_num: 0
previous_locality:
storage_format_version: 0
storage_format_work_version: 0
default_tablegroup_id: -1
compatibility_mode: 0
drop_tenant_time: -1
status: TENANT_STATUS_NORMAL
in_recyclebin: 0
1 row in set (0.002 sec)
4.2 创建数据库、表
连接业务租户yw
obclient -h127.0.0.1 -P2881 -uroot@yw -p -c -A -Doceanbase
alter user root identified by 'root';
-- 创建数据库
MySQL [oceanbase]> create database ywdb charset='utf8mb4' read write;code>
Query OK, 1 row affected (0.013 sec)
MySQL [oceanbase]> use ywdb
Database changed
MySQL [ywdb]> create table t1(name char(20));
Query OK, 0 rows affected (0.072 sec)
MySQL [ywdb]> create table t3(id int(10),t3name char(20)) partition by hash(id) partitions 5;
Query OK, 0 rows affected (0.058 sec)
-- 创建表组
MySQL [ywdb]> create tablegroup tbgroup1 partition by hash partitions 5;
Query OK, 0 rows affected (0.019 sec)
-- 创建分区表并加入表组
MySQL [ywdb]> create table t4(t4id int(10)) tablegroup=tbgroup1 partition by hash(t4id) partitions 5;
Query OK, 0 rows affected (0.033 sec)
-- 将表加入表组
MySQL [ywdb]> alter table t3 tablegroup=tbgroup1;
Query OK, 0 rows affected (0.021 sec)
-- 查看表的创建语句
MySQL [ywdb]> SHOW CREATE TABLE t3;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`id` int(10) DEFAULT NULL,
`t3name` char(20) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = COMPACT COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 TABLEGROUP = 'tbgroup1'
partition by hash(id)
(partition p0,
partition p1,
partition p2,
partition p3,
partition p4) |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.027 sec)
五、参考链接
Linux安装Docker完整教程 - 哈哈哈嗝 - 博客园 (cnblogs.com)
Docker Hub 镜像源 - 掘金 (juejin.cn)
快速体验 OceanBase-OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。