通过docker容器部署oceanbase单机版测试

本文件介绍通过docker容器部署oceanbase单机测试版,以了解oceanbase的基本运行机制。

1、在可以联网的服务器上准备镜像
bash 复制代码
[root@localhost dockerimages]# docker pull oceanbase/oceanbase-ce    
Using default tag: latest
latest: Pulling from oceanbase/oceanbase-ce
bf5ec1942180: Pull complete 
d3b8d3efa035: Pull complete 
9a3f60e016b0: Pull complete 
243997d3d8b2: Pull complete 
23d39df551a8: Pull complete 
93f13dfaf800: Pull complete 
4f4fb700ef54: Pull complete 
Digest: sha256:e0451ccf8b602d90119cfc85e3084a7978f46e202da8fe957a58d1f46a61de1a
Status: Downloaded newer image for oceanbase/oceanbase-ce:latest
[root@localhost dockerimages]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
oceanbase/oceanbase-ce           latest              e20691ae2edd        11 days ago         662MB
[root@localhost dockerimages]# docker save -o oceanbase-ce.tar oceanbase/oceanbase-ce
[root@localhost dockerimages]# ll
总用量 57G
-rw-------  1 root root 641M  4月 11 09:06 oceanbase-ce.tar

保存镜像为oceanbase-ce.tar文件,以下操作在内网生产机上执行。

2、编写运行文件

本例将oceanbase的端口从2881映射为3306,便于mysql环境开发的应用程序连接

bash 复制代码
[root@localhost dockerfile]# pwd
/app/oceanbase/dockerfile
[root@localhost dockerfile]# vi 0_docker_run.sh
docker run -p 3306:2881 -v /app/oceanbase/dockerdata/ob:/root/ob -v /app/oceanbase/dockerdata/obd:/root/.obd --name 
oceanbase -e MODE=normal -e FASTBOOT=true -d oceanbase/oceanbase-ce
~                                                                  
3、准备数据存储目录
bash 复制代码
[root@localhost dockerfile]# mkdir /app/oceanbase/dockerdata/ob
[root@localhost dockerfile]# mkdir /app/oceanbase/dockerdata/obd
[root@localhost dockerfile]# tree /app       
/app
└── oceanbase
    ├── dockerdata
    │   ├── ob
    │   └── obd
    └── dockerfile
        ├── 0_docker_run.sh
        └── oceanbase-ce.tar
4、安装docker运行环境
bash 复制代码
[root@localhost dockerfile]# yum install docker
Last metadata expiration check: 1:47:04 ago on 2024年04月11日 星期四 09时42分58秒.
Dependencies resolved.
====================================================================================================================
 Package                    Architecture        Version                         Repository                     Size
====================================================================================================================
Installing:
 docker-engine              x86_64              18.09.0-300.oe2203              openEuler2203LTS               37 M
Installing dependencies:
 libcgroup                  x86_64              0.42.2-1.oe2203                 openEuler2203LTS               97 k

Transaction Summary
====================================================================================================================
Install  2 Packages

Total download size: 37 M
Installed size: 154 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): libcgroup-0.42.2-1.oe2203.x86_64.rpm                                         7.3 MB/s |  97 kB     00:00    
(2/2): docker-engine-18.09.0-300.oe2203.x86_64.rpm                                   70 MB/s |  37 MB     00:00    
--------------------------------------------------------------------------------------------------------------------
Total                                                                                69 MB/s |  37 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Running scriptlet: libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Installing       : libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Running scriptlet: libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Installing       : docker-engine-18.09.0-300.oe2203.x86_64                                                    2/2 
  Running scriptlet: docker-engine-18.09.0-300.oe2203.x86_64                                                    2/2 
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

  Verifying        : docker-engine-18.09.0-300.oe2203.x86_64                                                    1/2 
  Verifying        : libcgroup-0.42.2-1.oe2203.x86_64                                                           2/2 

Installed:
  docker-engine-18.09.0-300.oe2203.x86_64                      libcgroup-0.42.2-1.oe2203.x86_64                     

Complete!
5、导入步骤保存的镜像文件
bash 复制代码
[root@localhost dockerfile]# docker load -i oceanbase-ce.tar 
8dff2b73bdd5: Loading layer [==================================================>]  226.5MB/226.5MB
f39658e6cbc6: Loading layer [==================================================>]  286.1MB/286.1MB
0f7de1da77d2: Loading layer [==================================================>]  1.536kB/1.536kB
31d4a89eb7d9: Loading layer [==================================================>]  151.1MB/151.1MB
11fddd0ccdc4: Loading layer [==================================================>]  8.355MB/8.355MB
d4796d1899b0: Loading layer [==================================================>]  12.29kB/12.29kB
5f70bf18a086: Loading layer [==================================================>]  1.024kB/1.024kB
Loaded image: oceanbase/oceanbase-ce:latest
[root@localhost dockerfile]# 
6、执行容器生脚本

