通过该篇文章可以在国产X86-64或ARM架构上构建商业版oceanbase,只需要替换pkg安装包即可。下面截图主要以国产X86-64安装为例,作为操作截图:
镜像构建目录说明
pkg:用来存放安装包及脚本,抛出rpm其他是脚步,这些rpm包可以下载不同系统架构的包,构建镜像时该目录只需要保留对应架构包就行。
镜像文件说明
Dockerfile
FROM kylin-server-10-sp2-x86:b09
MAINTAINER weltestADD pkg /mnt/software/pkgENV OB_HOME_PATH=/home/admin/oceanbaseEXPOSE 2881 2882 RUN cd /mnt/software/pkg && yum clean all && yum makecache \&& yum install libaio net-tools -y && bash installDB && rm -rf /mnt && chmod 755 -R /home/admin/oceanbase/init/InitDB && chmod 755 -R /home/admin/oceanbase/sh/*WORKDIR /home/admin/oceanbaseCMD ["/bin/bash","-c","/home/admin/oceanbase/init/InitDB"]
这里未提供yum的repo文件,如果内网构建这里需要把RUN替换为如下内容:
RUN cd /mnt/software/pkg && rm -rf /etc/yum.repos.d/* && mv nexus-kylin-V10SP2.repo /etc/yum.repos.d/ && yum clean all && yum makecache \&& yum install libaio net-tools -y && bash installDB && rm -rf /mnt && chmod 755 -R /home/admin/oceanbase/init/InitDB && chmod 755 -R /home/admin/oceanbase/sh/*
installDB
Dockerfile中的bash installDB
执行脚步内容如下:
#!/bin/bash
set -e
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
source /mnt/software/pkg/_envecho "create data dirs..."
mkdir -p $OB_DATA_PATH/{1,log1}
echo "install ob cluster ..."
rpm -ivh /mnt/software/pkg/*.rpm --nodepsecho "Init ob dir..."
mkdir -p $OB_DATA_PATH/1/$OB_CLUSTER_NAME/{etc3,sort_dir,sstable,slog}
mkdir -p $OB_DATA_PATH/log1/$OB_CLUSTER_NAME/{clog,etc2,ilog,oob_clog}
mkdir -p $OB_HOME_PATH/store/$OB_CLUSTER_NAME
for t in {etc3,sort_dir,sstable,slog};do ln -s $OB_DATA_PATH/1/$OB_CLUSTER_NAME/$t $OB_HOME_PATH/store/$OB_CLUSTER_NAME/$t; done
for t in {clog,etc2,ilog,oob_clog};do ln -s $OB_DATA_PATH/log1/$OB_CLUSTER_NAME/$t $OB_HOME_PATH/store/$OB_CLUSTER_NAME/$t; donemkdir -p $OB_HOME_PATH/{sh,init}
mv /mnt/software/pkg/StartOB $OB_HOME_PATH/sh
mv /mnt/software/pkg/StopOB $OB_HOME_PATH/sh
mv /mnt/software/pkg/_env $OB_HOME_PATH/sh
mv /mnt/software/pkg/InitDB $OB_HOME_PATH/init
mv /mnt/software/pkg/ob-init.sql $OB_HOME_PATH/init
echo "install Oceanbase success!"
该脚步主要用于安装包安装及oceanbase目录创建及脚步添加。
InitDB
Dockerfile中的/home/admin/oceanbase/init/InitDB
执行脚步内容如下:
#!/bin/bash
source /home/admin/oceanbase/sh/_env
set -e
CWD=$(cd `dirname $0`;pwd)
echo "Current dir: ${CWD}"echo "update BOOTSTRAP config..."
sed -i "s|@HOSTIP@:@OB_RPC_PORT@|${HOST_IP}:${OB_RPC_PORT}|g" $OB_HOME_PATH/init/ob-init.sqlcd ${OB_HOME_PATH}CMD="${OB_HOME_PATH}/bin/observer -i eth0 -P ${OB_RPC_PORT} -p ${OB_DB_PORT} -z zone1 -d ${OB_HOME_PATH}/store/${OB_CLUSTER_NAME} -r '${HOST_IP}:2882:2881' -c 10001 -n ${OB_CLUSTER_NAME} -o \"system_memory=${SYSTEM_MEMORY},datafile_size=${DATAFILE_SIZE},config_additional_dir=${OB_DATA_PATH}/1/${OB_CLUSTER_NAME}/etc3;${OB_DATA_PATH}/log1/${OB_CLUSTER_NAME}/etc2\""echo "Command is: ${CMD}"
${CMD}
if [ $? -eq 0 ]; thenecho "boot success!"sleep 30sCMD="obclient -h${HOST_IP} -uroot@${OB_TENANT_NAME} -A -P${OB_DB_PORT} < ${OB_HOME_PATH}/init/ob-init.sql"echo "Init BOOTSTRAP Command is: ${CMD}"obclient -h${HOST_IP} -uroot@${OB_TENANT_NAME} -A -P${OB_DB_PORT} < $OB_HOME_PATH/init/ob-init.sqlecho "Init BOOTSTRAP success!"elseecho "boot failed!"echo "Please check the log file ${OB_HOME_PATH}/log/observer.log"
fi
该脚本主要用于启动并初始化oceanbase集群。改脚步中的ob-init.sql内容如下:
SET SESSION ob_query_timeout=1000000000;
ALTER SYSTEM BOOTSTRAP ZONE 'zone1' SERVER '@HOSTIP@:@OB_RPC_PORT@';
StartOB
StartOB脚步内容如下:
#!/bin/bash
source /home/admin/oceanbase/sh/_env
set -e
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
cd ${OB_HOME_PATH}CMD="${OB_HOME_PATH}/bin/observer -i eth0 -P ${OB_RPC_PORT} -p ${OB_DB_PORT} -z zone1 -d ${OB_HOME_PATH}/store/${OB_CLUSTER_NAME} -r '${HOST_IP}:2882:2881' -c 10001 -n ${OB_CLUSTER_NAME} -o \"system_memory=${SYSTEM_MEMORY},datafile_size=${DATAFILE_SIZE},config_additional_dir=${OB_DATA_PATH}/1/${OB_CLUSTER_NAME}/etc3;${OB_DATA_PATH}/log1/${OB_CLUSTER_NAME}/etc2\""echo "Command is: ${CMD}"
svrs=`ps -ef | grep 'observer' | grep -v 'grep observer' | wc -l`
if [ $svrs -gt 0 ]thenecho -e "\e[31;1;5mServers are running now!\e[0m\n"echo -e "\e[32;1mPlease stop servers and try again!\e[0m\n"exit 5
else ${CMD}if [ $? -eq 0 ]; thendatesleep 60sdateecho "boot success!"elseecho "boot failed!"echo "Please check the log file ${OB_HOME_PATH}/log/observer.log"
fi
fi
改脚步用于启动oceanbase集群服务。
StopOB
StopOB脚步内容如下:
#!/bin/bashsvrs=`ps -ef | grep 'observer' | grep -v 'grep observer' | wc -l`
if [ $svrs -gt 0 ]thenkill -9 $(ps -ef | grep 'observer' | grep -v 'grep observer' | awk '{ print $2 }')echo -e "\e[31;1;5m Kill observer is Finished!\e[0m\n"
fi
该脚步主要用于关闭Oceanbase集群服务。
_env
installDB、InitDB脚本中的_env
内容如下:
OB_HOME_PATH="/home/admin/oceanbase"
OB_DATA_PATH="/data"
OB_DB_PORT="2881"
OB_RPC_PORT="2882"
OB_CLUSTER_NAME="obcluster"
OB_TENANT_NAME="sys"
HOST_IP="$(ifconfig | grep cast | awk '{print $2}')"
SYSTEM_MEMORY="5G"
DATAFILE_SIZE="2G"
该脚本主要用于环境配置,用来设置oceabase的初始配置值。
镜像构建
进入到构建目录下,执行构建命令:
docker build -t oceanbase:3.2.4.1 .
使用docker-compose编排容器
version: '2'
services: oceanbase:container_name: oceanbaseimage: oceanbase:3.2.4.1user: roothostname: oceanbaseports: - "12881:2881"- "12882:2882"volumes:#对数据进行固化- "/data/oceanbase:/home/admin/oceanbase/data" command:- /bin/sh- -c- |sh /home/admin/oceanbase/init/InitDB#创建资源单元obclient -h127.0.0.1 -uroot@sys -A -P2881 -e "CREATE RESOURCE UNIT unit1 MAX_CPU 1, MAX_MEMORY '1G', MAX_IOPS 128,MAX_DISK_SIZE '10G', MAX_SESSION_NUM 64, MIN_CPU=1, MIN_MEMORY='1G', MIN_IOPS=128"echo "创建资源单元unit1完成!"#调整最小资源池限制为1Gobclient -h127.0.0.1 -uroot@sys -A -P2881 -e "alter system __min_full_resource_pool_memory=1073741824"echo "调整最小资源池限制为1G完成!"#创建资源池obclient -h127.0.0.1 -uroot@sys -A -P2881 -e "CREATE RESOURCE POOL pool1 unit='unit1', unit_num=1, zone_list=('zone1')"echo "创建资源池pool1完成!"#创建oracle租户obclient -h127.0.0.1 -uroot@sys -A -P2881 -e "CREATE TENANT IF NOT EXISTS oracledb charset='utf8mb4', replica_num=1, zone_list=('zone1'), primary_zone='zone1', resource_pool_list=('pool1') SET ob_compatibility_mode='oracle', ob_tcp_invited_nodes='%'"echo "创建oracle租户oracledb完成!"#连接oracle模式创建用户WELTESTobclient -h127.0.0.1 -usys@oracledb -A -P2881 -e "create user WELTEST identified by WELTEST"echo "oracle模式创建用户WELTEST完成!"#给用户赋权obclient -h127.0.0.1 -usys@oracledb -A -P2881 -e "GRANT ALL PRIVILEGES TO WELTEST"echo "给用户赋权完成!"/bin/shtty: truestdin_open: true
该文件主要是使用启动oceanbase集群、创建资源池、创建oracle租户并给用户赋权。