未验证 提交 f75f5992 编写于 作者: M MizuhaHimuraki 提交者: GitHub

add dockerfiles to build a simple image for oceanbase-ce (#295)

上级 23934c96
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 && mkdir /root/pkg && cd /root/pkg && rm -rf /usr/obd/mirror/remote/* && yumdownloader oceanbase-ce oceanbase-ce-libs && obd mirror clone *rpm && obd mirror list local && rm -rf * && yum clean all
COPY boot /root/boot/
ENV PATH /root/boot:$PATH
CMD _boot
# 如何使用这个镜像
部署 OceanBase 数据库的方式有很多,使用 Docker 是其中较方便的一种。本仓库提供了 OceanBase 数据库的 Docker 镜像 obce-mini。obce-mini 是 OceanBase 数据库社区版的小规格单机体验镜像,仅供研究、学习和评估使用,不适用于生产环境或性能测试场景。
## 前提条件
在部署 obce-mini 镜像之前,您需要确认以下信息:
- 确保您的机器至少提供 2 核 10GB 以上的资源。
- 您的机器已经安装以下程序:
应用程序 | 推荐版本 | 参考文档
--- | ------ | -----
Docker | 最新版 | [Docker 文档](https://docs.docker.com/get-docker/)
- 您的机器已经启动 Docker 服务。
## 启动 OceanBase 实例
运行以下命令,启动 OceanBase 的实例:
```bash
docker run -p 2881:2881 --name some-obce -d oceanbase/obce-mini
```
启动预计需要 2-5 分钟。执行以下命令,如果返回 `boot success!`,则启动成功。
```bash
$ docker logs some-obce | tail -1
boot success!
```
## 连接 OceanBase 实例
obce-mini 镜像安装了 OceanBase 数据库客户端 obclient,并提供了默认连接脚本 ob-mysql。
```bash
docker exec -it some-obce ob-mysql sys # 连接 sys 租户
docker exec -it some-obce ob-mysql root # 连接用户租户的 root 账户
docker exec -it some-obce ob-mysql test # 连接用户租户的 test 账户
```
您也可以运行以下命令,使用您本机的 obclient 或者 MySQL 客户端连接实例。
```bash
$mysql -uroot -h127.1 -P2881
```
连接成功后,终端将显示如下内容:
```mysql
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>
```
## 支持的环境变量
下表列出了当前版本的 obce-mini 镜像支持的环境变量:
变量名称 | 默认值 | 描述
------- | ----- | ---
OB_HOME_PATH | /root/ob | OceanBase 数据库实例的部署路径。
OB_MYSQL_PORT | 2881 | OceanBase 数据库实例的 MySQL 协议端口。
OB_RPC_PORT | 2882 | OceanBase 数据库实例的 RPC 通信端口。
OB_ROOT_PASSWORD | empty | OceanBase 数据库实例 sys 租户的密码。
OB_CLUSTER_NAME | mini-ce | OceanBase 数据库实例名称,OBD 将使用这个名称作为集群名。
OB_TENANT_NAME | test | OceanBase 数据库实例默认初始化的用户租户的名称。
## 运行 Sysbench 脚本
obce-mini 镜像默认安装了 Sysbench 工具,并进行了简单配置。您可以依次执行以下命令,使用默认配置运行 Sysbench 脚本。
```bash
docker exec -it some-obce sysbench cleanup # 清理数据
docker exec -it some-obce sysbench prepare # 准备数据
docker exec -it some-obce sysbench run # 进行测试
docker exec -it some-obce sysbench # 依次执行上述三条命令
```
# 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.
## Prerequisite
Before you deploy obce-mini 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
docker run -p 2881:2881 --name some-obce -d oceanbase/obce-mini
```
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 some-obce | tail -1
boot success!
```
## Connect to an OceanBase instance
obce-mini image contains obclient (OceanBase Database client) and the default connection script `ob-mysql`.
```bash
docker exec -it some-obce ob-mysql sys # Connect to sys tenant
docker exec -it some-obce ob-mysql root # Connect to the root account of a general tenant
docker exec -it some-obce 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 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>
```
## Supported environment variables
This table shows the supported environment variables of the current obce-mini mirror version:
Variable name | Default value | Description
------- | ----- | ---
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_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
obce-mini 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 some-obce sysbench cleanup # Clean the data
docker exec -it some-obce sysbench prepare # Prepare the data
docker exec -it some-obce sysbench run # Do the test
docker exec -it some-obce sysbench # Run the preceding three commands in order
```
#!/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"
cp -f boot-tmp.yaml $TMPFILE
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
echo "create boot dirs and deploy ob cluster ..."
mkdir -p $OB_HOME_PATH && obd cluster deploy "${OB_CLUSTER_NAME}" -c $TMPFILE && mv -f $TMPFILE boot.yaml
}
[[ -f boot.yaml ]] && {
echo "start ob cluster ..."
obd cluster restart $OB_CLUSTER_NAME
}
[[ -f init_tenant.sql ]] || {
echo "generate init_tenant.sql ..."
TMPSQL="init_tenant.${STAMP}.sql"
cp -f init_tenant-tmp.sql $TMPSQL
sed -i "s|@OB_TENANT_NAME@|${OB_TENANT_NAME}|g" $TMPSQL
if [[ "${OB_ROOT_PASSWORD}x" != "x" ]]; then
PASSCMD=-p${OB_ROOT_PASSWORD}
fi
echo "init tenant and sysbench database ..."
obclient -h127.1 -uroot@sys -A -Doceanbase -P${OB_MYSQL_PORT} ${PASSCMD} < $TMPSQL &&
obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql &&
mv -f ${TMPSQL} init_tenant.sql
} && echo "boot success!" && exec /sbin/init
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:-"mini-ce"}
OB_TENANT_NAME=${OB_TENANT_NAME:-"test"}
#FROM https://gitee.com/oceanbase/obdeploy/blob/master/example/mini-local-example.yaml
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: 10
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: 10s
large_query_threshold: 1s
clog_sync_time_warn_threshold: 2000ms
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@ # default: null
CREATE RESOURCE UNIT IF NOT EXISTS @OB_TENANT_NAME@ max_cpu = 9, max_memory = 2684354560, min_memory = 2684354560, max_iops = 10000, min_iops = 1280, max_session_num = 3000, max_disk_size = 5153960755;
CREATE RESOURCE POOL IF NOT EXISTS @OB_TENANT_NAME@ UNIT = '@OB_TENANT_NAME@', UNIT_NUM = 1, ZONE_LIST = ('zone1');
CREATE TENANT IF NOT EXISTS @OB_TENANT_NAME@ charset='utf8mb4', replica_num=1, zone_list=('zone1'), primary_zone='RANDOM', resource_pool_list=('@OB_TENANT_NAME@');
ALTER SYSTEM SET _clog_aggregation_buffer_amount = 4;
ALTER SYSTEM SET _flush_clog_aggregation_buffer_timeout = '1ms';
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES ob_timestamp_service = 'GTS';
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES autocommit = ON;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES ob_query_timeout = 36000000000;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES ob_trx_timeout = 36000000000;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES max_allowed_packet = 67108864;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES ob_sql_work_area_percentage = 100;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES parallel_max_servers = 20;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES parallel_servers_target = 48;
ALTER TENANT @OB_TENANT_NAME@ SET VARIABLES ob_tcp_invited_nodes='%'
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}
#!/bin/bash
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
source _env
cd /usr/sysbench/share/sysbench
export LD_LIBRARY_PATH=/u01/mysql/lib/
SYSBENCH=/usr/sysbench/bin/sysbench
SYSBENCH_SCRIPT=${SYSBENCH_SCRIPT:-"/usr/sysbench/share/sysbench/oltp_point_select.lua"}
SYSBENCH_TABLE_SIZE=${SYSBENCH_TABLE_SIZE:-20000}
SYSBENCH_TABLE_NUM=${SYSBENCH_TABLE_NUM:-32}
SYSBENCH_THREADS=${SYSBENCH_THREADS:-32}
SYSBENCH_REPORT_INTERVAL=${SYSBENCH_REPORT_INTERVAL:-2}
SYSBENCH_TIME=${SYSBENCH_TIME:-120}
SYSBENCH_CMD="${SYSBENCH} ${SYSBENCH_SCRIPT} --mysql-host=127.0.0.1 --mysql-port=${OB_MYSQL_PORT} --mysql-db=test --mysql-user=test@${OB_TENANT_NAME} --table_size=${SYSBENCH_TABLE_SIZE} --tables=${SYSBENCH_TABLE_NUM} --threads=${SYSBENCH_THREADS} --report-interval=${SYSBENCH_REPORT_INTERVAL} --time=${SYSBENCH_TIME}"
case "$1" in
cleanup)
set -x
${SYSBENCH_CMD} cleanup
;;
prepare)
set -x
${SYSBENCH_CMD} prepare
;;
run)
set -x
${SYSBENCH_CMD} --db-ps-mode=disable run
;;
*)
set -x
${SYSBENCH_CMD} cleanup
${SYSBENCH_CMD} prepare
${SYSBENCH_CMD} --db-ps-mode=disable run
;;
esac
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册