生成容器并检查容器运行状态,测试服务端口开放情况:

bash 复制代码
[root@localhost dockerfile]# sh 0_docker_run.sh              
d53ad21d1a70a0439574d6539850055b71455d526ed0b7cb55b8fc107fbce785
[root@localhost dockerfile]# cat ../dockerdata/obd/version   
2.7.0[root@localhost dockerfile]# docker ps
CONTAINER ID        IMAGE                    COMMAND              CREATED             STATUS              PORTS                    NAMES
d53ad21d1a70        oceanbase/oceanbase-ce   "/bin/sh -c _boot"   2 minutes ago       Up 2 minutes        0.0.0.0:3306->2881/tcp   oceanbase
[root@localhost dockerfile]# telnet 127.0.0.1 3306
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
[root@localhost dockerfile]#
7、检查容器运行日志

最后一行为"boot success!"即表示容器运行正常

bash 复制代码
[root@localhost dockerfile]# docker logs oceanbase | tail -1
boot success!
8、直接连接到容器内数据查看当前有哪些数据库
bash 复制代码
[root@localhost dockerfile]# docker exec -it oceanbase ob-mysql sys 
login as root@sys
Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881 
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487743
Server version: OceanBase_CE 4.3.0.1 (r100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9) (Built Mar 22 2024 13:19:48)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ocs                |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
8 rows in set (0.026 sec)

obclient [oceanbase]>exit
9、交互式登录,查看集群清单,可见容器默认生成的集群名为obcluster
bash 复制代码
[root@localhost dockerfile]# docker exec -it  oceanbase bash   
[root@d53ad21d1a70 ~]# obd cluster list 
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
Trace ID: 2180594c-f7cb-11ee-b84b-0242ac110002
If you want to view detailed obd logs, please run: obd display-trace 2180594c-f7cb-11ee-b84b-0242ac110002
[root@d53ad21d1a70 ~]# exit
exit
10、安装mysql客户端连接测试并修改root用户密码
bash 复制代码
[root@localhost dockerfile]# yum install mysql
Last metadata expiration check: 0:13:10 ago on 2024年04月11日 星期四 13时49分03秒.
Dependencies resolved.
====================================================================================================================
 Package                    Architecture       Version                           Repository                    Size
====================================================================================================================
Installing:
 mysql                      x86_64             8.0.28-1.oe2203                   openEuler2203LTS              10 M
Installing dependencies:
 mariadb-config             x86_64             4:10.5.10-3.oe2203                openEuler2203LTS             9.1 k
 mysql-common               x86_64             8.0.28-1.oe2203                   openEuler2203LTS              30 k

Transaction Summary
====================================================================================================================
Install  3 Packages

Total download size: 10 M
Installed size: 59 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): mariadb-config-10.5.10-3.oe2203.x86_64.rpm                                   380 kB/s | 9.1 kB     00:00    
(2/3): mysql-common-8.0.28-1.oe2203.x86_64.rpm                                      807 kB/s |  30 kB     00:00    
(3/3): mysql-8.0.28-1.oe2203.x86_64.rpm                                              48 MB/s |  10 MB     00:00    
--------------------------------------------------------------------------------------------------------------------
Total                                                                                44 MB/s |  10 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Installing       : mariadb-config-4:10.5.10-3.oe2203.x86_64                                                   1/3 
  Installing       : mysql-common-8.0.28-1.oe2203.x86_64                                                        2/3 
  Installing       : mysql-8.0.28-1.oe2203.x86_64                                                               3/3 
  Running scriptlet: mysql-8.0.28-1.oe2203.x86_64                                                               3/3 
  Verifying        : mariadb-config-4:10.5.10-3.oe2203.x86_64                                                   1/3 
  Verifying        : mysql-8.0.28-1.oe2203.x86_64                                                               2/3 
  Verifying        : mysql-common-8.0.28-1.oe2203.x86_64                                                        3/3 

Installed:
  mariadb-config-4:10.5.10-3.oe2203.x86_64    mysql-8.0.28-1.oe2203.x86_64    mysql-common-8.0.28-1.oe2203.x86_64   

Complete!
[root@localhost dockerfile]# mysql -uroot -h127.0.0.1 -P3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487750
Server version: 5.7.25 OceanBase_CE 4.3.0.1 (r100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9) (Built Mar 22 2024 13:19:48)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ocs                |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
8 rows in set (0.00 sec)

