实践练习一

在一台CentOS7系统上,通过yum添加Docker仓库并安装最新版本的Docker。然后配置Docker镜像加速器,下载OceanBase的镜像。接着启动Docker服务,并确保其正常运行。使用Docker运行OceanBase镜像,分配10G内存以满足最低要求。在Docker容器内启动并管理OB集群,创建资源单元、资源池和MySQL兼容的租户,完成OceanBase数据库的初步配置和使用。
摘要由CSDN通过智能技术生成

一、环境信息
[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@localhost ~]# 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

[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# tee /etc/docker/daemon.json <<-‘EOF’

{
“registry-mirrors”: [“https://yxzrazem.mirror.aliyuncs.com”]
}
EOF
{
“registry-mirrors”: [“https://yxzrazem.mirror.aliyuncs.com”]
}
[root@localhost ~]#
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

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

[root@localhost ~]# 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@localhost ~]# docker images | grep oceanbase
obpilot/oceanbase-ce latest 943379e0b05b 10 months ago 2.25GB
[root@localhost ~]# docker run -itd -m 10G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest
1cb6a05746e9853bb8528c83ae0de3f344b88ec94d7739ade868cbb56db6d772
[root@localhost ~]# 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@localhost ~]# 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 © 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 © 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 © 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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值