使用docker快速体验OceanBase(Win10 Home)

1 检查笔记本电脑是否符合资源要求

     

     所用笔记本电脑内存为16GB, 处理器Intel i5-8250U,操作系统为Windows 10 Home版,符合Ocean对Docker资源的要求。

23 安装Docker软件

从官网上下载Docker 安装包,地址如下图所示:

这台笔记本上已经安装配置号了WSL2,所以这里选择的是WSL2 backend,下载安装包后双击下载的安装包按照提示安装即可,安装的最后一步,需要退出当前windows 用户重新登陆。

打开Docker 桌面,手动调整一下默认容器资源限制,点击Docker桌面 右上角setting后,Resources菜单,看到下图提示:

        由于Docker后端使用的是WSL 2,要通过WSL2 来配置内存,cpu, 和交换区大小,查看微软官网关于WSL2 资源配置,发现下面的内容:

 windows 内存超过8G之后,默认每个容器的内存限制是总内存的80%,这台笔记本电脑内存为16G,容器内存限制为16GB*80%, 超过了Ocean要求的10GB限制,所以这里使用默认的限制即可。

3 下载并启动镜像

打开命令提示符窗口,搜索Ocean Base映像

C:\Users\lichengxu>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  

下载映像obpilot/oceanbase-ce,

C:\Users\lichengxu>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

运行下载的映像

C:\Users\lichengxu>docker images
REPOSITORY             TAG       IMAGE ID       CREATED       SIZE
obpilot/oceanbase-ce   latest    943379e0b05b   4 weeks ago   2.25GB

C:\Users\lichengxu>docker run -itd -m 10G --name oceanbase-ce 943379e0b05b
9b435a0284d5f45fca8d0c8a82f1d3635d483ce11f930c78b253cd220274f8fc

C:\Users\lichengxu>docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS         PORTS                NAMES
9b435a0284d5   943379e0b05b   "/bin/bash"   8 seconds ago   Up 9 seconds   2881/tcp, 2883/tcp   oceanbase-ce

检查容器oceanbase-ce状态为up。

4 OceanBase集群部署

登陆到运行容器内检查集群状态,集群obdemo状态为deployed

C:\Users\lichengxu>docker exec -it oceanbase-ce bash
[admin@9b435a0284d5 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+

启动集群

[admin@9b435a0284d5 ~]$ 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

启动时,可以从屏幕上看到oceanbase的启动过程,集群先启动observer,后启动obproxy,然后初始化集群,启动成功后,显示odemo状态为running。

[admin@9b435a0284d5 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | running         |
+--------+---------------------------------+-----------------+

检查现在集群状态为running,表名集群正在运行。

管理员admin的密码是adminPWD123,运行下面命令连接集群,2881为oceanbase observer监听的端口

[admin@40ba977baa4e obdemo]$ obclient -h127.1 -uroot@sys -P2881 -prootPWD123 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 3221487883
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.

也可以通过obproxy连接

[admin@40ba977baa4e obdemo]$ obclient -h127.1 -uroot@sys -P2883 -prootPWD123 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 12
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.

5 创建一个业务租户、一个业务数据库,表

创建资源单元,名称为s1c1c
MySQL [oceanbase]> create resource unit s1c1c max_cpu=1, min_cpu=1, max_memory='1G', min_memory='1G',m
ax_iops=1000, max_session_num=10000, max_disk_size='6G';
Query OK, 0 rows affected (0.014 sec)
创建资源池my_pool
MySQL [oceanbase]> create resource pool my_pool unit='s1c1c', unit_num=1;
Query OK, 0 rows affected (0.014 sec)
创建租户obmysql 
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 (1.943 sec)

退出当前会话,重新登陆,切换当前数据库至test

[admin@40ba977baa4e obdemo]$ obclient -h127.1 -uroot@obmysql -P2883
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 13
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.003 sec)

MySQL [(none)]> use test;
Database changed

创建表,插入一下数据

MySQL [test]> create table student(
    ->     sno int not null auto_increment primary key,
    ->     sname varchar(10) not null,
    ->     sex char(1) not null,
    ->     sage tinyint(100) not null,
    ->     sdept char(4) not null)comment = '学生表';
Query OK, 0 rows affected (0.101 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('liyong', 'm', 20, 'CS');
Query OK, 1 row affected (0.021 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('liuchen', 'f', 19, 'CS');
Query OK, 1 row affected (0.006 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('wangmin', 'f', 18, 'MA');
Query OK, 1 row affected (0.006 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('zhangli', 'f', 19, 'IS');
Query OK, 1 row affected (0.006 sec)

MySQL [test]>
MySQL [test]> insert into student (sname, sex, sage, sdept) values ('wangyong', 'm', 20, 'CS');
Query OK, 1 row affected (0.004 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('zhangchen', 'f', 19, 'CS');
Query OK, 1 row affected (0.006 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('xiemin', 'f', 18, 'MA');
Query OK, 1 row affected (0.006 sec)

MySQL [test]> insert into student (sname, sex, sage, sdept) values ('duli', 'm', 19, 'IS');
Query OK, 1 row affected (0.004 sec)

检查表中的数据,表中已有数据。

MySQL [test]> select * from student;
+-----+-----------+-----+------+-------+
| sno | sname     | sex | sage | sdept |
+-----+-----------+-----+------+-------+
|   1 | liyong    | m   |   20 | CS    |
|   2 | liuchen   | f   |   19 | CS    |
|   3 | wangmin   | f   |   18 | MA    |
|   4 | zhangli   | f   |   19 | IS    |
|   5 | wangyong  | m   |   20 | CS    |
|   6 | zhangchen | f   |   19 | CS    |
|   7 | xiemin    | f   |   18 | MA    |
|   8 | duli      | m   |   19 | IS    |
+-----+-----------+-----+------+-------+
8 rows in set (0.002 sec)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值