OceanBase Docker 体验(一)

2024年 5月 7日 46.1k 0

1 系统版本和docker 版本信息

[root@db02 ~#]cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@db02 ~#]docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-32.git88a4867.el7.centos.x86_64
Go version: go1.7.4
Git commit: 88a4867/1.12.6
Built: Mon Jul 3 16:02:02 2017
OS/Arch: linux/amd64

Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-32.git88a4867.el7.centos.x86_64
Go version: go1.7.4
Git commit: 88a4867/1.12.6
Built: Mon Jul 3 16:02:02 2017
OS/Arch: linux/amd64

2 系统内存不低于10G,否则observer启动报错!!

[root@db01 ~]# docker exec -it oceanbase-ce bash
[admin@72fc9534d496 ~]$ obd cluster list
+------------------------------------------------------------+
| Cluster List |
+--------+---------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed |
+--------+---------------------------------+-----------------+
[admin@72fc9534d496 ~]$ obd cluster start obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer x
[WARN] (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[ERROR] (127.0.0.1) not enough memory. (Free: 1.3G, Need: 8.0G)
Check before start obproxy ok

3 镜像下载

我把相关镜像推送到阿里云,如果docker.io速度慢可以尝试使用一下阿里云地址:

registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase-ce
registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/obce-mini

#默认下载地址docker.io速度可能有点慢
[root@db01 ~]# docker pull obpilot/oceanbase-ce:latest

#阿里云镜像加速,下载地址
[root@db01 ~]# docker pull registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase-ce
latest: Pulling from registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase                                                                                        -ce

116a30ad4fce: Pull complete
0571080d28be: Pull complete
e01ece42daf0: Pull complete
a58f568417e7: Pull complete
e92e6c0d6402: Pull complete
63df6fe0b40d: Pull complete
3b3748f7eb9b: Pull complete
6b7932b19a6b: Pull complete
9bd570a5383f: Already exists
1f260b789676: Already exists
ba1cc918537d: Already exists
47d2d6c8103f: Already exists
2b79aad78c09: Already exists
c7e888f3edad: Already exists
Digest: sha256:c187435240a266278ad141138eaef83fc6807534f07d0b6c35650e03ef7cab07
Status: Downloaded newer image for registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase-ce:latest

4 启动镜像

#检查镜像信息
[root@db01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase-ce latest 6b7932b19a6b 4 days ago 2.254 GB

#启动镜像
[root@db01 ~]# docker run -itd -m 10G --name oceanbase-ce registry.cn-zhangjiakou.aliyuncs.com/snowofsummer/oceanbase-ce
72fc9534d4960c3961c8a59c203c8d31c5724eeefda4900a4f3a35a054f32757
#登陆容器, 并初始化集群
[root@db01 ~#]docker exec -it oceanbase-ce bash
[admin@5498fffaa097 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
[admin@5498fffaa097 ~]$ 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 value of fs.aio-max-nr is 1048576 (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@5498fffaa097 ~]$

OceanBase Docker 体验(一)-1

#状态检查:
[admin@5498fffaa097 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | running         |
+--------+---------------------------------+-----------------+
[admin@5498fffaa097 ~]$ 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 |
+-----------+------+-----------------+--------+
[admin@5498fffaa097 ~]$

OceanBase Docker 体验(一)-2

5 登陆数据库并创建租户和数据库和表

5.1查看密码和集群名称

容器数据库使用了obd自动部署了1台observer和1台obproxy。

查看数据库密码:

odb配置文件位置:/home/admin/.obd/cluster/obdemo

从配置文件查看root密码为rootPWD123。

[admin@5498fffaa097 obdemo]$ cat config.yaml |grep password
# password: your password if need
root_password: rootPWD123 # root user password, can be empty
proxyro_password: proxyROPWD123 # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty
obproxy_sys_password: proxySYSPWD123 # obproxy sys user password, can be empty
observer_sys_password: proxyROPWD123 # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be empty

集群名称:obce-single

[admin@5498fffaa097 obdemo]$ cat config.yaml |grep appname
appname: obce-single
# observer cluster name, consistent with oceanbase-ce's appname
[admin@5498fffaa097 obdemo]$ cat config.yaml |grep cluster
cluster_id: 1
# observer cluster name, consistent with obproxy's cluster_name
enable_cluster_checkout: false
# observer cluster name, consistent with oceanbase-ce's appname
cluster_name: obce-single

5.2 登陆数据库

集群管理员为root@sys

通过obproxy登陆,端口2883 (用户名称@租户#集群名称)

[admin@5498fffaa097 obdemo]$ 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]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set (0.007 sec)

MySQL [oceanbase]>

直连OBSERVER,端口2881 (用户名称@租户)

[admin@5498fffaa097 obdemo]$ obclient -h127.1 -uroot -P2881 -prootPWD123 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 3221487857
Server version: 5.7.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 databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set (0.004 sec)

ob初始化完成之后,使用sys@root登陆数据库,进行相关管理工作。

6 新建租户,数据库,表

新建租户obmysql

obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A 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;

登陆obmysql租户:默认密码为空

建立测试表。

[admin@5498fffaa097 obdemo]$ 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 9
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]>
MySQL [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.002 sec)

MySQL [test]> source bmsql.sql
Query OK, 1 row affected (0.034 sec)

Query OK, 0 rows affected (0.054 sec)

Query OK, 0 rows affected (0.023 sec)

Query OK, 0 rows affected (0.038 sec)

+-----------------+------------+---------------+
| Tablegroup_name | Table_name | Database_name |
+-----------------+------------+---------------+
| oceanbase       | NULL       | NULL          |
| tpcc_group      | NULL       | NULL          |
+-----------------+------------+---------------+
2 rows in set (0.034 sec)

+----------------------------------------------+
| Grants for tpcc@%                            |
+----------------------------------------------+
| GRANT USAGE ON *.* TO 'tpcc'                 |
| GRANT SELECT ON `oceanbase`.* TO 'tpcc'      |
| GRANT ALL PRIVILEGES ON `tpccdb`.* TO 'tpcc' |
+----------------------------------------------+
3 rows in set (0.072 sec)

Database changed
Query OK, 0 rows affected (0.145 sec)

Query OK, 0 rows affected (0.040 sec)

Query OK, 0 rows affected (0.078 sec)

Query OK, 0 rows affected (0.158 sec)

Query OK, 0 rows affected (0.209 sec)

Query OK, 0 rows affected (0.213 sec)

Query OK, 0 rows affected (0.312 sec)

Query OK, 0 rows affected (0.370 sec)

Query OK, 0 rows affected (0.242 sec)

Query OK, 0 rows affected (0.234 sec)

Query OK, 0 rows affected (0.177 sec)

Query OK, 0 rows affected (0.183 sec)

MySQL [tpccdb]>

7 ob启停命令

停止

[admin@5498fffaa097 ~]$ obd cluster stop obdemp
[ERROR] No such deploy: obdemp.
[admin@5498fffaa097 ~]$ obd cluster stop obdemo
Get local repositories and plugins ok
Open ssh connection ok
Stop observer ok
Stop obproxy ok
obdemo stopped

启动

[admin@5498fffaa097 ~]$ 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 value of fs.aio-max-nr is 1048576 (Current value: 65536)

Check before start obproxy ok
Start observer ok
observer program health 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 |
+-----------+---------+------+-------+--------+

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

8 obd配置文件信息

[admin@5498fffaa097 ~]$ cat /home/admin/.obd/cluster/obdemo/config.yaml
## Only need to configure when remote login is required
# user:
#   username: your username
#   password: your password if need
#   key_file: your ssh-key file path if need
#   port: your ssh port, default 22
#   timeout: ssh connection timeout (second), default 30
oceanbase-ce:servers:# Please don't use hostname, only IP can be supported- 127.0.0.1global:#  The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.home_path: /home/admin/oceanbase-ce# The directory for data storage. The default value is $home_path/store.# data_dir: /data/1# The directory for clog, ilog, and slog. The default value is the same as the data_dir value.redo_dir: /data/log1# Please set devname as the network adaptor's name whose ip is  in the setting of severs.# if set severs as "127.0.0.1", please set devname as "lo"# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"devname: lomysql_port: 2881 # External port for OceanBase Database. The default value is 2881.rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882.zone: zone1cluster_id: 1# please set memory limit to a suitable value which is matching resource.memory_limit: 8G # The maximum running memory for an observersystem_memory: 4G # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.stack_size: 512Kcpu_count: 16cache_wash_threshold: 1G__min_full_resource_pool_memory: 268435456workers_per_cpu_quota: 10schema_history_expire_time: 1d# The value of net_thread_count had better be same as cpu's core number.net_thread_count: 4major_freeze_duty_time: Disableminor_freeze_times: 10enable_separate_sys_clog: 0enable_merge_by_turn: FALSE#datafile_disk_percentage: 20 # The percentage of the data_dir space to the total disk space. This value takes effect only when datafile_size is 0. The default value is 90.datafile_size: 5Gsyslog_level: ERROR # System log level. The default value is INFO.enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.enable_syslog_recycle: true # Enable auto system log recycling or not. The default value is false.max_syslog_file_count: 4 # The maximum number of reserved log files before enabling auto recycling. The default value is 0.# observer cluster name, consistent with obproxy's cluster_nameappname: obce-singleroot_password: rootPWD123 # root user password, can be emptyproxyro_password:  proxyROPWD123 # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty
obproxy:servers:- 127.0.0.1depends:- oceanbase-ceglobal:listen_port: 2883 # External port. The default value is 2883.prometheus_listen_port: 2884 # The Prometheus port. The default value is 2884.home_path: /home/admin/obproxy# oceanbase root server list# format: ip:mysql_port,ip:mysql_portrs_list: 127.0.0.1:2881enable_cluster_checkout: false# observer cluster name, consistent with oceanbase-ce's appnamecluster_name: obce-singleobproxy_sys_password:  proxySYSPWD123 # obproxy sys user password, can be emptyobserver_sys_password: proxyROPWD123 # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be emptyautomatic_match_work_thread: falsework_thread_num: 12xflush_log_level: ERRORmonitor_log_level: ERRORsyslog_level: ERRORlog_dir_size_threshold: 1Genable_compression_protocol: false

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论