实践练习一(必选):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

相关文章

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

SQLite3命令行工具最佳实践指南

《SQLite3命令行工具最佳实践指南》SQLite3是轻量级嵌入式数据库,无需服务器支持,具备ACID事务与跨平台特性,适用于小型项目和学习,sqlite3.exe作为命令行工具,支持SQL执行、数... 目录1. SQLite3简介和特点2. sqlite3.exe使用概述2.1 sqlite3.exe

SQL中JOIN操作的条件使用总结与实践

《SQL中JOIN操作的条件使用总结与实践》在SQL查询中,JOIN操作是多表关联的核心工具,本文将从原理,场景和最佳实践三个方面总结JOIN条件的使用规则,希望可以帮助开发者精准控制查询逻辑... 目录一、ON与WHERE的本质区别二、场景化条件使用规则三、最佳实践建议1.优先使用ON条件2.WHERE用

Springboot整合Redis主从实践

《Springboot整合Redis主从实践》:本文主要介绍Springboot整合Redis主从的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言原配置现配置测试LettuceConnectionFactory.setShareNativeConnect

全屋WiFi 7无死角! 华硕 RP-BE58无线信号放大器体验测评

《全屋WiFi7无死角!华硕RP-BE58无线信号放大器体验测评》家里网络总是有很多死角没有网,我决定入手一台支持Mesh组网的WiFi7路由系统以彻底解决网络覆盖问题,最终选择了一款功能非常... 自2023年WiFi 7技术标准(IEEE 802.11be)正式落地以来,这项第七代无线网络技术就以超高速

java中Optional的核心用法和最佳实践

《java中Optional的核心用法和最佳实践》Java8中Optional用于处理可能为null的值,减少空指针异常,:本文主要介绍java中Optional核心用法和最佳实践的相关资料,文中... 目录前言1. 创建 Optional 对象1.1 常规创建方式2. 访问 Optional 中的值2.1

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa