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

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

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

练习内容
请记录并分享下列内容:

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

参考资料

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

练习要求
请用文章记录实践练习的环境、过程和问题(可选)、总结等,图文并茂。如果企业内部有安全限制,可以对 IP 、 密码等打码或者修改。如果不允许截图,可以用文字适当补充说明。
分享的文章行文语句通顺,有条理,字数不少于 500 字。
发布:OceanBase 社区版官网问答区或社区版博客(准备word 版本稿件给运营 @Hope,钉钉:hopelee21@dingtalk.com),也可以在CSDN、开源中国、Itpub、知乎等技术社区发布,在问答区附上作业链接及简要说明。

一、安装Docker并下载OceanBase官方社区版镜像

#下载docker,安装Docker要求内核版本高于3.10

[root@dm8 docker]# wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz

#解压压缩包

[root@dm8 docker]# tar -zxvf docker-20.10.9.tgz

#将解压docker目录下的所有文件移动到/usr/bin下

[root@dm8 docker]# mv docker/* /usr/bin/

#以systemd的方式管理docker

[root@dm8 docker]# cat > /usr/lib/systemd/system/docker.service << EOF
> [Unit]
> Description=Docker Application Container Engine
> Documentation=https://docs.docker.com
> After=network-online.target firewalld.service
> Wants=network-online.target
> [Service]
> Type=notify
> ExecStart=/usr/bin/dockerd
> ExecReload=/bin/kill -s HUP $MAINPID
> LimitNOFILE=infinity
> LimitNPROC=infinity
> LimitCORE=infinity
> TimeoutStartSec=0
> Delegate=yes
> KillMode=process
> Restart=on-failure
> StartLimitBurst=3
> StartLimitInterval=60s
> [Install]
> WantedBy=multi-user.target
> EOF
#配置镜像加速器
[root@dm8 docker]# mkdir -p /etc/docker
[root@dm8 docker]# tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
> }
> EOF
#启动docker并设置开机自启
systemctl daemon-reload
systemctl start docker
systemctl enable docker
#检查docker是否安装成功
[root@dm8 docker]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、使用OBD命令完成后续的OceanBase集群部署

