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

相关文章

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

Docker镜像pull失败两种解决办法小结

《Docker镜像pull失败两种解决办法小结》有时候我们在拉取Docker镜像的过程中会遇到一些问题,:本文主要介绍Docker镜像pull失败两种解决办法的相关资料,文中通过代码介绍的非常详细... 目录docker 镜像 pull 失败解决办法1DrQwWCocker 镜像 pull 失败解决方法2总

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

通过Docker Compose部署MySQL的详细教程

《通过DockerCompose部署MySQL的详细教程》DockerCompose作为Docker官方的容器编排工具,为MySQL数据库部署带来了显著优势,下面小编就来为大家详细介绍一... 目录一、docker Compose 部署 mysql 的优势二、环境准备与基础配置2.1 项目目录结构2.2 基

springboot集成Deepseek4j的项目实践

《springboot集成Deepseek4j的项目实践》本文主要介绍了springboot集成Deepseek4j的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录Deepseek4j快速开始Maven 依js赖基础配置基础使用示例1. 流式返回示例2. 进阶

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Spring Boot中定时任务Cron表达式的终极指南最佳实践记录

《SpringBoot中定时任务Cron表达式的终极指南最佳实践记录》本文详细介绍了SpringBoot中定时任务的实现方法,特别是Cron表达式的使用技巧和高级用法,从基础语法到复杂场景,从快速启... 目录一、Cron表达式基础1.1 Cron表达式结构1.2 核心语法规则二、Spring Boot中定