OceanBase Docker 部署&使用

一、测试环境

硬件环境:virtual box虚拟机,16G内存
操作系统:ubuntu

二、环境准备

  • 下载docker
frank@frank:~$ sudo apt install docker.io 
frank@frank:~$ sudo systemctl start docker
frank@frank:~$ ps -ef | grep docker
root       16728       1  0 09:32 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
frank      18244   15670  0 09:33 pts/0    00:00:00 grep --color=auto docker
frank@frank:~$ 
- 拉取镜像
frank@frank:~$ sudo docker pull oceanbase/obce-mini
frank@frank:~$ sudo docker images
[sudo] frank 的密码:
REPOSITORY             TAG       IMAGE ID       CREATED        SIZE
obpilot/oceanbase-ce   latest    943379e0b05b   8 weeks ago    2.25GB
oceanbase/obce-mini    latest    1a5ca6d233a7   5 months ago   690MB

三、启动容器

frank@frank:~$ sudo docker run -it -p 2881:2881 --name obce-mini  oceanbase/obce-mini
generate boot.yaml ...
create boot dirs and deploy ob cluster ...
Package oceanbase-ce-3.1.0 is available.
install oceanbase-ce-3.1.0 for local ok
+-----------------------------------------------------------------------------+
|                                   Packages                                  |
+--------------+---------+---------+------------------------------------------+
| Repository   | Version | Release | Md5                                      |
+--------------+---------+---------+------------------------------------------+
| oceanbase-ce | 3.1.0   | 2.el7   | afd11d52f83eef4b456d77969fde620c4bfba85e |
+--------------+---------+---------+------------------------------------------+
Open ssh connection ok
Remote oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e repository install ok
Remote oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e repository lib check !!
[WARN] 127.0.0.1 oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e require: libmariadb.so.3
[WARN] 127.0.0.1 oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e require: libaio.so.1
Try to get lib-repository
Package oceanbase-ce-libs-3.1.0 is available.
install oceanbase-ce-libs-3.1.0 for local ok
Use oceanbase-ce-libs-3.1.0-47300ca1ac4c62493caf3e9235b105e242e533b5 for oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e
Remote oceanbase-ce-libs-3.1.0-47300ca1ac4c62493caf3e9235b105e242e533b5 repository install ok
Remote oceanbase-ce-3.1.0-afd11d52f83eef4b456d77969fde620c4bfba85e repository lib check ok
Cluster status check ok
127.0.0.1 initializes cluster work home
mini-ce deployed
start ob cluster ...
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)
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.0   | 2881 | zone1 | active |
+-----------+---------+------+-------+--------+
mini-ce running
generate init_tenant.sql ...
init tenant and sysbench database ...
boot success!

四、链接OceanBase

frank@frank:~$ mycli -h172.17.0.2 -uroot@sys -P2881
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Anonymous
mysql root@sys@172.17.0.2:(none)> show databases;                                                                                                                                          
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set
Time: 0.012s
mysql root@sys@172.17.0.2:(none)>  

五、创建资源单元、资源池、租户

frank@frank:~$ mycli -h172.17.0.2 -uroot@sys -P2881 
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Magnus udd
mysql root@sys@172.17.0.2:(none)> create resource unit ocp_unit min_cpu=3, max_cpu=3, min_memory=1073741824, max_memory=1073741824, max_iops=256, min_iops=128, max_disk_size=1000000000, max_session_num=64;
mysql root@sys@172.17.0.2:(none)> create resource pool ocp_frank unit='ocp_unit', zone_list=('zone1'), unit_num=1;                                                                         
Query OK, 0 rows affected
Time: 0.010s
mysql root@sys@172.17.0.2:(none)> create tenant frank resource_pool_list = ('ocp_frank') set variables ob_compatibility_mode='mysql', ob_tcp_invited_nodes='%';                            
Query OK, 0 rows affected
Time: 1.002s
mysql root@sys@172.17.0.2:(none)> 

六、创建用户