#下载OceanBase镜像并启动
[root@dm8 docker]# docker search oceanbase
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oceanbase/oceanbase-ce             OceanBase is an open-source, distributed HTA…   11                   
obpilot/oceanbase-ce               3 steps to run an OceanBase-CE docker in you…   4                    
oceanbase/oceanbase-xe             OceanBase Database 2.2 Express Edition          4                    
oceanbase/obce-mini                obce-mini is a mini standalone test image fo…   3                    
oceanbase/miniob                   miniob database competition                     2                    
zibuyu886/oceanbase-ce-cluster     OceanBase ce cluster                            1                    
oceanbase/obce-operator            obce-operator                                   1                    
oceanbase/oceanbase-cloud-native                                                   0                    
oceanbase/obproxy-ce                                                               0                    
oceanbasedev/oceanbase-cn                                                          0                    
oceanbase/centos7                                                                  0                    
oceanbase/obagent                                                                  0                    
oceanbasedev/ob-operator                                                           0                    
oceanbasedev/obagent                                                               0                    
huweijie/oceanbase-ce-deploy                                                       0                    
oceanbase/ob-operator                                                              0                    
datatomdev/oceanbase                                                               0                    
superbigfu/oceanbase                                                               0                    
oceanbasedev/obproxy-ce                                                            0                    
hongxinsun/oceanbase-cn                                                            0                    
hnwyllmm/oceanbase-ce                                                              0                    
oceanbasedev/obproxy                                                               0                    
hnwyllmm/oceanbase-ce-x86                                                          0                    
oceanbasedev/create_tenant                                                         0                    
hnwyllmm/oceanbase-ce-aarch64                                                      0                    
[root@dm8 docker]# 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
#启动OceanBase Docker容器
[root@dm8 docker]# docker run -itd -m 15G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest
0510bd3dca82c09cb016a88d7d9ae9091b55f435d9154a78feb5016390ca870b
#检查进程
[root@dm8 docker]# docker ps
CONTAINER ID   IMAGE                         COMMAND       CREATED          STATUS          PORTS                                                                                  NAMES
904199e14348   obpilot/oceanbase-ce:latest   "/bin/bash"   14 minutes ago   Up 14 minutes   0.0.0.0:2881->2881/tcp, :::2881->2881/tcp, 0.0.0.0:2883->2883/tcp, :::2883->2883/tcp   oceanbase-ce
#进入到容器内部并查看集群列表
[root@dm8 docker]# docker exec -it oceanbase-ce bash
[admin@0510bd3dca82 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
#使用OBD命令执行集群初始化
[admin@0510bd3dca82 ~]$ obd cluster start obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
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
[admin@0510bd3dca82 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | running         |
+--------+---------------------------------+-----------------+

三、创建业务租户、业务数据库,表等

#登陆OceanBase并创建租户
[admin@0510bd3dca82 ~]$ 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 4
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=3,max_memory='2G',min_memory='2G',min_iops=10000;
CREATE resource unit ZEEOB1 max_cpu=2, min_cpu=2, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='100G'; 

MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu=3,max_memory='2G',min_memory='2G',min_iops=10000;
Query OK, 0 rows affected (0.015 sec)
MySQL [oceanbase]> CREATE resource unit ZEEOB1 max_cpu=2, min_cpu=2, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='100G'; 
Query OK, 0 rows affected (0.035 sec)
#创建资源池
CREATE resource pool pool_1 unit = 'ZEEOB1', unit_num = 1;
#创建租户
create tenant obmysql resource_pool_list=('pool_1'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
MySQL [oceanbase]> create tenant obmysql resource_pool_list=('pool_1'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (1.238 sec)

MySQL [oceanbase]> select * from oceanbase.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 | obmysql     | zone1     | RANDOM       |              0 | mysql tenant/instance |         0 | FULL{1}@zone1 |
+-----------+-------------+-----------+--------------+----------------+-----------------------+-----------+---------------+
2 rows in set (0.006 sec)
#登录刚刚创建的业务租户obmysql
obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A
#默认空密码
[admin@0510bd3dca82 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A
#创建数据库
MySQL [(none)]> create database mydb;
Query OK, 1 row affected (0.027 sec)
MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| mydb               |
+--------------------+
4 rows in set (0.003 sec
#创建业务用户并赋权
MySQL [(none)]> create user zee identified by "zee123";
Query OK, 0 rows affected (0.057 sec)
MySQL [(none)]> grant all privileges on mydb.* to zee;
Query OK, 0 rows affected (0.023 sec)
#业务用户登录
obclient -h 127.1 -uzee@obmysql#obce-single -P2883 -p -c -A
[admin@0510bd3dca82 ~]$ obclient -h 127.1 -uzee@obmysql#obce-single -P2883 -p -c -A mydb
Enter password: 
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 15
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 [mydb]> 

#创建业务表

CREATE TABLE `accountmoremenuinfo` (
  `id` INT DEFAULT NULL,
  `labelid` INT DEFAULT NULL,
  `customname` VARCHAR(1000) DEFAULT NULL,
  `icon` VARCHAR(1000) DEFAULT NULL,
  `isshow` CHAR(1) DEFAULT NULL,
  `url` VARCHAR(1000) DEFAULT NULL,
  `linkmode` CHAR(1) DEFAULT NULL,
  `type` VARCHAR(10) DEFAULT NULL,
  `shoposition` CHAR(1) DEFAULT NULL,
  `sortnum` INT DEFAULT NULL,
  `sType` VARCHAR(255) DEFAULT NULL,
  `iconType` VARCHAR(100) DEFAULT NULL,
  `iconFrom` VARCHAR(100) DEFAULT NULL,
  `iconImgSrc` VARCHAR(300) DEFAULT NULL
);

CREATE TABLE `actionexecutelog` (
  `id` INT NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `ACTIONID` TEXT,
  `ACTIONTYPE` INT DEFAULT NULL,
  `DATASHOWCOUNT` INT DEFAULT NULL,
  `CREATEDATE` VARCHAR(80) DEFAULT NULL,
  `CREATETIME` VARCHAR(64) DEFAULT NULL,
  `ModifyDate` VARCHAR(80) DEFAULT NULL,
  `ModifyTime` VARCHAR(64) DEFAULT NULL,
  `clientip` VARCHAR(256) DEFAULT NULL,
  `execresult` INT DEFAULT NULL,
  `actiondbid` VARCHAR(1000) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_0826_actiondbid` (`actiondbid`),
  KEY `idx_0826_createDate` (`CREATEDATE`)
) ;

CREATE TABLE `actionsetting` (
  `id` INT NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `ACTIONNAME` VARCHAR(1000) DEFAULT NULL,
  `ACTIONCLASS` TEXT,
  `TYPENAME` VARCHAR(160) DEFAULT NULL,
  `ACTIONSHOWNAME` VARCHAR(1000) DEFAULT NULL,
  `CREATEDATE` VARCHAR(80) DEFAULT NULL,
  `CREATETIME` VARCHAR(64) DEFAULT NULL,
  `MODIFYDATE` VARCHAR(80) DEFAULT NULL,
  `MODIFYTIME` VARCHAR(64) DEFAULT NULL,
  `javacode` TEXT,
  `uuid` VARCHAR(50) DEFAULT '0',
  `subcompanyid` INT DEFAULT NULL,
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=152 ;

MySQL [mydb]> show tables;
+---------------------+
| Tables_in_mydb      |
+---------------------+
| accountmoremenuinfo |
| actionexecutelog    |
| actionsetting       |
+---------------------+
3 rows in set (0.003 sec)

附:
常用 Docker 命令参考

查看docker版本

docker version

显示docker系统的信息

docker info

日志信息

docker logs
故障检查
service docker status
启动关闭docker
service docker start | stop
查看容器日志
docker logs -f <容器名orID>
关闭容器
docker stop 容器名称
docker ps
docker ps -l
清理不用的容器
docker container prune
docker rm 904199e14348
清理不用的镜像
docker image prune
清理不用的卷
docker volume prune *
日志信息 docker logs *
故障检查 service docker status

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值