暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

「OceanBase 征文」|OB4.0-基础操作

原创 不想用随机名字 2023-03-01
658

实验环境接上一章https://www.modb.pro/db/616630

集群的基本管理

启动集群

obd cluster start obtest

查看集群状态

obd cluster list

停止集群

obd cluster stop obtest

重启集群

obd cluster restart obtest

销毁集群

obd cluster destroy obtest

创建租户

使用obd创建租户

创建租户命令

obd cluster tenant create obtest -n biz_test

创建租户失败

[root@miniob ~]# obd cluster tenant create obtest -n biz_test Get local repositories and plugins ok Open ssh connection ok Connect to observer ok Create tenant biz_test x [ERROR] failed to create pool, execute sql exception: create resource pool biz_test_pool unit='biz_test_unit', unit_num=1, zone_list=('zone1')

    提示在创建资源池的时候失败,但是通过日志可以看出来,obd创建租户还是比较方便的,省略的很多sql语句,但是资源池名字什么的都是默认的,如果想要指定主副本位置、特定的资源池建议还是手动创建,测试环境可以使用obd创建,后面会描述手工创建租户的步骤。
    这个错误可以通过obclient黑屏工具,使用sys租户的root用户登录中执行sql语句查看具体是什么报错,建议obd也可以把错误日志打印出来。

[root@miniob ~]# obclient -h172.20.10.177 -P2881 -uroot -Doceanbase Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221487619 Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:57:18) Copyright (c) 2000, 2018, OB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient [oceanbase]> create resource pool biz_test_pool unit='biz_test_unit', unit_num=1, zone_list=('zone1'); ERROR 1235 (0A000): unit MEMORY_SIZE less than __min_full_resource_pool_memory not supported obclient [oceanbase]>

    发现是__min_full_resource_pool_memory参数控制普通用户的内存必须是2个G;因为我们是MiniOB,可以调整__min_full_resource_pool_memory参数大小,创建一个内存是1G的用户。
查询当前参数值的语句

obclient [oceanbase]> select value from __all_virtual_sys_parameter_stat where name like '%resource_pool_memory%'; +------------+ | value | +------------+ | 2147483648 | +------------+ 1 row in set (0.003 sec)

默认大小是2147483648=2G,那修改这个参数值为1G,最小是1个G

alter system __min_full_resource_pool_memory=1073741824

修改完成后重新创建租户

[root@miniob ~]# obd cluster tenant create obtest -n biz_test Get local repositories and plugins ok Open ssh connection ok Connect to observer ok Create tenant biz_test ok

创建成功

使用obclient创建租户

  1. 使用obclient登录sys租户
obclient -h172.20.10.177 -P2881 -uroot -Doceanbase
  1. 创建资源单元
obclient [oceanbase]> CREATE RESOURCE UNIT unit1 MAX_CPU 1, MEMORY_SIZE '1G'; Query OK, 0 rows affected (0.022 sec)
  1. 创建资源池
CREATE RESOURCE POOL pool1 UNIT='unit1',UNIT_NUM=1,ZONE_LIST=('zone1');

    此处我报了一个错误

obclient [oceanbase]> CREATE RESOURCE POOL pool1 UNIT='unit1',UNIT_NUM=1,ZONE_LIST=('zone1'); 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 '"172.20.10.177:2882"' MEMORY resource not enough

    ZONE 的剩余资源不足以创建所有的 UNIT,只能删除掉之前obd自动创建的资源单元,只能把obd自动创建的租户删掉。

    删除租户

obd cluster tenant drop obtest -n biz_test

    查询资源单元

obclient [oceanbase]> SELECT a.UNIT_CONFIG_ID, a.NAME FROM oceanbase.DBA_OB_UNIT_CONFIGS a; +----------------+-----------------+ | UNIT_CONFIG_ID | NAME | +----------------+-----------------+ | 1 | sys_unit_config | | 1002 | unit1 | +----------------+-----------------+ 2 rows in set (0.004 sec)

    资源单元obd自动创建的已经删除了。
    查询资源池

obclient [oceanbase]> select * from DBA_OB_RESOURCE_POOLS\G; *************************** 1. row *************************** RESOURCE_POOL_ID: 1 NAME: sys_pool TENANT_ID: 1 CREATE_TIME: 2023-03-01 20:25:27.058155 MODIFY_TIME: 2023-03-01 20:25:27.099260 UNIT_COUNT: 1 UNIT_CONFIG_ID: 1 ZONE_LIST: zone1 REPLICA_TYPE: FULL 1 row in set (0.004 sec)

    通过检查已经没有问题了,需要退出obclient然后重新登录,手动创建资源池

obclient [oceanbase]> CREATE RESOURCE POOL pool1 UNIT='unit1',UNIT_NUM=1,ZONE_LIST=('zone1'); Query OK, 0 rows affected (0.029 sec)
  1. 创建租户,并允许所有ip登录新租户
obclient [oceanbase]> CREATE TENANT IF NOT EXISTS tenant1 charset='utf8mb4', comment 'mysql tenant/instance', primary_zone='RANDOM', resource_pool_list = ('pool1') set ob_tcp_invited_nodes = '%'; Query OK, 0 rows affected (43.946 sec)
  1. 使用root用户登录到新租户,创建一个用户,并授予all权限
[root@miniob ~]# obclient -h172.20.10.177 -P2881 -uroot@tenant1 -Doceanbase Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221487618 Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:57:18) Copyright (c) 2000, 2018, OB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient [oceanbase]> CREATE USER 'test_user' IDENTIFIED BY 'test_user'; Query OK, 0 rows affected (0.212 sec) obclient [oceanbase]> grant all on *.* to test_user; Query OK, 0 rows affected (0.120 sec)
  1. 使用新用户登录,并创建一个数据库
[root@miniob ~]# obclient -h172.20.10.177 -P2881 -utest_user@tenant1 -ptest_user Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221487624 Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:57:18) Copyright (c) 2000, 2018, OB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient [(none)]> create database test_db default character set utf8mb4; Query OK, 1 row affected (0.099 sec) obclient [(none)]>

总结

  1. __min_full_resource_pool_memory类似于oracle的隐藏参数,默认通过show parameter看不到,重启集群后,参数会恢复到默认值,如果想要长期生效,需要修改配置文件,配置文件的修改方法可以使用obd的edit-config修改,修改完成重新reload
obd cluster edit-config obtest obd cluster eload obtest
  1. obd在创建租户的时候会自动创建资源单元、资源池,同理使用obd删除租户的时候也会删除对应的资源池和资源单元。
最后修改时间:2023-03-03 16:36:44
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论