一、操作系统及配置
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# free -g
total used free shared buff/cache available
Mem: 15 3 7 0 3 11
Swap: 0 0 0
[root@localhost ~]# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
二、安装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-ce
拉取镜像并运行
# 拉取镜像 oceanbase-ce
docker pull oceanbase/oceanbase-ce
# 运行oceanbase实例
docker run -p 2881:2881 --name obstandalone -e MINI_MODE=0 -d oceanbase/oceanbase-ce
检查
docker ps |grep obstandalone
[root@localhost ~]# docker ps |grep obstandalone
a37616f86ec9 oceanbase/oceanbase-ce "/bin/sh -c _boot" 43 hours ago Up 43 hours 0.0.0.0:2881->2881/tcp, :::2881->2881/tcp obstandalone
执行以下命令,如果返回 boot success!
,则表示启动成功
[root@localhost ~]# docker logs obstandalone | tail -1
boot success!
检查集群状态
进入到容器内部-bash
docker exec -it obstandalone bash
然后执行
[root@a37616f86ec9 ~]# obd cluster list
+------------------------------------------------------------+
| Cluster List |
+-----------+------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running |
+-----------+------------------------------+-----------------+
Trace ID: f3c46414-967a-11ee-9519-0242ac110002
If you want to view detailed obd logs, please run: obd display-trace f3c46414-967a-11ee-9519-0242ac110002
获取集群详细信息
[root@a37616f86ec9 ~]# obd cluster display obcluster
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer 127.0.0.1:2881 ok
Wait for observer init ok
+---------------------------------------------+
| observer |
+-----------+---------+------+-------+--------+
| ip | version | port | zone | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.2.1.1 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A
Connect to Obagent ok
+---------------------------------------------------------------+
| obagent |
+------------+--------------------+--------------------+--------+
| ip | mgragent_http_port | monagent_http_port | status |
+------------+--------------------+--------------------+--------+
| 172.17.0.2 | 8089 | 8088 | active |
+------------+--------------------+--------------------+--------+
Trace ID: 1dd3b6c4-967b-11ee-b637-0242ac110002
If you want to view detailed obd logs, please run: obd display-trace 1dd3b6c4-967b-11ee-b637-0242ac110002
登录 OceanBase 数据库实例
方法1
docker exec -it obstandalone bash ---进入到容器内部-bash
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A ---登录数据库
[root@localhost ~]# docker exec -it obstandalone bash
[root@a37616f86ec9 ~]# obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221631204
Server version: OceanBase_CE 4.2.1.1 (r101010012023111012-2f6924cd5a576f09d6e7f212fac83f1a15ff531a) (Built Nov 10 2023 12:13:59)
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]>
方法2
[root@localhost ~]# 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 3221631147
Server version: OceanBase_CE 4.2.1.1 (r101010012023111012-2f6924cd5a576f09d6e7f212fac83f1a15ff531a) (Built Nov 10 2023 12:13:59)
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.1.1 |
+------------------------------+
1 row in set (0.001 sec)
四、创建租户
docker镜像起来后会自动创建一个test_pool资源池,自动占用了除sys_pool cpu之外的所有cpu这里查资料后删除了test账户和test_pool
(创建时的报错信息MEMORY resource not enough、CPU resource not enough)
select * from DBA_OB_TENANTS;-- 查看所有租户
drop tenant test force;
select * from DBA_OB_RESOURCE_POOLS;--查看所有资源池
drop resource pool test_pool;
# 创建resource unit
CREATE RESOURCE UNIT unit1 MAX_CPU 1, MIN_CPU 1, MEMORY_SIZE '2G',MAX_IOPS 1024, MIN_IOPS 1024, IOPS_WEIGHT 0, LOG_DISK_SIZE '2G';
创建resource pool
CREATE RESOURCE POOL pool1 UNIT='unit1',UNIT_NUM=1,ZONE_LIST=('zone1');
# 创建租户
create tenant ob_mysql resource_pool_list=('pool1'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
命令过程
obclient [oceanbase]> CREATE RESOURCE POOL pool1 UNIT='unit1',UNIT_NUM=1,ZONE_LIST=('zone1');
Query OK, 0 rows affected (0.013 sec)
obclient [oceanbase]> create tenant ob_mysql resource_pool_list=('pool1'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (26.092 sec)
五、创建用户及测试数据
obclient [oceanbase]> create database banjin;
Query OK, 1 row affected (0.033 sec)
obclient [oceanbase]> use banjin
Database changed
obclient [banjin]>
obclient [banjin]>
obclient [banjin]>
obclient [banjin]> show tables
-> ;
Empty set (0.003 sec)
obclient [banjin]> create table t1(id int,name varchar(10),primary key (id));
Query OK, 0 rows affected (0.097 sec)
obclient [banjin]>
obclient [banjin]>
obclient [banjin]> insert into t1 values (1,'beijing'),(2,'hebei'),(3,'shandong');
Query OK, 3 rows affected (0.008 sec)
Records: 3 Duplicates: 0 Warnings: 0
obclient [banjin]> select * from t1;
+----+----------+
| id | name |
+----+----------+
| 1 | beijing |
| 2 | hebei |
| 3 | shandong |
+----+----------+
3 rows in set (0.003 sec)
obclient [banjin]>