docker下体验OceanBase3.1.1数据库

2024年 5月 7日 78.1k 0

参考这里的博客:https://open.oceanbase.com/answer/detail?id=508 。

宿主机信息

操作系统

[admin@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

内存

[admin@localhost ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:            31G        1.7G         22G         32M        6.8G         29G
Swap:            0B          0B          0B

CPU

[admin@localhost ~]$ cat /proc/cpuinfo | grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
processor       : 8
processor       : 9
processor       : 10
processor       : 11
processor       : 12
processor       : 13
processor       : 14
processor       : 15

安装docker

安装docker软件,命令如下,详细可参考docker官网。

yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io

查找OceanBase镜像

[admin@localhost ~]$ docker search oceanbase
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oceanbase/oceanbase-xe           OceanBase Database 2.2 Express Edition          3
oceanbase/obce-mini              obce-mini is a mini standalone test image fo…   2
obpilot/oceanbase-ce             3 steps to run an OceanBase-CE docker in you…   2
zibuyu886/oceanbase-ce-cluster   OceanBase ce cluster                            1
oceanbase/oceanbase-ce           OceanBase is open source now. This is the do…   1
huweijie/oceanbase-ce-deploy                                                     0
oceanbase/centos7                                                                0
superbigfu/oceanbase                                                             0
hongweiqin/anolisos-oceanbase    A tentative deploy of oceanbase.                0
stutiredboy/centos_ob            Build environment for OceanBase 3.1 CE. Crea…   0

安装oceanbase-ce

拉取镜像并运行

# 拉取镜像 oceanbase-ce
[admin@localhost ~]$ docker pull obpilot/oceanbase-ce:latest
latest: Pulling from obpilot/oceanbase-ce
7a0437f04f83: Pull complete
615dc48ac9f1: Pull complete
b10c1cdae3af: Pull complete
4f4fb700ef54: Pull complete
c0f6c94a6a6a: Pull complete
7079f15617f4: Pull complete
Digest: sha256:2d36d7b50745204c20dee156379c793787231386cd4cc6b0dad109a9c7267dc0
Status: Downloaded newer image for obpilot/oceanbase-ce:latest
docker.io/obpilot/oceanbase-ce:latest
# 运行 
[admin@localhost ~]$ docker run -itd -m 10G --name oceanbase-ce  obpilot/oceanbase-ce:latest
[admin@localhost ~]$ docker ps  | grep oceanbase-ce
ffd94a946881   obpilot/oceanbase-ce:latest   "/bin/bash"              26 seconds ago   Up 23 seconds   2881/tcp, 2883/tcp                                       oceanbase-ce

登录并启动oceanbase-ce

# 进入到容器内部-bash
[admin@localhost ~]$ docker exec -it oceanbase-ce bash

# 获取集群信息
[admin@ffd94a946881 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+

# 启动集群
[admin@ffd94a946881 ~]$ obd cluster start obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
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

# 获取集群详细信息
[admin@ffd94a946881 ~]$ obd cluster display obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 3.1.1   | 2881 | zone1 | active |
+-----------+---------+------+-------+--------+

Connect to obproxy ok
+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+


创建MySQL租户

# 登录单节点
[admin@ffd94a946881 ~]$ obclient -h127.1 -uroot@sys -P2881 -prootPWD123 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 3221487704
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]> show parameters like 'cluster';  # 获取集群名称(obce-single),obproxy连接的时候会使用这个名称,而不是上面的obdemo。
+-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+
| 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.009 sec)

# 使用obproxy 2883端口登录
[admin@ffd94a946881 ~]$ obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase
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.

MySQL [oceanbase]>



创建租户

#命令汇总
alter resource unit sys_unit_config min_cpu=5;
CREATE resource unit S4C1G max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G'; 
CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
exit;

# 执行过程记录
[admin@ffd94a946881 ~]$ obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 18
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]>
MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu=5;
Query OK, 0 rows affected (0.023 sec)

MySQL [oceanbase]> CREATE resource unit S4C1G max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G';
Query OK, 0 rows affected (0.027 sec)

MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
Query OK, 0 rows affected (0.048 sec)

MySQL [oceanbase]> create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (2.374 sec)
MySQL [oceanbase]> exit
Bye

登录租户并创建业务数据库

[admin@ffd94a946881 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
Enter password:
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 23
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 [test]> create database db1 ;
Query OK, 1 row affected (0.077 sec)

创建业务用户

MySQL [test]> create user user1@'%' identified by 'user1' ;
Query OK, 0 rows affected (0.093 sec)

MySQL [test]> grant all privileges on *.* to user1@'%';
Query OK, 0 rows affected (0.067 sec)

建业务表

# 使用业务用户 user1 登录 obmysql 租户
[admin@ffd94a946881 ~]$ obclient -h 127.1 -uuser1@obmysql#obce-single -P2883 -puser1 -c -A db1
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 26
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 [db1]> create table t1(id int) ;
Query OK, 0 rows affected (0.241 sec)

MySQL [db1]> insert into t1 values(1) ;
Query OK, 1 row affected (0.054 sec)

MySQL [db1]> select * from t1 ;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.005 sec)

MySQL [db1]>

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论