未验证 提交 b6b7da6b 编写于 作者: R Rongfeng Fu 提交者: GitHub

standalone (#853)

上级 3d79cacb
**当前镜像已不在维护,相关能力由 [standalone](../standalone/README-CN.md#启动-oceanbase-实例) 提供**
# 如何使用这个镜像
部署 OceanBase 数据库的方式有很多,使用 Docker 是其中较方便的一种。本仓库提供了 OceanBase 数据库的 Docker 镜像 obce-mini。obce-mini 是 OceanBase 数据库社区版的小规格单机体验镜像,仅供研究、学习和评估使用,不适用于生产环境或性能测试场景。
......
**This image is no longer maintained, and related capabilities are provided by [standalone](../standalone/README.md##start-an-oceanbase-instance)**
# How to use this image
You can deploy OceanBase databases by using many methods. But Docker is the easiest method. This repository gives you an obce-mini image for deploying OceanBase database by using Docker. obce-mini is a mini standalone test image for OceanBase Database Community Edition. You can use it only for research/study/evaluation. DO NOT use it for production or performance testing.
......
FROM oceanbase/centos7:latest
RUN yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo && \
yum install -y ob-deploy obclient ob-sysbench wget libaio && \
mkdir /root/pkg && \
cd /root/pkg && \
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-3.1.2-10000392021123010.el7.x86_64.rpm -q && \
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-libs-3.1.2-10000392021123010.el7.x86_64.rpm -q && \
rm -rf /usr/obd/mirror/remote/* && \
obd mirror clone *.rpm && \
obd mirror list local && \
rm -rf /root/base /root/pkg && \
yum clean all
COPY boot /root/boot/
ENV PATH /root/boot:$PATH
CMD _boot
# 如何使用这个镜像
部署 OceanBase 数据库的方式有很多,使用 Docker 是其中较方便的一种。本仓库提供了 OceanBase 数据库的 Docker 镜像 oceanbase-standalone。oceanbase-standalone 是 OceanBase 数据库的单机镜像。默认会根据当前容器情况部署最大规格的实例,也可以通过环境变量指定MINI MODE部署最小规格实例。
## 前提条件
在部署 oceanbase-standalone 镜像之前,您需要确认以下信息:
- 确保您的机器至少提供 2 核 10GB 以上的资源。
- 您的机器已经安装以下程序:
应用程序 | 推荐版本 | 参考文档
--- | ------ | -----
Docker | 最新版 | [Docker 文档](https://docs.docker.com/get-docker/)
- 您的机器已经启动 Docker 服务。
## 启动 OceanBase 实例
运行以下命令,启动 OceanBase 的实例:
```bash
# 根据当前容器情况部署最大规格的实例
docker run -p 2881:2881 --name obstandalone -d oceanbase/oceanbase-ce-standalone
# 部署最小规格实例
docker run -p 2881:2881 --name obstandalone -e MINI_MODE=1 -d oceanbase/oceanbase-ce-standalone
```
启动预计需要 2-5 分钟。执行以下命令,如果返回 `boot success!`,则启动成功。
```bash
$ docker logs obstandalone | tail -1
boot success!
```
## 连接 OceanBase 实例
oceanbase-standalone 镜像安装了 OceanBase 数据库客户端 obclient,并提供了默认连接脚本 ob-mysql。
```bash
docker exec -it obstandalone ob-mysql sys # 连接 sys 租户
docker exec -it obstandalone ob-mysql root # 连接用户租户的 root 账户
docker exec -it obstandalone ob-mysql test # 连接用户租户的 test 账户
```
您也可以运行以下命令,使用您本机的 obclient 或者 MySQL 客户端连接实例。
```bash
$mysql -uroot -h127.1 -P2881
```
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 167310
Server version: 5.7.25 OceanBase 3.1.0 (r-00672c3c730c3df6eef3b359eae548d8c2db5ea2) (Built Jun 22 2021 12:46:28)
Copyright (c) 2000, 2021, 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>
```
## 支持的环境变量
下表列出了当前版本的 oceanbase-standalone 镜像支持的环境变量:
变量名称 | 默认值 | 描述
------- | ----- | ---
MINI_MODE | false | OceanBase 数据库实例是否采用mini模式部署,该模式仅供研究、学习和评估使用,不适用于生产环境或性能测试场景。
OB_HOME_PATH | /root/ob | OceanBase 数据库实例的部署路径。
OB_DATA_DIR | empty | OceanBase 数据库使用的数据存储路径。默认在部署路径下的 `store` 目录
OB_REDO_DIR | empty | OceanBase 数据库使用的clog,ilog,slog路径。默认与数据存储路径一致。
OB_MYSQL_PORT | 2881 | OceanBase 数据库实例的 MySQL 协议端口。
OB_RPC_PORT | 2882 | OceanBase 数据库实例的 RPC 通信端口。
OB_ROOT_PASSWORD | empty | OceanBase 数据库实例 sys 租户的密码。
OB_CLUSTER_NAME | obcluster | OceanBase 数据库实例名称,OBD 将使用这个名称作为集群名。
OB_TENANT_NAME | test | OceanBase 数据库实例默认初始化的用户租户的名称。
## 运行 Sysbench 脚本
oceanbase-standalone 镜像默认安装了 Sysbench 工具,并进行了简单配置。您可以依次执行以下命令,使用默认配置运行 Sysbench 脚本。
```bash
docker exec -it obstandalone obd test sysbench [OB_CLUSTER_NAME]
```
# How to use this image
You can deploy OceanBase databases by using many methods. But Docker is the easiest method. This repository gives you an oceanbase-standalone image for deploying OceanBase database by using Docker. oceanbase-standalone is a standalone test image for OceanBase Database. By default, this image deploys an instance of the largest size according to the current container. You can also deploy a mini standalone instance through the environment variable MINI_MODE.
## Prerequisite
Before you deploy oceanbase-standalone image, do a check of these:
- Make sure that your machine has at least 2 physical core and 10GB memory.
- Your machine has installed these applications:
Application | Recommended version | Documentation
--- | ------ | -----
Docker | Latest | [Docker Documentation](https://docs.docker.com/get-docker/)
- You have started the Docker service on your machine.
## Start an OceanBase instance
To start an OceanBase instance, run this command:
```bash
# deploy an instance of the largest size according to the current container
docker run -p 2881:2881 --name obstandalone -d oceanbase/oceanbase-ce-standalone
# deploy mini standalone instance
docker run -p 2881:2881 --name obstandalone -e MINI_MODE=1 -d oceanbase/oceanbase-ce-standalone
```
Two to five minutes are necessary for the boot procedure. To make sure that the boot procedure is successful, run this command:
```bash
$ docker logs obstandalone | tail -1
boot success!
```
## Connect to an OceanBase instance
oceanbase-standalone image contains obclient (OceanBase Database client) and the default connection script `ob-mysql`.
```bash
docker exec -it obstandalone ob-mysql sys # Connect to sys tenant
docker exec -it obstandalone ob-mysql root # Connect to the root account of a general tenant
docker exec -it obstandalone ob-mysql test # Connect to the test account of a general tenant
```
Or you can run this command to connect to an OceanBase instance with your local obclient or MySQL client.
```bash
$mysql -uroot -h127.1 -P2881
```
When you connect to an OceanBase instance successfully, the terminal returns this message:
```mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 3221528373
Server version: 5.7.25 OceanBase 2.2.77 (r20211015104618-3510dfdb38c6b8d9c7e27747f82ccae4c8d560ee) (Built Oct 15 2021 11:19: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 [(none)]>
```
## Supported environment variables
This table shows the supported environment variables of the current oceanbase-standalone mirror version:
Variable name | Default value | Description
------- | ----- | ---
MINI_MODE | false | If ture, will use mini mode to deploy OceanBase Database instance, it should be used only for research/study/evaluation. DO NOT use it for production or performance testing.
OB_HOME_PATH | /root/ob | Home path for an OceanBase Database instance.
OB_MYSQL_PORT | 2881 | The MySQL protocol port for an OceanBase Database instance.
OB_DATA_DIR | empty | The directory for data storage. The default value is $OB_HOME_PATH/store.
OB_REDO_DIR | empty | The directory for clog, ilog, and slog. The default value is the same as the OB_DATA_DIR value.
OB_RPC_PORT | 2882 | The RPC communication port for an OceanBase Database instance.
OB_ROOT_PASSWORD | empty | The password for the system tenant in an OceanBase Database instance.
OB_CLUSTER_NAME | mini-ce | Instance name for OceanBase Database instance. OBD uses this value as its cluster name.
OB_TENANT_NAME | test | The default initialized general tenant name for an OceanBase Database instance.
## Run the Sysbench script
oceanbase-standalone image installs the Sysbench tool by default. And the Sysbench tool is configured. You can run these commands in sequence to run the Sysbench script with the default configurations.
```bash
docker exec -it obstandalone obd test sysbench [OB_CLUSTER_NAME]
```
#!/bin/bash
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
source _env
STAMP="$(date +%s)"
[[ -f boot.yaml ]] && echo "find boot.yaml, skip configuring..." || {
echo "generate boot.yaml ..."
TMPFILE="boot.${STAMP}.yaml"
if ${MINI_MODE}
then
cp -f boot-mini-tmp.yaml $TMPFILE
else
cp -f boot-tmp.yaml $TMPFILE
fi
sed -i "s|@OB_HOME_PATH@|${OB_HOME_PATH}|g" $TMPFILE
sed -i "s|@OB_MYSQL_PORT@|${OB_MYSQL_PORT}|g" $TMPFILE
sed -i "s|@OB_RPC_PORT@|${OB_RPC_PORT}|g" $TMPFILE
sed -i "s|@OB_ROOT_PASSWORD@|${OB_ROOT_PASSWORD}|g" $TMPFILE
[ "${OB_DATA_DIR}" ] && echo " data_dir: ${OB_DATA_DIR}" >> $TMPFILE
[ "${OB_REDO_DIR}" ] && echo " redo_dir: ${OB_REDO_DIR}" >> $TMPFILE
echo "create boot dirs and deploy ob cluster ..."
mkdir -p $OB_HOME_PATH
if ${MINI_MODE}
then
obd cluster deploy "${OB_CLUSTER_NAME}" -c $TMPFILE && obd cluster tenant create "${OB_CLUSTER_NAME}" -n ${OB_TENANT_NAME} && obd cluster start "${OB_CLUSTER_NAME}" && obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql && mv -f $TMPFILE boot.yaml
else
obd cluster autodeploy "${OB_CLUSTER_NAME}" -c $TMPFILE && obd cluster tenant create "${OB_CLUSTER_NAME}" -n ${OB_TENANT_NAME} && obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql && mv -f $TMPFILE boot.yaml
fi
}
[[ -f boot.yaml ]] && {
echo "start ob cluster ..."
obd cluster start $OB_CLUSTER_NAME
} && echo "boot success!" && exec /sbin/init
\ No newline at end of file
MINI_MODE=${MINI_MODE:-false}
OB_HOME_PATH=${OB_HOME_PATH:-"/root/ob"}
OB_MYSQL_PORT=${OB_MYSQL_PORT:-"2881"}
OB_RPC_PORT=${OB_RPC_PORT:-"2882"}
OB_ROOT_PASSWORD=${OB_ROOT_PASSWORD:-""}
OB_CLUSTER_NAME=${OB_CLUSTER_NAME:-"obcluster"}
OB_TENANT_NAME=${OB_TENANT_NAME:-"test"}
\ No newline at end of file
oceanbase-ce:
servers:
- 127.0.0.1
global:
home_path: @OB_HOME_PATH@ # default: /root/ob
devname: lo
mysql_port: @OB_MYSQL_PORT@ # default: 2881
rpc_port: @OB_RPC_PORT@ # default: 2882
zone: zone1
cluster_id: 1
memory_limit: 8G
system_memory: 4G
stack_size: 512K
cpu_count: 16
cache_wash_threshold: 1G
__min_full_resource_pool_memory: 268435456
workers_per_cpu_quota: 10
schema_history_expire_time: 1d
net_thread_count: 4
sys_bkgd_migration_retry_num: 3
minor_freeze_times: 100
enable_separate_sys_clog: 0
enable_merge_by_turn: FALSE
enable_auto_leader_switch: FALSE
enable_one_phase_commit: FALSE
weak_read_version_refresh_interval: 5s
trace_log_slow_query_watermark: 1s
large_query_threshold: 1s
clog_sync_time_warn_threshold: 1s
syslog_io_bandwidth_limit: 10M
enable_sql_audit: FALSE
enable_perf_event: FALSE
clog_max_unconfirmed_log_count: 5000
autoinc_cache_refresh_interval: 86400s
cpu_quota_concurrency: 2
datafile_size: 5G
syslog_level: WARN
enable_syslog_recycle: TRUE
max_syslog_file_count: 2
enable_early_lock_release: false tenant=all
default_compress_func: lz4_1.0
root_password: @OB_ROOT_PASSWORD@
clog_disk_utilization_threshold: 95
clog_disk_usage_limit_percentage: 98
oceanbase-ce:
servers:
- 127.0.0.1
global:
home_path: @OB_HOME_PATH@ # default: /root/ob
devname: lo
mysql_port: @OB_MYSQL_PORT@ # default: 2881
rpc_port: @OB_RPC_PORT@ # default: 2882
root_password: @OB_ROOT_PASSWORD@ # default: null
CREATE USER 'test'@'%';
GRANT ALL ON test.* TO 'test'@'%';
#!/bin/bash
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
source _env
PASSCMD=""
case "$1" in
sys)
LOGIN_USER="root@sys"
DB="oceanbase"
if [[ "${OB_ROOT_PASSWORD}x" != "x" ]]; then
PASSCMD=-p${OB_ROOT_PASSWORD}
fi
;;
root)
DB="oceanbase"
LOGIN_USER="root@${OB_TENANT_NAME}"
;;
*)
DB="test"
LOGIN_USER="test@${OB_TENANT_NAME}"
;;
esac
echo "login as ${LOGIN_USER}"
CMD="obclient -h127.1 -u${LOGIN_USER} -A -D${DB} -P${OB_MYSQL_PORT} ${PASSCMD}"
echo "Command is: ${CMD}"
${CMD}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册