赞
踩
通过该篇文章可以在国产X86-64或ARM架构上构建商业版oceanbase,只需要替换pkg安装包即可。下面截图主要以国产X86-64安装为例,作为操作截图:
pkg:用来存放安装包及脚本,抛出rpm其他是脚步,这些rpm包可以下载不同系统架构的包,构建镜像时该目录只需要保留对应架构包就行。
FROM kylin-server-10-sp2-x86:b09
MAINTAINER weltest
ADD pkg /mnt/software/pkg
ENV OB_HOME_PATH=/home/admin/oceanbase
EXPOSE 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/oceanbase
CMD ["/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/*
Dockerfile中的bash installDB
执行脚步内容如下:
#!/bin/bash set -e CWD=$(cd `dirname $0`;pwd) cd "${CWD}" source /mnt/software/pkg/_env echo "create data dirs..." mkdir -p $OB_DATA_PATH/{1,log1} echo "install ob cluster ..." rpm -ivh /mnt/software/pkg/*.rpm --nodeps echo "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; done mkdir -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目录创建及脚步添加。
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.sql 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}" ${CMD} if [ $? -eq 0 ]; then echo "boot success!" sleep 30s CMD="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.sql echo "Init BOOTSTRAP success!" else echo "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脚步内容如下:
#!/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 ] then echo -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 ]; then date sleep 60s date echo "boot success!" else echo "boot failed!" echo "Please check the log file ${OB_HOME_PATH}/log/observer.log" fi fi
改脚步用于启动oceanbase集群服务。
StopOB脚步内容如下:
#!/bin/bash
svrs=`ps -ef | grep 'observer' | grep -v 'grep observer' | wc -l`
if [ $svrs -gt 0 ]
then
kill -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集群服务。
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 .
version: '2' services: oceanbase: container_name: oceanbase image: oceanbase:3.2.4.1 user: root hostname: oceanbase ports: - "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完成!" #调整最小资源池限制为1G obclient -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模式创建用户WELTEST obclient -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/sh tty: true stdin_open: true
该文件主要是使用启动oceanbase集群、创建资源池、创建oracle租户并给用户赋权。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。