暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

实践练习一(必选):OceanBase Docker 体验

原创 roycehwang 2022-10-19
269

练习目的

本次练习目的是通过 OceanBase Docker 容器,快速的体验 OceanBase 的 自动化部署过程,以及了解 OceanBase 集群安装成功后的目录特点和使用方法。

练习条件

  1. 有笔记本或服务器,内存至少12G 。
  2. 操作系统不限,能安装 Docker 环境即可。

练习内容

请记录并分享下列内容:

  1. (必选)下载Docker 镜像:OceanBase 官方社区版镜像 53 。
  2. (必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
  3. (必选)创建一个业务租户、一个业务数据库,以及一些表等。

参考资料

  1. 社区版官网-文档-学习中心-入门教程:实战教程第二章2.2:如何快速体验 OceanBase 81
  2. 社区版官网-博客-入门实战:实战教程第二章2.2:如何快速体验 OceanBase 28
  3. 社区版官网-问答:OceanBase CE 容器下载使用简介 12
  4. 教程视频:【2-2-OceanBase Docker 体验.mp4] 18

一、环境信息

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# free -g total used free shared buff/cache available Mem: 11 0 9 0 1 10 Swap: 4 0 4

二、安装Docker

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装Docker
[root@localhost ~]# yum -y install docker-ce docker-ce-cli containerd.io
验证
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker
 docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-10-19 18:51:46 CST; 4s ago
     Docs: https://docs.docker.com
 Main PID: 24242 (dockerd)
    Tasks: 7
   Memory: 27.8M
   CGroup: /system.slice/docker.service
           └─24242 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Oct 19 18:51:45 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:45.517319141+08:00" level=info msg="ccRes...=grpc
Oct 19 18:51:45 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:45.517325809+08:00" level=info msg="Clien...=grpc
Oct 19 18:51:45 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:45.539901314+08:00" level=info msg="Loadi...art."
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.390641200+08:00" level=info msg="Defau...ress"
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.537117001+08:00" level=info msg="Firew...ning"
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.731711787+08:00" level=info msg="Loadi...one."
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.784643369+08:00" level=info msg="Docke...10.18
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.785410265+08:00" level=info msg="Daemo...tion"
Oct 19 18:51:46 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Oct 19 18:51:46 localhost.localdomain dockerd[24242]: time="2022-10-19T18:51:46.878255001+08:00" level=info msg="API l...sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:14:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:12:21 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


三、下载OceanBase镜像

[root@10 ~]# docker pull obpilot/oceanbase-ce:latest
latest: Pulling from obpilot/oceanbase-ce
7a0437f04f83: Downloading [=>                                                 ]  2.163MB/75.18MB
615dc48ac9f1: Download complete
b10c1cdae3af: Downloading [>                                                  ]  3.763MB/836.3MB
4f4fb700ef54: Download complete
c0f6c94a6a6a: Download complete
792630f35e24: Waiting


由于国外Docker下载实在太慢,使用下列方法更换为阿里云的docker源

[root@10 ~]# mkdir -p /etc/docker
[root@10 ~]# tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://yxzrazem.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://yxzrazem.mirror.aliyuncs.com"]
}
[root@10 ~]#
[root@10 ~]# systemctl daemon-reload
[root@10 ~]# systemctl restart docker


此时下载就很快了,安装完成

[root@10 ~]# 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
792630f35e24: Pull complete
Digest: sha256:7ac28415cf27ba19cb47acb67a55ebf9848ad73a63d80b7e2e85d653233dbaeb
Status: Downloaded newer image for obpilot/oceanbase-ce:latest
docker.io/obpilot/oceanbase-ce:latest


启动镜像设置Docker资源,OB低于10G内存会报错

[root@10 ~]# docker images | grep oceanbase
obpilot/oceanbase-ce   latest    943379e0b05b   10 months ago   2.25GB
[root@10 ~]# docker run -itd -m 10G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest
1cb6a05746e9853bb8528c83ae0de3f344b88ec94d7739ade868cbb56db6d772
[root@10 ~]# docker ps -a
CONTAINER ID   IMAGE                         COMMAND       CREATED         STATUS         PORTS                                                                                  NAMES
1cb6a05746e9   obpilot/oceanbase-ce:latest   "/bin/bash"   8 seconds ago   Up 6 seconds   0.0.0.0:2881->2881/tcp, :::2881->2881/tcp, 0.0.0.0:2883->2883/tcp, :::2883->2883/tcp   oceanbase-ce


四、启动OB集群并创建租户

进入Docker镜像并使用OBD工具启动OB集群

[root@10 ~]# docker exec -it oceanbase-ce bash
[admin@1cb6a05746e9 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
[admin@1cb6a05746e9 ~]$ 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 number of open files is 655350 (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


登录OB数据库并创建MySQL租户

[admin@1cb6a05746e9 ~]$ 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 3
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;
Query OK, 0 rows affected (0.180 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.229 sec)

MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
Query OK, 0 rows affected (0.198 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 (22.710 sec)


登录OB MySQL租户

[admin@1cb6a05746e9 ~]$ 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 6
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]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.146 sec)


创建数据库和表等:

[admin@1cb6a05746e9 ~]$ 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 11
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]> source /tmp/test_db-master/employees.sql;

MySQL [employees]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
| royce              |
| world              |
| employees          |
+--------------------+
7 rows in set (0.014 sec)

MySQL [employees]> show tables;
+----------------------+
| Tables_in_employees  |
+----------------------+
| current_dept_emp     |
| departments          |
| dept_emp             |
| dept_emp_latest_date |
| dept_manager         |
| employees            |
| salaries             |
| titles               |
+----------------------+
8 rows in set (0.008 sec)


至此,练习一完成。


参考:

https://hub.docker.com/r/obpilot/oceanbase-ce

https://lhrbest.blog.csdn.net/article/details/122265834

最后修改时间:2022-10-19 23:45:44
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论