From 503e76dc7243235ce9f5fecc4dae0826f49985cd Mon Sep 17 00:00:00 2001 From: LINxiansheng Date: Wed, 7 Feb 2024 06:29:18 +0000 Subject: [PATCH] Docker optimization --- README.md | 2 +- README_CN.md | 2 +- tools/docker/standalone/Dockerfile | 15 ++++++++++++--- tools/docker/standalone/README-CN.md | 9 +++++++++ tools/docker/standalone/README.md | 11 ++++++++++- tools/docker/standalone/boot/_boot | 8 ++++++++ tools/docker/standalone/boot/_env | 3 ++- tools/docker/standalone/boot/boot-mini-tmp.yaml | 6 ++++-- tools/docker/standalone/boot/boot-tmp.yaml | 6 ++++-- .../docker/standalone/boot/ob-configserver.yaml | 7 +++++++ tools/docker/standalone/boot/obagent.yaml | 2 +- .../fast_boot_docker_build_prepare/Dockerfile | 17 ++++++++++++++--- 12 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 tools/docker/standalone/boot/ob-configserver.yaml diff --git a/README.md b/README.md index a97011337..5d5706ca8 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ obd demo ```shell # Deploy a mini standalone instance. - docker run -p 2881:2881 --name oceanbase-ce -e MINI_MODE=1 -d oceanbase/oceanbase-ce + docker run -p 2881:2881 --name oceanbase-ce -e MODE=mini -d oceanbase/oceanbase-ce ``` 2. Connect to the OceanBase Database instance: diff --git a/README_CN.md b/README_CN.md index 733a1cc47..2e66dac37 100644 --- a/README_CN.md +++ b/README_CN.md @@ -88,7 +88,7 @@ obd demo ```shell # 部署一个mini模式实例 - docker run -p 2881:2881 --name oceanbase-ce -e MINI_MODE=1 -d oceanbase/oceanbase-ce + docker run -p 2881:2881 --name oceanbase-ce -e MODE=mini -d oceanbase/oceanbase-ce ``` 2. 连接 OceanBase diff --git a/tools/docker/standalone/Dockerfile b/tools/docker/standalone/Dockerfile index f75113482..ab3a43315 100644 --- a/tools/docker/standalone/Dockerfile +++ b/tools/docker/standalone/Dockerfile @@ -6,13 +6,22 @@ ARG VERSION RUN yum install -y yum-utils && \ yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo && \ sed -i 's/$releasever/7/' /etc/yum.repos.d/OceanBase.repo && \ - yum install -y ob-deploy obclient ob-sysbench libaio && \ + yum install -y ob-deploy obclient ob-sysbench libaio bc libselinux-utils zip && \ rm -rf /usr/obd/mirror/remote/* && \ yum clean all -RUN mkdir -p /root/pkg && \ +ENV OBVersion=$VERSION +RUN if [ -z "${OBVersion}" ]; then \ + echo "VERSION is empty, then build the docker with latest rpm"; \ + VersionPre=`yum info oceanbase-ce | grep Version | awk '{print $3}'`; \ + Release=`yum info oceanbase-ce | grep Release | awk '{print $3}' | awk -F. '{print $1}'`; \ + OBVersion="${VersionPre}-${Release}"; \ + else \ + echo "build the docker with VERSION ${OBVersion}"; \ + fi && \ + mkdir -p /root/pkg && \ cd /root/pkg && \ - yum install -y --downloadonly --downloaddir=. oceanbase-ce-${VERSION}.el7 oceanbase-ce-libs-${VERSION}.el7 obagent && \ + yum install -y --downloadonly --downloaddir=. oceanbase-ce-${OBVersion}.el7 oceanbase-ce-libs-${OBVersion}.el7 obagent ob-configserver && \ rm -rf /usr/obd/mirror/remote/* && \ yum clean all diff --git a/tools/docker/standalone/README-CN.md b/tools/docker/standalone/README-CN.md index 51fa7fc91..11c7909d6 100644 --- a/tools/docker/standalone/README-CN.md +++ b/tools/docker/standalone/README-CN.md @@ -123,3 +123,12 @@ docker -v 参数的详细说明可以参考 [docker volumn](https://docs.docker. - `./fast_boot_docker_build.sh ` 例如:`./fast_boot_docker_build.sh 4.2.1.0-100000102023092807` 等待构建完毕后,可使用前述相同的方式启动、测试实例。 + +## 故障诊断 +提供了一系列诊断方法用来诊断docker中的出错情况 +### 支持‘enable_rich_error_msg’参数 +- 首先在docker启动的过程中会默认开启‘enable_rich_error_msg’参数,如果在启动过程中发生错误,可以trace指令拿到更多的报错信息,启动成功后,docker会将该参数设置为关闭转态。 +- 用户可以通过打开该参数拿到更多运行阶段的sql语句的报错信息,打开方法为使用系统租户连接上docker中的oceanbase,然后执行 +```bash +alter system set enable_rich_error_msg = true; +``` diff --git a/tools/docker/standalone/README.md b/tools/docker/standalone/README.md index 4313f3a31..29eaeb397 100644 --- a/tools/docker/standalone/README.md +++ b/tools/docker/standalone/README.md @@ -118,4 +118,13 @@ After the modification is completed, execute the image build script: - `./fast_boot_docker_build.sh `. For example `./fast_boot_docker_build.sh 4.2.1.0-100000102023092807` -After waiting for the build to be completed, you can start and test the instance in the same way as mentioned above. \ No newline at end of file +After waiting for the build to be completed, you can start and test the instance in the same way as mentioned above. + +## Fault Diagnosis +A series of diagnostic methods are provided to diagnose errors in Docker. +### Support for 'enable_rich_error_msg' parameter +- Initially, the 'enable_rich_error_msg' parameter is enabled by default during the Docker startup process. If an error occurs during the startup process, more error information can be obtained using the trace command. After a successful startup, Docker sets this parameter to the false state. +- Users can open this parameter to obtain more error information about SQL statements during the runtime phase. The method to open it is to connect to Docker's oceanbase using the system tenant, and then execute the following command: +```bash +alter system set enable_rich_error_msg = true; +``` diff --git a/tools/docker/standalone/boot/_boot b/tools/docker/standalone/boot/_boot index 2228fbc40..ee5cbce7d 100755 --- a/tools/docker/standalone/boot/_boot +++ b/tools/docker/standalone/boot/_boot @@ -2,6 +2,7 @@ CWD=$(cd `dirname $0`;pwd) cd "${CWD}" source _env +export HOST_IP_MODE=1 STAMP="$(date +%s)" STEP=1 @@ -142,6 +143,11 @@ else # nothing here, bootstrap cat obagent.yaml >> $TMPFILE fi + if [ "x${MODE}" != "xMINI" ] && [ "x${MODE}" != "xSTANDALONE" ]; then + cat ob-configserver.yaml >> $TMPFILE + fi + + sed -i "s|@OB_SERVER_IP@|${OB_SERVER_IP}|g" $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 @@ -225,6 +231,8 @@ fi if [ $? -eq 0 ]; then echo "boot success!" + # close the enable_rich_error_msg + obclient -h127.1 -uroot@sys -A -P${OB_MYSQL_PORT} -e "alter system set enable_rich_error_msg = false;" else echo "boot failed!" if exit_while_error diff --git a/tools/docker/standalone/boot/_env b/tools/docker/standalone/boot/_env index 185b4df59..25cf09d34 100755 --- a/tools/docker/standalone/boot/_env +++ b/tools/docker/standalone/boot/_env @@ -1,6 +1,7 @@ -$MODE=${MODE:-MINI} +MODE=${MODE:-MINI} EXIT_WHILE_ERROR=${EXIT_WHILE_ERROR:-true} OB_HOME_PATH="/root/ob" +OB_SERVER_IP=$(hostname -i) OB_MYSQL_PORT="2881" OB_RPC_PORT="2882" OB_CLUSTER_NAME=${OB_CLUSTER_NAME:-obcluster} diff --git a/tools/docker/standalone/boot/boot-mini-tmp.yaml b/tools/docker/standalone/boot/boot-mini-tmp.yaml index e98f45d9a..b4819829f 100644 --- a/tools/docker/standalone/boot/boot-mini-tmp.yaml +++ b/tools/docker/standalone/boot/boot-mini-tmp.yaml @@ -1,11 +1,12 @@ oceanbase-ce: + depends: + - ob-configserver servers: # Please don't use hostname, only IP can be supported - - 127.0.0.1 + - @OB_SERVER_IP@ global: # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field. home_path: @OB_HOME_PATH@ - devname: lo mysql_port: @OB_MYSQL_PORT@ rpc_port: @OB_RPC_PORT@ zone: zone1 @@ -23,3 +24,4 @@ oceanbase-ce: max_syslog_file_count: 4 # The maximum number of reserved log files before enabling auto recycling. The default value is 0. appname: @OB_CLUSTER_NAME@ root_password: @OB_ROOT_PASSWORD@ + enable_rich_error_msg: true diff --git a/tools/docker/standalone/boot/boot-tmp.yaml b/tools/docker/standalone/boot/boot-tmp.yaml index f962ba506..74470882c 100644 --- a/tools/docker/standalone/boot/boot-tmp.yaml +++ b/tools/docker/standalone/boot/boot-tmp.yaml @@ -1,12 +1,14 @@ oceanbase-ce: + depends: + - ob-configserver servers: - - 127.0.0.1 + - @OB_SERVER_IP@ global: home_path: @OB_HOME_PATH@ - devname: lo mysql_port: @OB_MYSQL_PORT@ rpc_port: @OB_RPC_PORT@ datafile_size: 20G log_disk_size: 20G appname: @OB_CLUSTER_NAME@ root_password: @OB_ROOT_PASSWORD@ + enable_rich_error_msg: true diff --git a/tools/docker/standalone/boot/ob-configserver.yaml b/tools/docker/standalone/boot/ob-configserver.yaml new file mode 100644 index 000000000..9e914b1fc --- /dev/null +++ b/tools/docker/standalone/boot/ob-configserver.yaml @@ -0,0 +1,7 @@ +ob-configserver: + servers: + - @OB_SERVER_IP@ + global: + listen_port: 8080 + server_ip: 0.0.0.0 + home_path: /home/admin/obconfigserver \ No newline at end of file diff --git a/tools/docker/standalone/boot/obagent.yaml b/tools/docker/standalone/boot/obagent.yaml index c782c21b5..2feee8031 100644 --- a/tools/docker/standalone/boot/obagent.yaml +++ b/tools/docker/standalone/boot/obagent.yaml @@ -1,7 +1,7 @@ obagent: # The list of servers to be monitored. This list is consistent with the servers in oceanbase-ce. servers: - - 127.0.0.1 + - @OB_SERVER_IP@ # Set dependent components for the component. # When the associated configurations are not done, OBD will automatically get the these configurations from the dependent components. depends: diff --git a/tools/docker/standalone/fast_boot_docker_build_prepare/Dockerfile b/tools/docker/standalone/fast_boot_docker_build_prepare/Dockerfile index d7c550a6b..fcc858435 100644 --- a/tools/docker/standalone/fast_boot_docker_build_prepare/Dockerfile +++ b/tools/docker/standalone/fast_boot_docker_build_prepare/Dockerfile @@ -9,9 +9,18 @@ RUN yum install -y yum-utils && \ yum install -y libaio mysql && \ yum clean all -RUN mkdir -p /root/pkg && mkdir -p /root/store && mkdir -p /root/dest && \ +ENV OBVersion=$VERSION +RUN if [ -z "${OBVersion}" ]; then \ + echo "VERSION is empty, then build the docker with latest rpm"; \ + VersionPre=`yum info oceanbase-ce | grep Version | awk '{print $3}'`; \ + Release=`yum info oceanbase-ce | grep Release | awk '{print $3}' | awk -F. '{print $1}'`; \ + OBVersion="${VersionPre}-${Release}"; \ + else \ + echo "build the docker with VERSION ${OBVersion}"; \ + fi && \ + mkdir -p /root/pkg && mkdir -p /root/store && mkdir -p /root/dest && \ cd /root/pkg && \ - yum install -y --downloadonly --downloaddir=. oceanbase-ce-${VERSION}.el7 oceanbase-ce-libs-${VERSION}.el7 && \ + yum install -y --downloadonly --downloaddir=. oceanbase-ce-${OBVersion}.el7 oceanbase-ce-libs-${OBVersion}.el7 && \ rm -rf /usr/obd/mirror/remote/* && \ yum clean all @@ -21,4 +30,6 @@ ENV PATH /root/boot:$PATH ENV LD_LIBRARY_PATH /home/admin/oceanbase/lib:/root/ob/lib:$LD_LIBRARY_PATH WORKDIR /root -CMD _boot \ No newline at end of file +CMD _boot + +EXPOSE 2881 \ No newline at end of file