实践练习一(必选):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容器部署Python环境的全流程

《通过Docker容器部署Python环境的全流程》在现代化开发流程中,Docker因其轻量化、环境隔离和跨平台一致性的特性,已成为部署Python应用的标准工具,本文将详细演示如何通过Docker容... 目录引言一、docker与python的协同优势二、核心步骤详解三、进阶配置技巧四、生产环境最佳实践

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

PHP应用中处理限流和API节流的最佳实践

《PHP应用中处理限流和API节流的最佳实践》限流和API节流对于确保Web应用程序的可靠性、安全性和可扩展性至关重要,本文将详细介绍PHP应用中处理限流和API节流的最佳实践,下面就来和小编一起学习... 目录限流的重要性在 php 中实施限流的最佳实践使用集中式存储进行状态管理(如 Redis)采用滑动

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

ShardingProxy读写分离之原理、配置与实践过程

《ShardingProxy读写分离之原理、配置与实践过程》ShardingProxy是ApacheShardingSphere的数据库中间件,通过三层架构实现读写分离,解决高并发场景下数据库性能瓶... 目录一、ShardingProxy技术定位与读写分离核心价值1.1 技术定位1.2 读写分离核心价值二

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

MySQL分库分表的实践示例

《MySQL分库分表的实践示例》MySQL分库分表适用于数据量大或并发压力高的场景,核心技术包括水平/垂直分片和分库,需应对分布式事务、跨库查询等挑战,通过中间件和解决方案实现,最佳实践为合理策略、备... 目录一、分库分表的触发条件1.1 数据量阈值1.2 并发压力二、分库分表的核心技术模块2.1 水平分

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat