OceanBase Docker 体验

 

安装前准备

使用docker安装ob

请确保宿主机的可用资源满足下面要求:

逻辑 CPU 不少于4个

可用内存不少于 10G,并且 docker 容器内存限制不少于10G

空间不少于10G

安装docker

配置docker安装的repo包

[root@db~]#yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

使用yum 安装docker,出现需要依赖包的问题,这时我配置的是远端的源来获取对应的依赖包。

[root@db ~]# yum install docker-ce docker-ce-cli containerd.io

 

[root@db ~]# cat /etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

[centos-extras]

name=Centos extras - $basearch

baseurl=http://mirror.centos.org/centos/7/extras/x86_64

enabled=1

gpgcheck=0

 

后续再通过yum进行安装即可。

Doceker常用命令

docker version      #显示docker的版本信息

docker info         #显示docker的系统信息,包括镜像和容器的数量

docker 命令 --help   #帮助命令

 

docker镜像查看

docker images

REPOSITORY                TAG       IMAGE ID       CREATED         SIZE

# 解释

REPOSITORY 镜像的仓库源

TAG        镜像的标签

IMAGE ID   镜像的创建时间

SIZE       镜像的大小

 

#可选项

Options:

  -a, --all             # 列出所有的镜像

  -q, --quiet           # 只显示镜像的ID

docker下载镜像

docker pull 镜像名[:tag]   #下载镜像

查找镜像

docker search oceanbase

docker删除镜像

docker rm -f 镜像id #删除指定的镜像

docker rm -f 镜像id 容器id 容器id #删除多个指定的镜像

docker rm -f $(docker images -aq) # 删除全部镜像

 

docker运行启动镜像

docker run [可选参数] image

 

#参数说明

--name="Name"   容器名字  tomcat01  tomcat02 用来区分容器

-d              以后台方式运行,ja nohub

-it             使用交互模式运行,进入容器查看内容

-p              指定容器的端口 -p 8080:8080

-p 主机端:容器端口   主机端口映射到容器端口 (常用)

 

列出当前正在运行的容器

docker ps 命令

            

-a   #列出当前正在运行的容器+带出历史运行过的容器

-n=? #显示最近创建的容器

-q   #只显示容器的编号

 

docker start 容器id     #启动容器

docker restart 容器id   #重起容器

docker stop 容器id      #停止当前正在运行的容器

docker kill 容器id      #强制停止当前容器

 

安装OB

可以先通过docker search搜索对应的镜像,然后选择一个镜像进行下载

[root@db ~]# docker pull obpilot/oceanbase-ce

Using default tag: 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

 

启动镜像,指定镜像名称及内存配置大小

[root@db ~]# docker run -itd -m 10G --name oceanbase-ce  obpilot/oceanbase-ce:latest

b8cf44f9d7d2e955d5c37be763b77ece9e8b08f5c711934581bd207d0489c663

查看镜像进程信息

[root@db ~]# docker ps  | grep oceanbase-ce

b8cf44f9d7d2   obpilot/oceanbase-ce:latest   "/bin/bash"   31 seconds ago   Up 30 seconds   2881/tcp, 2883/tcp   oceanbase-ce

[root@db ~]#

进入到docker内部容器

[root@db ~]# docker exec -it oceanbase-ce bash

[admin@b8cf44f9d7d2 ~]$

列出当前集群状态信息

[admin@b8cf44f9d7d2 ~]$ obd cluster list

+------------------------------------------------------------+

|                        Cluster List                        |

+--------+---------------------------------+-----------------+

| Name   | Configuration Path              | Status (Cached) |

+--------+---------------------------------+-----------------+

| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |

+--------+---------------------------------+-----------------+

启动集群

[admin@b8cf44f9d7d2 ~]$ 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

[admin@b8cf44f9d7d2 ~]$

显示对应集群状态信息

[admin@b8cf44f9d7d2 ~]$ 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 |

+-----------+------+-----------------+--------+

 新增租户

进入sys租户并且配置资源池新增普通租户

[admin@b8cf44f9d7d2 ~]$ 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=5;

Query OK, 0 rows affected (0.007 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.031 sec)

 

MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;

Query OK, 0 rows affected (0.042 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 (0.981 sec)

 

MySQL [oceanbase]>

 

使用普通租户连接数据库进去初始密码为空

[admin@b8cf44f9d7d2 ~]$ 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 7

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]> show databases;

+--------------------+

| Database           |

+--------------------+

| oceanbase          |

| information_schema |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.003 sec)

 

创建普通业务用户并赋权

MySQL [test]> create user user1 identified by 'user1';

Query OK, 0 rows affected (0.033 sec)

MySQL [test]> select user,host from mysql.user;

+------------+------+

| user       | host |

+------------+------+

| root       | %    |

| ORAAUDITOR | %    |

| user1      | %    |

+------------+------+

3 rows in set (0.017 sec)

 

MySQL [test]> GRANT ALL PRIVILEGES ON *.* TO user1@'%';

Query OK, 0 rows affected (0.018 sec)

 

MySQL [test]> create database db1;

Query OK, 1 row affected (0.026 sec)

 

通过普通业务用户连接指定数据库,并建表及业务操作。

[admin@b8cf44f9d7d2 ~]$ obclient -h 127.1 -uuser1@obmysql#obce-single  -P2883 -p -c -A db1

Enter password:

Welcome to the OceanBase.  Commands end with ; or \g.

Your MySQL connection id is 8

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 [db1]> create table t1(id int);

Query OK, 0 rows affected (0.079 sec)

 

MySQL [db1]> insert into t1 values(1),(2);

Query OK, 2 rows affected (0.022 sec)

Records: 2  Duplicates: 0  Warnings: 0

 

MySQL [db1]> select * from t1;

+------+

| id   |

+------+

|    1 |

|    2 |

+------+

2 rows in set (0.016 sec)

 

posted on 2022-04-22 15:30  昔日丶芳华  阅读(251)  评论(0编辑  收藏  举报