实践练习一(必选):OceanBase Docker 体验

2024-03-13 22:20

本文主要是介绍实践练习一(必选):OceanBase Docker 体验,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


活动链接:「OceanBase 入门到实战教程」全套练习题 - OceanBase - 社区问答- OceanBase社区-分布式数据库

实验目录:
(必选)下载Docker 镜像:OceanBase 官方社区版镜像。
(必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
(必选)创建一个业务租户、一个业务数据库,以及一些表等。

下载Docker 镜像:OceanBase 官方社区版镜像。

安装docker环境

mkdir /data/docker
ln -s /data/docker /var/lib/
yum -y install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install containerd.io docker-ce-cli docker-ce
systemctl start docker
systemctl enable docker

国内镜像加速:

cat <<EOF > /etc/docker/daemon.json
{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"],"max-concurrent-downloads": 10,"log-driver": "json-file","log-level": "warn","log-opts": {"max-size": "10m","max-file": "3"},"data-root": "/var/lib/docker"
}
EOF

systemctl restart docker

拉取镜像

docker search oceanbase
docker pull oceanbase/oceanbase-ce

启动数据库实例

docker run -p 2881:2881 --name obstandalone -e MINI_MODE=0 -d oceanbase/oceanbase-ce
docker ps检查运行状态
执行 docker logs obstandalone | tail -1 终端提示如下:boot success! 表示启动成功(需要等几分钟)

登录检查

# 使用 root 用户登录集群的 sys 租户
docker exec -it obstandalone ob-mysql sys# 连接成功后,终端将显示如下内容:
[root@test104 ~]# docker exec -it obstandalone ob-mysql sys
login as root@sys
Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881 
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221488967
Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.obclient [oceanbase]>

使用 OBD 命令完成后续的 OceanBase 集群部署。

docker exec -it obstandalone bash# 终端将显示如下内容:
[root@2d7c8e25c2fe ~]#  obd cluster start obcluster
Get local repositories ok
Search plugins ok
Load cluster param plugin ok
Cluster status check ok
Deploy "obcluster" is running
Trace ID: ebb97b2e-e0e4-11ee-b4bf-0242ac110002
If you want to view detailed obd logs, please run: obd display-trace ebb97b2e-e0e4-11ee-b4bf-0242ac110002[root@2d7c8e25c2fe ~]# obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
Trace ID: cadbfbc0-e0e4-11ee-994a-0242ac110002
If you want to view detailed obd logs, please run: obd display-trace cadbfbc0-e0e4-11ee-994a-0242ac110002[root@2d7c8e25c2fe ~]# obclient -h127.0.0.1 -P2881 -uroot -p -Doceanbase
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -AWelcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221510482
Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.obclient [oceanbase]> 
obclient [oceanbase]> select version(); 
+------------------------------+
| version()                    |
+------------------------------+
| 5.7.25-OceanBase_CE-v4.2.2.0 |
+------------------------------+
1 row in set (0.001 sec)obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ocs                |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
8 rows in set (0.015 sec)

创建一个业务租户、一个业务数据库,以及一些表等。

创建业务租户

创建租户的流程:unit config(资源规格) -> resource pool(资源池) -> tenant(租户)

# 创建新的资源规格UNIT1
CREATE RESOURCE UNIT UNIT1 MAX_CPU=2,MIN_CPU=2,MEMORY_SIZE='2G',LOG_DISK_SIZE='2G';
# 以UNIT1的资源规格创建资源池pool1(由于是单节点集群环境,所以ZONE_LIST=('zone1');假设为3节点集群,则ZONE_LIST=('zone1','zone2','zone3')。)
CREATE RESOURCE POOL pool1 UNIT='UNIT1',UNIT_NUM=1,ZONE_LIST=('zone1');
# 创建租户tenant1(分配pool1)
CREATE TENANT tenant1 CHARSET='utf8mb4', ZONE_LIST=('zone1'), PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool1') SET ob_tcp_invited_nodes='%',ob_compatibility_mode='mysql';
# 查看已有租户
obclient [oceanbase]> select tenant_id,tenant_name,primary_zone from __all_tenant;
+-----------+-------------+--------------+
| tenant_id | tenant_name | primary_zone |
+-----------+-------------+--------------+
|         1 | sys         | RANDOM       |
|      1003 | META$1004   | zone1        |
|      1004 | tenant1     | zone1        |
+-----------+-------------+--------------+
3 rows in set (0.002 sec)
# Tips:若上述过程中提示资源不足,可使用如下SQL查看资源情况
select zone,svr_ip,svr_port, cpu_capacity,cpu_assigned_max,cpu_capacity-cpu_assigned_max as cpu_free, round(memory_limit/1024/1024/1024,2) as memory_total_gb, round((memory_limit-mem_capacity)/1024/1024/1024,2) as system_memory_gb, round(mem_assigned/1024/1024/1024,2) as mem_assigned_gb, round((mem_capacity-mem_assigned)/1024/1024/1024,2) as memory_free_gb, round(log_disk_capacity/1024/1024/1024,2) as log_disk_capacity_gb, round(log_disk_assigned/1024/1024/1024,2) as log_disk_assigned_gb, round((log_disk_capacity-log_disk_assigned)/1024/1024/1024,2) as log_disk_free_gb, round((data_disk_capacity/1024/1024/1024),2) as data_disk_gb, round((data_disk_in_use/1024/1024/1024),2) as data_disk_used_gb, round((data_disk_capacity-data_disk_in_use)/1024/1024/1024,2) as data_disk_free_gb from gv$ob_servers \G
# Tips2:若创建RESOURCE POOL时提示:
ERROR 4733 (HY000): zone 'zone1' resource not enough to hold 1 unit. You can check resource info by views: DBA_OB_UNITS, GV$OB_UNITS, GV$OB_SERVERS.
server '"127.0.0.1:2882"' CPU resource not enough# Tips3:执行前一步的SQL查询发现cpu_free/memory_free_gb为零,可选方法删除test_pool(test_pool自动占用了除sys_pool之外的所有cpu内存资源)
obclient [oceanbase]> drop resource pool test_pool;
ERROR 4626 (HY000): resource pool 'test_pool' has already been granted to a tenant
obclient [oceanbase]> DROP TENANT test purge;
Query OK, 0 rows affected (35.056 sec)
obclient [oceanbase]> drop resource pool test_pool;
Query OK, 0 rows affected (0.007 sec)

参考:
https://ask.oceanbase.com/t/topic/35602836

创建业务库表

obclient [(none)]> create database dev;
Query OK, 1 row affected (0.033 sec)obclient [(none)]> use dev
Database changed
obclient [dev]> create table test_tbl(id int,data varchar(50));
Query OK, 0 rows affected (0.116 sec)obclient [dev]> insert into test_tbl values(1,'qwe');
Query OK, 1 row affected (0.011 sec)obclient [dev]> insert into test_tbl values(2,'asd');
Query OK, 1 row affected (0.005 sec)obclient [dev]> insert into test_tbl values(3,'zxc');
Query OK, 1 row affected (0.001 sec)obclient [dev]> select * from test_tbl;
+------+------+
| id   | data |
+------+------+
|    1 | qwe  |
|    2 | asd  |
|    3 | zxc  |
+------+------+
3 rows in set (0.007 sec)

这篇关于实践练习一(必选):OceanBase Docker 体验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/806370

相关文章

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

golang内存对齐的项目实践

《golang内存对齐的项目实践》本文主要介绍了golang内存对齐的项目实践,内存对齐不仅有助于提高内存访问效率,还确保了与硬件接口的兼容性,是Go语言编程中不可忽视的重要优化手段,下面就来介绍一下... 目录一、结构体中的字段顺序与内存对齐二、内存对齐的原理与规则三、调整结构体字段顺序优化内存对齐四、内

docker如何删除悬空镜像

《docker如何删除悬空镜像》文章介绍了如何使用Docker命令删除悬空镜像,以提高服务器空间利用率,通过使用dockerimage命令结合filter和awk工具,可以过滤出没有Tag的镜像,并将... 目录docChina编程ker删除悬空镜像前言悬空镜像docker官方提供的方式自定义方式总结docker

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

python实现简易SSL的项目实践

《python实现简易SSL的项目实践》本文主要介绍了python实现简易SSL的项目实践,包括CA.py、server.py和client.py三个模块,文中通过示例代码介绍的非常详细,对大家的学习... 目录运行环境运行前准备程序实现与流程说明运行截图代码CA.pyclient.pyserver.py参

使用C++实现单链表的操作与实践

《使用C++实现单链表的操作与实践》在程序设计中,链表是一种常见的数据结构,特别是在动态数据管理、频繁插入和删除元素的场景中,链表相比于数组,具有更高的灵活性和高效性,尤其是在需要频繁修改数据结构的应... 目录一、单链表的基本概念二、单链表类的设计1. 节点的定义2. 链表的类定义三、单链表的操作实现四、

Spring Boot统一异常拦截实践指南(最新推荐)

《SpringBoot统一异常拦截实践指南(最新推荐)》本文介绍了SpringBoot中统一异常处理的重要性及实现方案,包括使用`@ControllerAdvice`和`@ExceptionHand... 目录Spring Boot统一异常拦截实践指南一、为什么需要统一异常处理二、核心实现方案1. 基础组件

SpringBoot项目中Maven剔除无用Jar引用的最佳实践

《SpringBoot项目中Maven剔除无用Jar引用的最佳实践》在SpringBoot项目开发中,Maven是最常用的构建工具之一,通过Maven,我们可以轻松地管理项目所需的依赖,而,... 目录1、引言2、Maven 依赖管理的基础概念2.1 什么是 Maven 依赖2.2 Maven 的依赖传递机

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI