OceanBase Docker 初体验

内存需求

内存10G,OB需要8G,4个逻辑CPU

卸载docker组件

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

安装docker的工具包

yum install -y yum-utils

创建docker仓库

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装docker

yum install docker-ce docker-ce-cli containerd.io

#报错信息
---> Package docker-compose-plugin.x86_64 0:2.24.7-1.el7 will be installed
--> Finished Dependency Resolution
Error: Package: 3:docker-ce-25.0.4-1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-25.0.4-1.el7.x86_64 (docker-ce-stable)
           Requires: fuse-overlayfs >= 0.7
Error: Package: containerd.io-1.6.28-3.1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-25.0.4-1.el7.x86_64 (docker-ce-stable)
           Requires: slirp4netns >= 0.4
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
 
 
 
 #查看linux版本
[root@innodb-cluster01 ~]# uname -r
5.4.17-2102.201.3.el7uek.x86_64

#使用下载rpm并安装
[root@ccl ~]# wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
[root@ccl ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm


#确认docker安装成功
[root@innodb-cluster01 ~]# docker --version
Docker version 17.09.0-ce, build afdb6d4

启动docker

 systemctl  start docker

搜索ob镜像

docker search oceanbase

拉取最新镜像

docker pull obpilot/oceanbase-ce

启动实例

docker run -p 2881:2881 -p 2883:2883 --name obce -itd -m 10G obpilot/oceanbase-ce:latest

查看进程

docker ps


CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                                                                NAMES
b6317918ab43        obpilot/oceanbase-ce:latest   "/bin/bash"         54 seconds ago      Up 46 seconds       0.0.0.0:2881->2881/tcp, 3000/tcp, 0.0.0.0:2883->2883/tcp, 9090/tcp   obce

可以查看容器启动日志

docker logs -f obce

进入容器

docker exec -it obce bash

获取集群信息

obd cluster list


[admin@b6317918ab43 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+

使用odb工具启动集群

# obd cluster start <deploy name> [-s]

[admin@b6317918ab43 ~]$ obd cluster start obdemo
Get local repositories ok
Search plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) clog and data use the same disk (/)

Check before start obproxy ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster |
Initialize cluster ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize cluster ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -prootPWD123 -Doceanbase

+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -prootPWD123 -Doceanbase
obdemo running

查看集群状态

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 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -prootPWD123 -Doceanbase

Connect to obproxy ok
+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -prootPWD123 -Doceanbase
[admin@b6317918ab43 ~]$ 

查看集群配置

cat /home/admin/.obd/cluster/obdemo/config.yaml

获取初始密码

[admin@b6317918ab43 ~]$ grep -E "root_password|appname|cluster_name" /home/admin/.obd/cluster/obdemo/config.yaml 
    # observer cluster name, consistent with obproxy's cluster_name
    appname: obdemo
    root_password: rootPWD123 # root user password, can be empty
    # observer cluster name, consistent with oceanbase-ce's appname. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.
    # cluster_name: obcluster

使用客户端进入数据库

[admin@b6317918ab43 ~]$ obclient -P2881 -h127.1 -uroot -p  
Enter password: 
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487632
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:56:31)

Copyright (c) 2000, 2018, OB Corporation Ab and others.

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

obclient [(none)]> 

查看已有的资源规格

USE oceanbase;
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_UNIT_CONFIGS;
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
| UNIT_CONFIG_ID | NAME            | CREATE_TIME                | MODIFY_TIME                | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
|              1 | sys_unit_config | 2024-03-08 11:16:11.941333 | 2024-03-08 11:16:11.941333 |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
1 row in set (0.002 sec)

创建资源规格

CREATE RESOURCE UNIT S1_unit_config
                MEMORY_SIZE = '3G',
                MAX_CPU = 1, MIN_CPU = 1,
                LOG_DISK_SIZE = '2G',
                MAX_IOPS = 10000, MIN_IOPS = 10000, IOPS_WEIGHT=1;

查看资源池信息

USE oceanbase;
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_RESOURCE_POOLS;
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-----------+--------------+
| RESOURCE_POOL_ID | NAME     | TENANT_ID | CREATE_TIME                | MODIFY_TIME                | UNIT_COUNT | UNIT_CONFIG_ID | ZONE_LIST | REPLICA_TYPE |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-----------+--------------+
|                1 | sys_pool |         1 | 2024-03-08 11:16:12.008158 | 2024-03-08 11:16:12.032219 |          1 |              1 | zone1     | FULL         |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-----------+--------------+
1 row in set (0.003 sec)

创建资源池

CREATE RESOURCE POOL mq_pool_01 
 UNIT='S1_unit_config', 
 UNIT_NUM=1; 

查看租户信息

obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_TENANTS;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME                | MODIFY_TIME                | PRIMARY_ZONE | LOCALITY      | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+
|         1 | sys         | SYS         | 2024-03-08 11:16:12.047096 | 2024-03-08 11:16:12.047096 | RANDOM       | FULL{1}@zone1 | NULL              | MYSQL              | NORMAL | NO            | NO     |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+
1 row in set (0.003 sec)

创建租户

obclient [oceanbase]> CREATE TENANT IF NOT EXISTS mq_t1 
    ->                 PRIMARY_ZONE='zone1', 
    ->                 RESOURCE_POOL_LIST=('mq_pool_01')
    ->                 set OB_TCP_INVITED_NODES='%';
Query OK, 0 rows affected (17.005 sec)

使用新租户进入数据库

[admin@b6317918ab43 ~]$ obclient -P2881 -h127.1 -uroot@mq_t1 -A
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487639
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:56:31)

Copyright (c) 2000, 2018, OB Corporation Ab and others.

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

obclient [(none)]> 

创建数据库

obclient [(none)]> create database db1;

Query OK, 1 row affected (0.137 sec)

创建表

obclient [db1]> create table t1(co1 int,co2 int);
Query OK, 0 rows affected (0.204 sec)
posted @   ideal_x  阅读(121)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示