frank@frank:~$ mycli -h172.17.0.2 -uroot@frank -P2881
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - zer09
mysql root@frank@172.17.0.2:(none)> create user ob_user identified by '123456';                                                                                                            
Query OK, 0 rows affected
Time: 0.021s
mysql root@frank@172.17.0.2:(none)> exit                                                                                                                                                   
Goodbye!
frank@frank:~$ mycli -h172.17.0.2 -uob_user@frank -P2881 -p123456
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Angelo Lupo
mysql ob_user@frank@172.17.0.2:(none)> 

七、创建业务库

frank@frank:~$ mycli -h172.17.0.2 -uroot@frank -P2881
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Chris Anderton
mysql root@frank@172.17.0.2:(none)> create database obtest;                                                                                                                                
Query OK, 1 row affected
Time: 0.023s
mysql root@frank@172.17.0.2:(none)> show databases;                                                                                                                                        
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
| obtest             |
+--------------------+
5 rows in set
Time: 0.007s
mysql root@frank@172.17.0.2:(none)> grant all privileges on *.* to 'ob_user'@'%' with grant option;                                                                                        
Query OK, 0 rows affected
Time: 0.018

八、建表

frank@frank:~$ mycli -h172.17.0.2 -uob_user@frank -P2881 -p123456
mysql 3.1.0
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Matheus Rosa
mysql ob_user@frank@172.17.0.2:(none)> show databases;                                                                                                                                     
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
| obtest             |
+--------------------+
5 rows in set
Time: 0.008s
mysql ob_user@frank@172.17.0.2:(none)> use obtest;                                                                                                                                         
You are now connected to database "obtest" as user "ob_user@frank"
Time: 0.005s
mysql ob_user@frank@172.17.0.2:obtest> CREATE TABLE t1(c1 INT PRIMARY KEY, c2 INT, c3 INT, c4 INT,  INDEX k1(c2,c3));                                                                      
Query OK, 0 rows affected
Time: 0.069s
mysql ob_user@frank@172.17.0.2:obtest> CREATE TABLE t2(c1 INT, c2 INT);                                                                                                                    
Query OK, 0 rows affected
Time: 0.050s
mysql ob_user@frank@172.17.0.2:obtest> INSERT INTO t2 VALUES(1, 1);                                                                                                                        
Query OK, 1 row affected
Time: 0.017s
mysql ob_user@frank@172.17.0.2:obtest> INSERT INTO t2 VALUES(3, 3);                                                                                                                        
Query OK, 1 row affected
Time: 0.005s
mysql ob_user@frank@172.17.0.2:obtest> INSERT INTO t2 VALUES(5, 5);                                                                                                                        
Query OK, 1 row affected
Time: 0.006s
mysql ob_user@frank@172.17.0.2:obtest> select * from t2;                                                                                                                                   
+----+----+
| c1 | c2 |
+----+----+
| 1  | 1  |
| 3  | 3  |
| 5  | 5  |
+----+----+
3 rows in set
Time: 0.012s

九、问题

由于使用PC环境虚拟机,整个过程主要的问题都集中在资源上,CPU、内存、硬盘在各实践阶段都出现了不同程度的问题,以下记录几个典型问题:
  1. 启动observer是失败,提示硬盘剩余空间不足(<5G):解决方式,通过虚拟机设置扩充存储。
  2. 创建资源池时,‘(4624, " machine resource ‘zone1’ is not enough to hold a new unit")’:经排查,CPU数量、内存/磁盘空间后,定位CPU可数已经超过了物理CPU个数。通过下面SQL分析资源使用情况,并进行调整。
    SELECT * FROM __all_unit_config;
    SELECT * FROM __all_resource_pool;
    SELECT * FROM __all_tenant;
    – 减少已有资源池中CPU使用个数
    ALTER RESOURCE UNIT obmysql min_cpu 2, MAX_CPU 2
  3. 删除租户时并重建时,报租户已存在:经查,删除租户默认会放入回收箱,使用FORCE 即刻删除。
    DROP TENANT t1 FORCE;

十、总结

整个过程相对顺利,大部分遇到的问题都是资源问题,不得不说OB对资源的要求还是比较高的,想单机玩一玩需要注意资源上可能会遇到一些坑。通过以上的实践,对基本的OB安装、部署、创建租户/用户等操作有了一个比较直观的认识,后续还有很多内容值得学习,期待~~~

你可能感兴趣的:(OceanBase,docker,ubuntu,linux,oceanbase)