练习内容
(必选)下载Docker 镜像:OceanBase 官方社区版镜像 55 。
(必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
(必选)创建一个业务租户、一个业务数据库,以及一些表等。
备注:第一次尝试使用docker安装OB,文章为个人测试过程记录以及个人理解,不一定正确,仅供参考。
安装前准备
主机配置
主机名 | ip | 配置 |
---|---|---|
competet-oecanbase | 192.179.4.212 | 16C/64G/1.5T |
安装docker环境
yum源已配置好,直接yum安装docker即可
yum -y install docker
启动docker服务,并设置成开机自启
[root@competet-oecanbase ~]# systemctl start docker
[root@competet-oecanbase ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@competet-oecanbase ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-10-20 18:38:54 CST; 13s ago
Docs: http://docs.docker.com
Main PID: 25543 (dockerd-current)
CGroup: /system.slice/docker.service
├─25543 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexe...
└─25555 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --...
Oct 20 18:38:53 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:53.022843318+08:00" level=info msg="libcontainerd: new containerd process, pid: 25555"
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.186819391+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.189190091+08:00" level=info msg="Loading containers: start."
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.328850676+08:00" level=info msg="Firewalld running: false"
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.444808707+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon opt...d IP address"
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.505595365+08:00" level=info msg="Loading containers: done."
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.540217754+08:00" level=info msg="Daemon has completed initialization"
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.540288579+08:00" level=info msg="Docker daemon" commit="7d71120/1.13.1" graphdriver=overlay2 version=1.13.1
Oct 20 18:38:54 competet-oecanbase dockerd-current[25543]: time="2022-10-20T18:38:54.552340619+08:00" level=info msg="API listen on /var/run/docker.sock"
Oct 20 18:38:54 competet-oecanbase systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
安装OceanBase
参考:https://www.oceanbase.com/docs/community-observer-cn-10000000000096600
[root@competet-oecanbase ~]# docker run -p 2881:2881 --name oceanbase-ce -d oceanbase/oceanbase-ce
[root@competet-oecanbase ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
769a593e1351 oceanbase/oceanbase-ce "/bin/sh -c _boot" 3 minutes ago Up 2 minutes 0.0.0.0:2881->2881/tcp oceanbase-ce
[root@competet-oecanbase ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/oceanbase/oceanbase-ce latest 4af946862346 3 months ago 558 MB
[root@competet-oecanbase ~]# docker logs oceanbase-ce |tail -1
boot success!
可能会用到的命令:
docker stop `docker ps -a -q`
docker rm `docker ps -a -q`
docker rmi `docker images -q`
下面的命令只用执行一个即可。
按照文档的描述,因为会创建一个test租户,这里会把给sys租户的资源除去之后剩下的资源都给到test租户。
如果选择mini应该是有另外一个小一点的资源规格,有机会再尝试。
连接OceanBase
#进入容器
[root@competet-oecanbase ~]# docker exec -it oceanbase-ce bash
#查看集群状态
[root@16073e6d087d ~]# obd cluster list
+------------------------------------------------------------+
| Cluster List |
+-----------+------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running |
+-----------+------------------------------+-----------------+
这个地方也是疑惑了很久,因为练习要求说安装完docker使用obd完成后面的集群部署,此时集群已经是running状态,代表集群已经部署完成且跑起来了。查询一些文档之后,怀疑应该是镜像不同的问题。
既然集群已经成功启动,接下来就创建租户、数据库和表。
创建租户
在容器内使用obclient客户端连接实例
[root@16073e6d087d ~]# obclient -h127.0.0.1 -u root -P 2881
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221487675
Server version: 5.7.25 OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)
Copyright (c) 2000, 2022, OceanBase and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| SYS |
| LBACSYS |
| ORAAUDITOR |
| test |
+--------------------+
7 rows in set (0.004 sec)
obclient [(none)]> use oceanbase;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
obclient [oceanbase]> select * from gv$tenant;
+-----------+-------------+-----------+--------------+----------------+---------------+-----------+---------------+
| tenant_id | tenant_name | zone_list | primary_zone | collation_type | info | read_only | locality |
+-----------+-------------+-----------+--------------+----------------+---------------+-----------+---------------+
| 1 | sys | zone1 | zone1 | 0 | system tenant | 0 | FULL{1}@zone1 |
| 1001 | test | zone1 | RANDOM | 0 | | 0 | FULL{1}@zone1 |
+-----------+-------------+-----------+--------------+----------------+---------------+-----------+---------------+
2 rows in set (0.003 sec)
通过视图gv$tenant可以看到,除了sys租户默认已经创建了一个test租户,并且资源已经分配完了。
obclient [oceanbase]> select * from gv$unit;
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
| unit_id | unit_config_id | unit_config_name | resource_pool_id | resource_pool_name | zone | tenant_id | tenant_name | svr_ip | svr_port | migrate_from_svr_ip | migrate_from_svr_port | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
| 1 | 1 | sys_unit_config | 1 | sys_pool | zone1 | 1 | sys | 127.0.0.1 | 2882 | | 0 | 5 | 2.5 | 8697308774 | 7247757312 | 10000 | 5000 | 10737418240 | 9223372036854775807 |
| 1001 | 1001 | test_unit | 1001 | test_pool | zone1 | 1001 | test | 127.0.0.1 | 2882 | | 0 | 11 | 11 | 20293720474 | 20293720474 | 128 | 128 | 10737418240 | 64 |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
2 rows in set (0.016 sec)
注意:一个资源池只能分配给一个租户,这里本来尝试把test_pool直接给mysql用的,发现不行。
为了熟悉步骤,遂删除test租户和对应资源,然后创建自己需要的obmysql租户和资源池。
#记得要使用force,不然无法删除资源池
obclient [oceanbase]> drop tenant test force;
Query OK, 0 rows affected (0.035 sec)
obclient [oceanbase]> drop resource pool test_pool;
Query OK, 0 rows affected (0.008 sec)
obclient [oceanbase]> drop resource unit test_unit;
Query OK, 0 rows affected (0.005 sec)
obclient [oceanbase]> CREATE resource unit mysql_unit max_cpu=4, min_cpu=4, max_memory='16G', min_memory='16G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='400G';
Query OK, 0 rows affected (0.010 sec)
obclient [oceanbase]> CREATE resource pool my_pool unit = 'mysql_unit', unit_num = 1;
Query OK, 0 rows affected (0.011 sec)
obclient [oceanbase]> create tenant obmysql resource_pool_list=('my_pool'), primary_zone='zone1',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (0.912 sec)
在obmysql租户下创建数据库db01及测试表course,插入几笔数据。文章来源:https://www.toymoban.com/news/detail-401117.html
obclient [(none)]> create database db01;
Query OK, 1 row affected (0.025 sec)
obclient [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| test |
| db01 |
+--------------------+
5 rows in set (0.003 sec)
obclient [(none)]> use db01;
Database changed
obclient [db01]> CREATE TABLE course (
-> cno varchar(5) NOT NULL,
-> cname varchar(50) NOT NULL,
-> tno char(3) NOT NULL,
-> PRIMARY KEY (cno)
-> );
Query OK, 0 rows affected (0.089 sec)
obclient [db01]> show tables;
+----------------+
| Tables_in_db01 |
+----------------+
| course |
+----------------+
1 row in set (0.002 sec)
obclient [db01]> INSERT INTO course VALUES ('3001','C语言实践','801');
Query OK, 1 row affected (0.009 sec)
obclient [db01]> INSERT INTO course VALUES ('3002','高等数学','802');
Query OK, 1 row affected (0.001 sec)
obclient [db01]> INSERT INTO course VALUES ('3003','数学分析','803');
Query OK, 1 row affected (0.002 sec)
obclient [db01]> INSERT INTO course VALUES ('3004','数据库原理','804');
Query OK, 1 row affected (0.001 sec)
obclient [db01]> INSERT INTO course VALUES ('3005','离散数学','805');
Query OK, 1 row affected (0.002 sec)
obclient [db01]> INSERT INTO course VALUES ('3006','大学英语','806');
Query OK, 1 row affected (0.001 sec)
obclient [db01]> INSERT INTO course VALUES ('3007','线性代数','807');
Query OK, 1 row affected (0.002 sec)
obclient [db01]> select * from course;
+------+-----------------+-----+
| cno | cname | tno |
+------+-----------------+-----+
| 3001 | C语言实践 | 801 |
| 3002 | 高等数学 | 802 |
| 3003 | 数学分析 | 803 |
| 3004 | 数据库原理 | 804 |
| 3005 | 离散数学 | 805 |
| 3006 | 大学英语 | 806 |
| 3007 | 线性代数 | 807 |
+------+-----------------+-----+
7 rows in set (0.002 sec)
测试感受:整体感觉使用docker安装OB是很简单方便的。如果对OB的架构和租户概念有一定了解,会更容易上手。文章来源地址https://www.toymoban.com/news/detail-401117.html
到了这里,关于实验1:通过Docker安装部署OceanBase的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!