support mount directory in container to host os
This commit is contained in:
@ -13,9 +13,6 @@ RUN mkdir /root/pkg && \
|
||||
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-${VERSION}.el7.x86_64.rpm -q && \
|
||||
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-libs-${VERSION}.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/
|
||||
|
@ -33,6 +33,8 @@ $ docker logs obstandalone | tail -1
|
||||
boot success!
|
||||
```
|
||||
|
||||
**WARNING:** 如果observer进程出现异常退出,容器不会自动退出。
|
||||
|
||||
## 连接 OceanBase 实例
|
||||
|
||||
oceanbase-standalone 镜像安装了 OceanBase 数据库客户端 obclient,并提供了默认连接脚本 ob-mysql。
|
||||
@ -70,6 +72,7 @@ mysql>
|
||||
变量名称 | 默认值 | 描述
|
||||
------- | ----- | ---
|
||||
MINI_MODE | false | OceanBase 数据库实例是否采用mini模式部署,该模式仅供研究、学习和评估使用,不适用于生产环境或性能测试场景。
|
||||
EXIT_WHILE_ERROR | true | OceanBase 如果启动失败,是否退出容器。比如初次run镜像失败,或start容器失败,可以将此参数设置为false,那么OB启动失败,也可以进入容器,查看OceanBase的运行日志,然后进行排查。
|
||||
OB_HOME_PATH | /root/ob | OceanBase 数据库实例的部署路径。
|
||||
OB_DATA_DIR | empty | OceanBase 数据库使用的数据存储路径。默认在部署路径下的 `store` 目录
|
||||
OB_REDO_DIR | empty | OceanBase 数据库使用的clog,ilog,slog路径。默认与数据存储路径一致。
|
||||
@ -82,9 +85,20 @@ OB_TENANT_NAME | test | OceanBase 数据库实例默认初始化的用户租户
|
||||
|
||||
## 运行 Sysbench 脚本
|
||||
|
||||
oceanbase-standalone 镜像默认安装了 Sysbench 工具,并进行了简单配置。您可以依次执行以下命令,使用默认配置运行 Sysbench 脚本。
|
||||
oceanbase-ce 镜像默认安装了 Sysbench 工具,并进行了简单配置。您可以依次执行以下命令,使用默认配置运行 Sysbench 脚本。
|
||||
|
||||
```bash
|
||||
docker exec -it obstandalone obd test sysbench [OB_CLUSTER_NAME]
|
||||
```
|
||||
|
||||
## 磁盘挂载
|
||||
如果想要将容器中的数据持久化保存下来,通常的做法是在`run` docker镜像时,使用 `-v /host/path:/container/path` 的方式将数据保存在宿主机上。
|
||||
oceanbase-ce镜像的数据库数据默认保存在/root/ob目录下。但是仅仅映射/root/ob目录,会导致新的镜像无法启动,因为oceanbase-ce镜像是使用[obd](https://github.com/oceanbase/obdeploy) 来管理集群的,新的镜像启动时,没有oceanbase的集群信息,所以需要同时挂载/root/ob和/root/.obd目录。
|
||||
挂载目录运行示例:
|
||||
|
||||
```bash
|
||||
docker run -d -p 2881:2881 -v $PWD/ob:/root/ob -v $PWD/obd:/root/.obd --name oceanbase oceanbase/oceanbase-ce
|
||||
```
|
||||
|
||||
注意需要按照实际情况调整自己的目录。
|
||||
docker -v 参数的详细说明可以参考 [docker volumn](https://docs.docker.com/storage/volumes/)
|
||||
|
@ -33,6 +33,8 @@ $ docker logs obstandalone | tail -1
|
||||
boot success!
|
||||
```
|
||||
|
||||
**WARNING:** the container will not exit while the process of observer exits.
|
||||
|
||||
## Connect to an OceanBase instance
|
||||
|
||||
oceanbase-standalone image contains obclient (OceanBase Database client) and the default connection script `ob-mysql`.
|
||||
@ -87,3 +89,17 @@ oceanbase-standalone image installs the Sysbench tool by default. And the Sysben
|
||||
docker exec -it obstandalone obd test sysbench [OB_CLUSTER_NAME]
|
||||
```
|
||||
|
||||
## Mount Volumn
|
||||
You can use `-v /host/path:/container/path` parameter in docker `run` command to save data in host os if you want to persistence the data of a container.
|
||||
|
||||
The docker image `oceanbase-ce` save the data to /root/ob directory default. You can not start a new docker image if you only bind the /root/ob directory, because the docker image oceanbase-ce use the [obd](https://github.com/oceanbase/obdeploy) to manage database clusters and there is no information about the database cluster after a new docker image started. So you should bind both the /root/ob and /root/.obd directory.
|
||||
|
||||
Below is an example.
|
||||
|
||||
```bash
|
||||
docker run -d -p 2881:2881 -v $PWD/ob:/root/ob -v $PWD/obd:/root/.obd --name oceanbase oceanbase/oceanbase-ce
|
||||
```
|
||||
|
||||
Note that you should use your own path.
|
||||
|
||||
You can view more information about `docker -v` at [docker volumn](https://docs.docker.com/storage/volumes/).
|
||||
|
@ -5,6 +5,17 @@ source _env
|
||||
|
||||
STAMP="$(date +%s)"
|
||||
|
||||
function is_true() {
|
||||
value=$1
|
||||
# convert value to upper case string(can work in bash 4.x)
|
||||
value=${value^^}
|
||||
|
||||
if [ "x${value}" == "xNO" ] || [ "x${value}" == "xFALSE" ] || [ "x${value}" == "x0" ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# return 0 if mini_mode is nil or 'no'/'false'/0
|
||||
# 0 means true and 1 for false in bash
|
||||
function is_mini_mode() {
|
||||
@ -12,13 +23,17 @@ function is_mini_mode() {
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return `is_true ${MINI_MODE}`
|
||||
}
|
||||
|
||||
# convert MINI_MODE to upper case string(can work in bash 4.x)
|
||||
mini_mode=${MINI_MODE^^}
|
||||
if [ "x${mini_mode}" == "xNO" ] || [ "x${mini_mode}" == "xFALSE" ] || [ "x${mini_mode}" == "x0" ]; then
|
||||
return 1
|
||||
function exit_while_error() {
|
||||
if test -z ${EXIT_WHILE_ERROR}
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
|
||||
return `is_true ${EXIT_WHILE_ERROR}`
|
||||
}
|
||||
|
||||
function remove_disk_check_logic_in_obd() {
|
||||
@ -29,7 +44,16 @@ function remove_disk_check_logic_in_obd() {
|
||||
sed -i "s/critical(EC_OBSERVER_NOT_ENOUGH_DISK_4_CLOG/alert(EC_OBSERVER_NOT_ENOUGH_DISK_4_CLOG/g" $start_check_file
|
||||
}
|
||||
|
||||
[[ -f boot.yaml ]] && echo "find boot.yaml, skip configuring..." || {
|
||||
# We should decide whether the observer's data exists and
|
||||
# whether the obd has the information of the cluster
|
||||
|
||||
if [ -f "$HOME/.obd/cluster/${OB_CLUSTER_NAME}/config.yaml" ]; then
|
||||
echo "find obd deploy information, skip configuring..."
|
||||
echo "start ob cluster ..."
|
||||
obd cluster start $OB_CLUSTER_NAME
|
||||
|
||||
else # nothing here, bootstrap
|
||||
|
||||
echo "generate boot.yaml ..."
|
||||
TMPFILE="boot.${STAMP}.yaml"
|
||||
|
||||
@ -51,14 +75,27 @@ function remove_disk_check_logic_in_obd() {
|
||||
echo "create boot dirs and deploy ob cluster ..."
|
||||
mkdir -p $OB_HOME_PATH
|
||||
|
||||
obd mirror clone /root/pkg/*.rpm \
|
||||
&& obd mirror list local
|
||||
|
||||
remove_disk_check_logic_in_obd
|
||||
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
|
||||
}
|
||||
&& mv -f $TMPFILE ${OB_HOME_PATH}/boot.yaml \
|
||||
&& echo "deploy success!"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "boot success!"
|
||||
else
|
||||
echo "boot failed!"
|
||||
if exit_while_error
|
||||
then
|
||||
exit 1
|
||||
else
|
||||
echo "Please check the log file ${OB_HOME_PATH}/log/observer.log"
|
||||
fi
|
||||
fi
|
||||
exec /sbin/init
|
||||
|
||||
[[ -f boot.yaml ]] && {
|
||||
echo "start ob cluster ..."
|
||||
obd cluster start $OB_CLUSTER_NAME
|
||||
} && echo "boot success!" && exec /sbin/init
|
||||
|
@ -1,7 +1,8 @@
|
||||
MINI_MODE=${MINI_MODE:-false}
|
||||
EXIT_WHILE_ERROR=${EXIT_WHILE_ERROR:-true}
|
||||
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"}
|
||||
OB_TENANT_NAME=${OB_TENANT_NAME:-"test"}
|
||||
|
Reference in New Issue
Block a user