实验要求
练习目的
本次练习目的是通过 OceanBase Docker 容器,快速的体验 OceanBase 的 自动化部署过程,以及了解 OceanBase 集群安装成功后的目录特点和使用方法。
练习条件
有笔记本或服务器,内存至少12G 。
操作系统不限,能安装 Docker 环境即可。
练习内容
请记录并分享下列内容:
(必选)下载Docker 镜像:Docker Hub 。
(必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
(必选)创建一个业务租户、一个业务数据库,以及一些表等。
参考资料
社区版官网-文档-学习中心-入门教程:实战教程第二章2.2:如何快速体验 OceanBase
社区版官网-博客-入门实战:实战教程第二章2.2:如何快速体验 OceanBase
社区版官网-问答:OceanBase CE 容器下载使用简介
练习要求
请用文章记录实践练习的环境、过程和问题(可选)、总结等,图文并茂。如果企业内部有安全限制,可以对 IP 、 密码等打码或者修改。如果不允许截图,可以用文字适当补充说明。
分享的文章行文语句通顺,有条理,字数不少于 500 字。
发布:OceanBase 社区版官网问答区或社区版博客(准备word 版本稿件给运营 @Hope,钉钉:hopelee21@dingtalk.com),也可以在优快云、开源中国、Itpub、知乎等技术社区发布,在问答区附上作业链接及简要说明。
评分
OBCP考试券获取说明
OceanBase 入门到实战教程总共有 6 个练习,完成必选的 4 个练习,表示你掌握教程分享的学习技能,可以结业,并赠送全额 OBCP 考试券。本次练习为必选练习,请同学们积极参与哦~
其他
后期运营会针对同学的分享进行优秀评选,符合作业奖励规则的同学会给予积分奖励。
优秀作品 OceanBase 会在官方渠道实名推广。
我们欢迎同学们通过提 Issue、提交Pull Request 等方式参与 OceanBase github 社区 贡献。
实践过程如下:
宿主机信息
笔记本基本信息: MacBook Pro 10.15.7/ Intel i7 3.1 GHz/16G/500G VMware Fusion 12.1.2 Guest OS:centos 7.9 12G内存 40G磁盘空间
安装Vmware Guest OS
参考:Mac上安装VMware Fusion和CentOS-7 - 云+社区 - 腾讯云 选择最小化安装即可
[admin@localhost ~]$ cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core)
内存
[root@localhost ~]# free -h total used free shared buff/cache available Mem: 12G 571M 11G 10M 372M 8.7G Swap: 9G 15M 9G
CPU
[admin@localhost ~]$ cat /proc/cpuinfo | grep processor processor : 0 processor : 1
修改为静态IP地址
设置静态IP地址与动态iIP差不多,也是要修改网卡配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33 (最后一个为网卡名称) (1)bootproto=static (2)onboot=yes (3)在最后加上几行,IP地址、子网掩码、网关、dns服务器
ONBOOT=yes IPADDR=192.168.122.175 NETMASK=255.255.255.0 GATEWAY=192.168.122.2 systemctl restart network
安装docker
安装docker软件,命令如下,详细可参考docker官网。
yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io
查找OceanBase镜像
[root@localhost ~]# docker search oceanbase NAME DESCRIPTION STARS OFFICIAL AUTOMATED oceanbase/oceanbase-xe OceanBase Database 2.2 Express Edition 4 oceanbase/oceanbase-ce OceanBase is open source now. This is the do… 4 oceanbase/obce-mini obce-mini is a mini standalone test image fo… 3 obpilot/oceanbase-ce 3 steps to run an OceanBase-CE docker in you… 3 oceanbase/obce-operator obce-operator 1 oceanbase/miniob miniob database competition 1 zibuyu886/oceanbase-ce-cluster OceanBase ce cluster 1 huweijie/oceanbase-ce-deploy 0 superbigfu/oceanbase 0 oceanbase/centos7 0 20220121/oceanbase 0 jimmyzhou623/oceanbase 0 hongweiqin/anolisos-oceanbase A tentative deploy of oceanbase. 0 stutiredboy/centos_ob Build environment for OceanBase 3.1 CE. Crea… 0 ggzzzzzzz/obce-mini oceanbase community edition 3.1.3 mini image 0
安装oceanbase-ce
拉取镜像并运行
# 拉取镜像 oceanbase-ce [root@localhost ~]# docker pull obpilot/oceanbase-ce:latest latest: Pulling from obpilot/oceanbase-ce Digest: sha256:7ac28415cf27ba19cb47acb67a55ebf9848ad73a63d80b7e2e85d653233dbaeb Status: Image is up to date for obpilot/oceanbase-ce:latest docker.io/obpilot/oceanbase-ce:latest # 运行docker镜像文件 [admin@localhost ~]$ docker run -itd -m 10G --name oceanbase-ce obpilot/oceanbase-ce:latest [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 341e7fc1b199 obpilot/oceanbase-ce:latest "/bin/bash" 6 seconds ago Up 5 seconds 2881/tcp, 2883/tcp oceanbase-ce
登录并启动oceanbase-ce
# 进入到容器内部-bash [admin@localhost ~]$ docker exec -it oceanbase-ce bash # 获取集群信息 [admin@341e7fc1b199 ~]$ obd cluster list +------------------------------------------------------------+ | Cluster List | +--------+---------------------------------+-----------------+ | Name | Configuration Path | Status (Cached) | +--------+---------------------------------+-----------------+ | obdemo | /home/admin/.obd/cluster/obdemo | deployed | +--------+---------------------------------+-----------------+ # 启动集群 [admin@31c842167372 ~]$ 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.3 | 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@31c842167372 ~]$ obd cluster display obdemo Get local repositories and plugins ok Open ssh connection ok Cluster status check ok Connect to observer ok Wait for observer init ok +---------------------------------------------+ | observer | +-----------+---------+------+-------+--------+ | ip | version | port | zone | status | +-----------+---------+------+-------+--------+ | 127.0.0.1 | 3.1.1 | 2881 | zone1 | active | +-----------+---------+------+-------+--------+ Connect to obproxy ok +---------------------------------------------+ | obproxy | +-----------+------+-----------------+--------+ | ip | port | prometheus_port | status | +-----------+------+-----------------+--------+ | 127.0.0.1 | 2883 | 2884 | active | +-----------+------+-----------------+--------+
创建MySQL租户
# 登录单节点 [admin@31c842167372 ~]$ obclient -h127.1 -uroot@sys -P2881 -prootPWD123 -c -A oceanbase Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 3221487704 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]> show parameters like 'cluster'; # 获取集群名称(obce-single),obproxy连接的时候会使用这个名称,而不是上面的obdemo。 +-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+ | zone | svr_type | svr_ip | svr_port | name | data_type | value | info | section | scope | source | edit_level | +-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+ | zone1 | observer | 127.0.0.1 | 2882 | cluster | NULL | obce-single | Name of the cluster | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE | +-------+----------+-----------+----------+---------+-----------+-------------+---------------------+----------+---------+---------+-------------------+ 1 row in set (0.009 sec) # 使用obproxy 2883端口登录 [admin@31c842167372 ~]$ 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 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 [oceanbase]>
创建租户
#命令汇总 alter resource unit sys_unit_config min_cpu=5; 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'; CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1; 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'; exit; # 执行过程记录 [admin@31c842167372 ~]$ 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 18 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]> MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu=5; Query OK, 0 rows affected (0.023 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.027 sec) MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1; Query OK, 0 rows affected (0.048 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 (2.374 sec) MySQL [oceanbase]> exit Bye
登录租户并创建业务数据库
[admin@31c842167372 ~]$ 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 23 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]> create database db1 ; Query OK, 1 row affected (0.077 sec)
创建测试用户
MySQL [test]> create user u1@'%' identified by 'u1' ; Query OK, 0 rows affected (0.093 sec) MySQL [test]> grant all privileges on *.* to u1@'%'; Query OK, 0 rows affected (0.067 sec)
创建测试表
# 使用业务用户 u1 登录 obmysql 租户 [admin@ffd94a946881 ~]$ obclient -h 127.1 -uu1@obmysql#obce-single -P2883 -pu1 -c -A db1 Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 26 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]> create table t1(id int) ; Query OK, 0 rows affected (0.241 sec) MySQL [test]> insert into t1 values(1) ; Query OK, 1 row affected (0.054 sec) MySQL [test]> select * from t1 ; +------+ | id | +------+ | 1 | +------+ 1 row in set (0.005 sec) MySQL [test]>
结论
-
由于这是初次进行OceanBase 体验,对于内存最少需要8G
-
随着对Oceanbase的深入学习,慢慢体验分布数据库的特性