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

实践:OceanBase Docker 初体验

原创 厚厚 2022-03-11
1821

练习环境:

1、 采用虚拟机部署

2、 虚拟机资源分配:16VCPU、16GB内存、100GB硬盘;

3、 操作系统:CentOS 7.9 


一、安装操作系统

在虚拟机上安装 操作系统:CentOS 7.9  ---- 步骤:略


二、安装Docter前准备

1、配置虚拟机网络,使其能正常访问互联网

//便于后面通过互联网yum安装相关软件包

[root@oceanbase ~]# ping www.baidu.com

PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.

64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=55 time=21.6 ms

64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=55 time=20.8 ms

 

2、修改主机名称

[root@oceanbase ~]# hostname

oceanbase

[root@oceanbase ~]# cat /etc/hostname

oceanbase


三、安装Docter服务

//通过以下yum命令安装

yum install -y yum-utils

yum-config-manager   --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

yum install docker-ce docker-ce-cli containerd.io


//以下为安装过程

[root@opengauss yum.repos.d]# yum install -y yum-utils

Loaded plugins: fastestmirror, langpacks

 **** 输出 略 ****

Complete!

[root@oceanbase ~]# rpm -qa | grep yum-utils

yum-utils-1.1.31-54.el7_8.noarch


[root@oceanbase ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

**** 输出 略 ****

[root@oceanbase ~]# yum install docker-ce docker-ce-cli containerd.io

Loaded plugins: fastestmirror, langpacks

 **** 输入 略 ****

 Complete!

[root@oceanbase ~]# rpm -qa | grep docker

docker-scan-plugin-0.17.0-3.el7.x86_64

docker-ce-rootless-extras-20.10.13-3.el7.x86_64

docker-ce-cli-20.10.13-3.el7.x86_64

docker-ce-20.10.13-3.el7.x86_64


四、查看并启动Docker服务

[root@oceanbase ~]# systemctl status docker.service

[root@oceanbase ~]# systemctl start docker.service

[root@oceanbase ~]# systemctl enable docker.service

[root@oceanbase ~]# systemctl status docker.service

//说明:以上命令输出略;


五、获取OceanBase数据库docker镜像

docker search oceanbase

docker pull oceanbase/oceanbase-ce


[root@oceanbase ~]# docker search oceanbase

NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

oceanbase/oceanbase-xe           OceanBase Database 2.2 Express Edition          4                   

oceanbase/obce-mini              obce-mini is a mini standalone test image fo…   3                   

oceanbase/oceanbase-ce           OceanBase is open source now. This is the do…   3                   

obpilot/oceanbase-ce             3 steps to run an OceanBase-CE docker in you…   2                   

oceanbase/obce-operator          obce-operator                                   1                   

zibuyu886/oceanbase-ce-cluster   OceanBase ce cluster                            1                   

oceanbase/centos7                                                                0                   

huweijie/oceanbase-ce-deploy                                                     0                   

superbigfu/oceanbase                                                             0                   

20220121/oceanbase                                                               0                   

hongweiqin/anolisos-oceanbase    A tentative deploy of oceanbase.                0                   

stutiredboy/centos_ob            Build environment for OceanBase 3.1 CE. Crea…   0                   

[root@oceanbase ~]# docker pull oceanbase/oceanbase-ce

Using default tag: latest

Error response from daemon: manifest for oceanbase/oceanbase-ce:latest not found: manifest unknown: manifest unknown

[root@oceanbase ~]# docker pull obpilot/oceanbase-ce

Using default tag: latest

latest: Pulling from obpilot/oceanbase-ce

7a0437f04f83: Pull complete

615dc48ac9f1: Pull complete

b10c1cdae3af: Pull complete

4f4fb700ef54: Pull complete

c0f6c94a6a6a: Pull complete

792630f35e24: Pull complete

Digest: sha256:7ac28415cf27ba19cb47acb67a55ebf9848ad73a63d80b7e2e85d653233dbaeb

Status: Downloaded newer image for obpilot/oceanbase-ce:latest

docker.io/obpilot/oceanbase-ce:latest

 

六、启动OceanBase Docker并进入

docker run -itd -m 12G --name oceanbase-ce obpilot/oceanbase-ce:latest

docker exec -it oceanbase-ce bash


[root@oceanbase ~]# docker run -itd -m 12G --name oceanbase-ce obpilot/oceanbase-ce:latest

b586872bd8a095be89ea8c192a6a2a5e9d53951c6ed43b6e1ceebd105d767211

[root@oceanbase ~]# docker ps |grep obpilot

b586872bd8a0   obpilot/oceanbase-ce:latest   "/bin/bash"   9 seconds ago   Up 8 seconds   2881/tcp, 2883/tcp   oceanbase-ce

[root@oceanbase ~]# docker exec -it oceanbase-ce bash

[admin@b586872bd8a0 ~]$

//此时,已进入 oceanbase-ce Docker,当前用户为: admin


七、使用OBD命令查看集群信息

obd cluster list


[admin@b586872bd8a0 ~]$ obd cluster list

+------------------------------------------------------------+

|                        Cluster List                        |

+--------+---------------------------------+-----------------+

| Name   | Configuration Path              | Status (Cached) |

+--------+---------------------------------+-----------------+

| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |

+--------+---------------------------------+-----------------+

// 此时,集群状态为: deployed  


八、使用OBD命令启动集群

obd cluster start obdemo


[admin@b586872bd8a0 ~]$ obd cluster start obdemo

Get local repositories and plugins ok

Open ssh connection ok

Cluster param config check ok

Check before start observer ok

[WARN] (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)

 

Check before start obproxy ok

Start observer ok

observer program health check ok

Connect to observer ok

Initialize cluster

Cluster bootstrap ok

Wait for observer init ok

+---------------------------------------------+

|                   observer                  |

+-----------+---------+------+-------+--------+

| ip        | version | port | zone  | status |

+-----------+---------+------+-------+--------+

| 127.0.0.1 | 3.1.1   | 2881 | zone1 | active |

+-----------+---------+------+-------+--------+

 

Start obproxy ok

obproxy program health check ok

Connect to obproxy ok

Initialize cluster

+---------------------------------------------+

|                   obproxy                   |

+-----------+------+-----------------+--------+

| ip        | port | prometheus_port | status |

+-----------+------+-----------------+--------+

| 127.0.0.1 | 2883 | 2884            | active |

+-----------+------+-----------------+--------+

obdemo running

//从上述输出可以了解该集群的相关信息:

//1. 该集群只有一个zone,即: zone1

//2. observer 相关信息,如:ip,版本,端口等;

//3. obproxy 相关信息,如:ip,商品,状态等;


九、创建业务租户、业务数据库,表等操作

以下内容操作参考OceanBase Docker中:/home/admin/readme.md 文档

[admin@b586872bd8a0 ~]$ cat /home/admin/readme.md

**** 输入 略 ****


1、连接系统租户

//使用root用户,直连 observer上sys租户的oceanbase数据库

 [admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -uroot@sys -P2881 -prootPWD123 -c -A oceanbase

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 3221487627

Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [oceanbase]>

 

或 使用root用户,通过obproxy连接集群obce-single上sys租户的oceanbase数据库

[admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [oceanbase]> show parameters like 'cluster';

+-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+

| zone  | svr_type | svr_ip    | svr_port | name    | data_type | value       | info                | section  | scope   | source  | edit_level        |

+-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+

| zone1 | observer | 127.0.0.1 |     2882 | cluster | NULL      | obce-single | Name of the cluster | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |

+-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+

1 row in set (0.008 sec)

 

MySQL [oceanbase]>

 

2、创建资源单元

//创建一个 1核2GB内存10GB硬盘空间 的资源单元 

MySQL [oceanbase]> create resource unit U1C2G max_cpu=1,min_cpu=1,max_memory='2G',min_memory='2G',max_iops=500,min_iops=500,max_session_num=1000,max_disk_size='10G';

Query OK, 0 rows affected (0.022 sec)

 

MySQL [oceanbase]>

 

3、创建资源池

MySQL [oceanbase]> create resource pool testp unit='U1C2G' ,unit_num=2;

ERROR 4656 (HY000): resource pool unit num is bigger than zone server count

//说明:集群只有一个zone,且zone中只有一台observer ,所以无法创建 unit_num大于1的资源池;

MySQL [oceanbase]> create resource pool testp unit='U1C2G' ,unit_num=1;

Query OK, 0 rows affected (0.020 sec)

 

4、 创建mysql模式租户

MySQL [oceanbase]> create tenant oboracle resource_pool_list=('testp'),primary_zone='RANDOM',charset='utf8' set ob_tcp_invited_nodes='%',ob_compatibility_mode='oracle';

ERROR 1235 (0A000): Not support oracle mode not supported

//docter 版不支持 oracle 模式;

 

MySQL [oceanbase]> create tenant testob resource_pool_list=('testp'),primary_zone='RANDOM',charset='utf8' set ob_tcp_invited_nodes='%',ob_compatibility_mode='mysql';

Query OK, 0 rows affected (1.025 sec)

 

5、登录mysql模式租户

//租户创建后,连接该租户

MySQL [oceanbase]> exit

Bye

[admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -uroot@testob#obce-single -P2883 -c

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| oceanbase          |

| information_schema |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.007 sec)

 

6、创建数据库

MySQL [(none)]> create database mydb;

Query OK, 1 row affected (0.025 sec)

 

//查看当前租户下的所有数据库

MySQL [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| oceanbase          |

| information_schema |

| mysql              |

| test               |

| mydb               |

+--------------------+

5 rows in set (0.004 sec)


//连接mydb数据库 

MySQL [(none)]> use mydb;

Database changed

MySQL [mydb]>

 

//查看用户

MySQL [mydb]> select user,host from mysql.user;

+------------+------+

| user       | host |

+------------+------+

| root       | %    |

| ORAAUDITOR | %    |

+------------+------+

2 rows in set (0.003 sec)

 

7、创建表

MySQL [mydb]> create table test01 (tid int not null, tname varchar(50));

Query OK, 0 rows affected (0.079 sec)

 

//查询表test01数据

MySQL [mydb]> select * from test01;

Empty set (0.010 sec)

 

//向表test01中插入一行数据

MySQL [mydb]> insert into test01 values (1,'testname');

Query OK, 1 row affected (0.023 sec)

 

MySQL [mydb]> commit;

Query OK, 0 rows affected (0.001 sec)


//查询表test01数据 

MySQL [mydb]> select * from test01;

+-----+----------+

| tid | tname    |

+-----+----------+

|   1 | testname |

+-----+----------+

1 row in set (0.001 sec)

 

//查询表test01结构

MySQL [mydb]> desc test01;

+-------+-------------+------+-----+---------+-------+

| Field | Type        | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| tid   | int(11)     | NO   |     | NULL    |       |

| tname | varchar(50) | YES  |     | NULL    |       |

+-------+-------------+------+-----+---------+-------+

2 rows in set (0.010 sec)

 

//查询表test01的创建语句

MySQL [mydb]> show create table test01;

+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Table  | Create Table                                                                                                                                                                                                                                                     |

+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| test01 | CREATE TABLE `test01` (

  `tid` int(11) NOT NULL,

  `tname` varchar(50) DEFAULT NULL

) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = COMPACT COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 |

+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.015 sec)

 

十、其他一些操作

1、创建用户

MySQL [mydb]> create user testuser01@'%' identified by 'testuser01';

Query OK, 0 rows affected (0.032 sec)

 

//查看已有用户信息

MySQL [mydb]> select user,host from mysql.user;

+------------+------+

| user       | host |

+------------+------+

| root       | %    |

| ORAAUDITOR | %    |

| testuser01 | %    |

+------------+------+

3 rows in set (0.006 sec)

 

MySQL [mydb]> exit                                    

Bye

  

2、使用新创建的用户 testuser01 连接租户 testob

[admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -utestuser01@testob#obce-single -P2883 -ptestuser01 -c -A mydb

ERROR 1044 (42000): Access denied for user 'testuser01'@'%' to database 'mydb'

//用户 testuser01创建后,未授予相关权限,无法连接

//使用root用户对用户 testuser01授权

[admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -uroot@testob#obce-single -P2883 -c

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [(none)]> grant all privileges on *.* to testuser01@'%';

Query OK, 0 rows affected (0.012 sec)

 

MySQL [(none)]> exit

Bye


//再次使用 testuser01连接用户testob下的 mydb 数据库

[admin@b586872bd8a0 ~]$ obclient -h127.0.0.1 -utestuser01@testob#obce-single -P2883 -ptestuser01 -c -A mydb

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

3、使用用户 testuser01 对表test01进行增、删、改、查

MySQL [mydb]> select * from test01;

+-----+----------+

| tid | tname    |

+-----+----------+

|   1 | testname |

+-----+----------+

1 row in set (0.001 sec)

 

MySQL [mydb]> insert into test01 values (2,'testname');

Query OK, 1 row affected (0.013 sec)

 

MySQL [mydb]> commit;

Query OK, 0 rows affected (0.001 sec)

 

MySQL [mydb]> select * from test01;

+-----+----------+

| tid | tname    |

+-----+----------+

|   1 | testname |

|   2 | testname |

+-----+----------+

2 rows in set (0.001 sec)

 

MySQL [mydb]> exit

Bye

[admin@b586872bd8a0 ~]$



上述即本次初步体验OceanBase Docker的内容,不足之处,请多多指教;


参考文档:

  1. 社区版官网-文档-学习中心-入门教程:https://open.oceanbase.com/docs/tutorials/quickstart/V1.0.0/2-2-how-to-quickly-experience-oceanbase
  2. 社区版官网-博客-入门实战:https://open.oceanbase.com/blog/8600142
  3. 社区版官网-问答:https://open.oceanbase.com/ask/detail?id=508
  4. 教程视频:https://www.bilibili.com/video/BV1dS4y1X7aC?spm_id_from=333.999.0.0
  5. https://docs.docker.com/engine/install/centos/
  6. https://open.oceanbase.com/ask/detail?id=508




「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论