mysql> ALTER USER root IDENTIFIED BY '******';
Query OK, 0 rows affected (0.63 sec)
mysql> exit
Bye
12、查看oceanbase库的租户和表情况
bash 复制代码
mysql> 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
mysql> SELECT * FROM DBA_OB_TENANTS;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+----------+------------+-----------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME                | MODIFY_TIME                | PRIMARY_ZONE | LOCALITY      | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED | TENANT_ROLE | SWITCHOVER_STATUS | SWITCHOVER_EPOCH | SYNC_SCN            | REPLAYABLE_SCN      | READABLE_SCN        | RECOVERY_UNTIL_SCN  | LOG_MODE     | ARBITRATION_SERVICE_STATUS | UNIT_NUM | COMPATIBLE | MAX_LS_ID |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+----------+------------+-----------+
|         1 | sys         | SYS         | 2024-03-30 15:43:11.938501 | 2024-03-30 15:43:11.938501 | RANDOM       | FULL{1}@zone1 | NULL              | MYSQL              | NORMAL | NO            | NO     | PRIMARY     | NORMAL            |                0 |                NULL |                NULL |                NULL |                NULL | NOARCHIVELOG | DISABLED                   |        1 | 4.3.0.1    |         1 |
|      1001 | META$1002   | META        | 2024-03-30 15:43:19.789417 | 2024-03-30 15:43:36.491571 | RANDOM       | FULL{1}@zone1 | NULL              | MYSQL              | NORMAL | NO            | NO     | PRIMARY     | NORMAL            |                0 |                NULL |                NULL |                NULL |                NULL | NOARCHIVELOG | DISABLED                   |        1 | 4.3.0.1    |         1 |
|      1002 | test        | USER        | 2024-03-30 15:43:19.793521 | 2024-03-30 15:43:36.524407 | RANDOM       | FULL{1}@zone1 | NULL              | MYSQL              | NORMAL | NO            | NO     | PRIMARY     | NORMAL            |                0 | 1712817363037657389 | 1712817363037657389 | 1712817363037657389 | 4611686018427387903 | NOARCHIVELOG | DISABLED                   |        1 | 4.3.0.1    |      1001 |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+----------+------------+-----------+
3 rows in set (0.05 sec)

mysql> show tables;
+-------------------------------------------+
| Tables_in_oceanbase                       |
+-------------------------------------------+
| ALL_OB_EXTERNAL_TABLE_FILES               |
| CDB_INDEXES                               |
| CDB_INDEX_USAGE                           |
| CDB_IND_COLUMNS                           |
| CDB_IND_PARTITIONS                        |
| CDB_IND_SUBPARTITIONS                     |
| CDB_MVIEWS                                |
| CDB_MVIEW_LOGS                            |
| CDB_MVREF_CHANGE_STATS                    |
| CDB_MVREF_RUN_STATS                       |
| CDB_MVREF_STATS                           |
| CDB_MVREF_STATS_PARAMS                    |
| CDB_MVREF_STATS_SYS_DEFAULTS              |
| CDB_MVREF_STMT_STATS                      |
| CDB_OBJECTS                               |
| CDB_OB_ACCESS_POINT                       |
| CDB_OB_ARCHIVELOG                         |
| CDB_OB_ARCHIVELOG_PIECE_FILES             |
| CDB_OB_ARCHIVELOG_SUMMARY                 |
| CDB_OB_ARCHIVE_DEST                       |
| CDB_OB_AUTO_INCREMENT                     |
| CDB_OB_AUX_STATISTICS                     |
| CDB_OB_BACKUP_DELETE_JOBS                 |
......
| __wr_sysstat                              |
+-------------------------------------------+
640 rows in set (0.01 sec)

mysql> 

至此,初步测试完成。

相关推荐
小袁搬码8 分钟前
Windows中指定路径安装DockerDesktop
windows·docker·容器·docker desktop
qq_3129201133 分钟前
docker 部署 kvm 图形化管理工具 WebVirtMgr
运维·docker·容器
踏雪Vernon33 分钟前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
条纹布鲁斯2 小时前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
工业3D_大熊3 小时前
3D可视化引擎HOOPS Luminate场景图详解:形状的创建、销毁与管理
java·c++·3d·docker·c#·制造·数据可视化
szc17673 小时前
docker 相关命令
java·docker·jenkins
CP-DD4 小时前
Docker 容器化开发 应用
运维·docker·容器
Stark-C4 小时前
万物皆可Docker,在NAS上一键部署最新苹果MacOS 15系统
macos·docker·策略模式
老司机张师傅4 小时前
【微服务实战之Docker容器】第七章-Dockerfile解析
容器·dockerfile·虚悬镜像·docker学习
微信-since811924 小时前
[ruby on rails] 安装docker
后端·docker·ruby on rails