本文主要是介绍实践练习一(必选):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 体验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!