当前位置: 首页 > news >正文

通过 Docker 实现国产数据库 OpenGauss 开发环境搭建

通过 Docker 实现国产数据库 OpenGauss 开发环境搭建

一 前置准备

2.1 下载镜像

docker pull enmotech/opengauss:5.0.1

构建镜像的 Dockerfile,方便后期实现个性化定制:

FROM ubuntu:22.04 as builderARG TARGETARCHWORKDIR /warehouseRUN set -eux; \if [ "$TARGETARCH" = "arm64" ]; then \echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse" >/etc/apt/sources.list && \echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse" >>/etc/apt/sources.list && \echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse" >>/etc/apt/sources.list && \echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse" >>/etc/apt/sources.list && \echo "deb http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse" >>/etc/apt/sources.list; \elif [ "$TARGETARCH" = "amd64" ]; then \echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" >/etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse" >>/etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse" >>/etc/apt/sources.list && \echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse" >>/etc/apt/sources.list; \fi && \mkdir -p /warehouse/opengauss && \apt-get update && apt-get install --yes --no-install-recommends  \wget \bzip2 \ca-certificates && \if [ "$TARGETARCH" = "arm64" ]; then \wget --progress=bar:force:noscroll https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.1/arm_2203/openGauss-5.0.1-openEuler-64bit-all.tar.gz -O /warehouse/openGauss.tar.bz2; \elif [ "$TARGETARCH" = "amd64" ]; then \wget --progress=bar:force:noscroll https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.1/x86_openEuler_2203/openGauss-5.0.1-openEuler-64bit-all.tar.gz -O /warehouse/openGauss.tar.bz2; \fi && \tar xf /warehouse/openGauss.tar.bz2  && \tar xf openGauss-5.0.1-openEuler-64bit.tar.bz2 -C /warehouse/opengauss && \rm -f /warehouse/openGauss.tar.bz2 && chmod -R +rx /warehouse/opengaussFROM ubuntu:22.04ARG TARGETARCHENV LANG en_US.utf8
ENV GAUSSLOG /home/omm/pg_log
ENV PGDATA /var/lib/opengauss/dataRUN set -eux; \apt-get update && apt-get install --yes --no-install-recommends \libc6 \ncat \gosu \bzip2 \procps \locales \iputils-ping \libaio-dev \libkeyutils-dev \libreadline-dev; \apt-get clean; \rm -rf /var/lib/apt/lists/* /tmp/*; \groupadd -g 70 omm; \useradd -u 70 -g omm -m -s /bin/bash omm; \mkdir -p /var/lib/opengauss; \mkdir -p /var/run/opengauss; \mkdir /docker-entrypoint-initdb.d; \chown omm:omm /var/lib/opengauss /home/omm /var/run/opengauss /docker-entrypoint-initdb.d; \echo "export GAUSSLOG=/home/omm/pg_log" >> /home/omm/.profile; \echo "export GAUSSHOME=/usr/local/opengauss" >> /home/omm/.profile; \echo "export PGDATA=/var/lib/opengauss/data" >> /home/omm/.profile; \echo "export PATH=\$GAUSSHOME/bin:\$PATH " >> /home/omm/.profile; \echo "export LD_LIBRARY_PATH=\$GAUSSHOME/lib:\$LD_LIBRARY_PATH" >> /home/omm/.profile; \locale-gen en_US.UTF-8 && \if [ "$TARGETARCH" = "arm64" ];then \ln -s /lib/aarch64-linux-gnu/libreadline.so.8.0 /lib/aarch64-linux-gnu/libreadline.so.7; \elif [ "$TARGETARCH" = "amd64" ];then \ln -s /lib/x86_64-linux-gnu/libreadline.so.8.0 /lib/x86_64-linux-gnu/libreadline.so.7; \fiCOPY entrypoint.sh /usr/local/bin/
COPY --chown=omm:omm --from=builder /warehouse/opengauss /usr/local/opengauss
RUN chmod 755 /usr/local/bin/entrypoint.sh && ln -s /usr/local/bin/entrypoint.sh /ENTRYPOINT ["entrypoint.sh"]
EXPOSE 5432
CMD ["gaussdb"]

docker-entrypoinrt.sh 内容:

#!/usr/bin/env bash
set -Eeo pipefail# usage: file_env VAR [DEFAULT]
#    ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
#  "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)export GAUSSHOME=/usr/local/opengauss
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export LANG=en_US.UTF-8file_env() {local var="$1"local fileVar="${var}_FILE"local def="${2:-}"if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; thenecho >&2 "error: both $var and $fileVar are set (but are exclusive)"exit 1filocal val="$def"if [ "${!var:-}" ]; thenval="${!var}"elif [ "${!fileVar:-}" ]; thenval="$(< "${!fileVar}")"fiexport "$var"="$val"unset "$fileVar"
}# check to see if this file is being run or sourced from another script
_is_sourced() {[ "${#FUNCNAME[@]}" -ge 2 ] \&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \&& [ "${FUNCNAME[1]}" = 'source' ]
}# used to create initial opengauss directories and if run as root, ensure ownership belong to the omm user
docker_create_db_directories() {local useruser="$(id -u)"mkdir -p "$PGDATA"chmod 700 "$PGDATA"# ignore failure since it will be fine when using the image provided directory;mkdir -p /var/run/opengauss || :chmod 775 /var/run/opengauss || :# Create the transaction log directory before initdb is run so the directory is owned by the correct userif [ -n "$POSTGRES_INITDB_XLOGDIR" ]; thenmkdir -p "$POSTGRES_INITDB_XLOGDIR"if [ "$user" = '0' ]; thenfind "$POSTGRES_INITDB_XLOGDIR" \! -user postgres -exec chown postgres '{}' +fichmod 700 "$POSTGRES_INITDB_XLOGDIR"fi# allow the container to be started with `--user`if [ "$user" = '0' ]; thenfind "$PGDATA" \! -user omm -exec chown omm '{}' +find /var/run/opengauss \! -user omm -exec chown omm '{}' +fi
}# initialize empty PGDATA directory with new database via 'initdb'
# arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments to this function
# `initdb` automatically creates the "postgres", "template0", and "template1" dbnames
# this is also where the database user is created, specified by `GS_USER` env
docker_init_database_dir() {# "initdb" is particular about the current user existing in "/etc/passwd", so we use "nss_wrapper" to fake that if necessaryif ! getent passwd "$(id -u)" &> /dev/null && [ -e /usr/lib/libnss_wrapper.so ]; thenexport LD_PRELOAD='/usr/lib/libnss_wrapper.so'NSS_WRAPPER_GROUP="$(mktemp)" && export NSS_WRAPPER_GROUPNSS_WRAPPER_PASSWD="$(mktemp)" && export NSS_WRAPPER_PASSWDecho "postgres:x:$(id -u):$(id -g):PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD"echo "postgres:x:$(id -g):" > "$NSS_WRAPPER_GROUP"fiif [ -n "$POSTGRES_INITDB_XLOGDIR" ]; thenset -- --xlogdir "$POSTGRES_INITDB_XLOGDIR" "$@"ficmdbase="gs_initdb --pwfile=<(echo $GS_PASSWORD)"if [ -n "$GS_NODENAME" ]; thencmdbase="$cmdbase --nodename=$GS_NODENAME"elsecmdbase="$cmdbase --nodename=gaussdb"fiif [ -n "$ENCODING" ]; thencmdbase="$cmdbase --encoding=$ENCODING"elsecmdbase="$cmdbase --encoding=UTF-8"fiif [ -n "$LOCALE" ]; thencmdbase="$cmdbase --locale=$LOCALE"elsecmdbase="$cmdbase --no-locale"fiif [ -n "$DBCOMPATIBILITY" ]; thencmdbase="$cmdbase --dbcompatibility=$DBCOMPATIBILITY"elsecmdbase="$cmdbase --dbcompatibility=PG"ficmdbase="$cmdbase -D $PGDATA"eval "$cmdbase"# unset/cleanup "nss_wrapper" bitsif [ "${LD_PRELOAD:-}" = '/usr/lib/libnss_wrapper.so' ]; thenrm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP"unset LD_PRELOAD NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUPfi
}# print large warning if GS_PASSWORD is long
# error if both GS_PASSWORD is empty and GS_HOST_AUTH_METHOD is not 'trust'
# print large warning if GS_HOST_AUTH_METHOD is set to 'trust'
# assumes database is not set up, ie: [ -z "$DATABASE_ALREADY_EXISTS" ]
docker_verify_minimum_env() {# check password first so we can output the warning before postgres# messes it upif [[ "$GS_PASSWORD" =~ ^(.{8,}).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[a-z]+).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[A-Z]).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[0-9]).*$ ]] && [[ "$GS_PASSWORD" =~ ^(.*[#?!@$%^&*-]).*$ ]]; thencat >&2 <<- 'EOWARN'Message: The supplied GS_PASSWORD is meet requirements.EOWARNelsecat >&2 <<- 'EOWARN'Error: The supplied GS_PASSWORD is not meet requirements.Please Check if the password contains uppercase, lowercase, numbers, special characters, and password length(8).At least one uppercase, lowercase, numeric, special character.Example: Enmo@123
EOWARNexit 1fiif [ -z "$GS_PASSWORD" ] && [ 'trust' != "$GS_HOST_AUTH_METHOD" ]; then# The - option suppresses leading tabs but *not* spaces. :)cat >&2 <<- 'EOE'Error: Database is uninitialized and superuser password is not specified.You must specify GS_PASSWORD to a non-empty value for thesuperuser. For example, "-e GS_PASSWORD=password" on "docker run".You may also use "GS_HOST_AUTH_METHOD=trust" to allow allconnections without a password. This is *not* recommended.EOEexit 1fiif [ 'trust' = "$GS_HOST_AUTH_METHOD" ]; thencat >&2 <<- 'EOWARN'********************************************************************************WARNING: GS_HOST_AUTH_METHOD has been set to "trust". This will allowanyone with access to the opengauss port to access your database withouta password, even if GS_PASSWORD is set.It is not recommended to use GS_HOST_AUTH_METHOD=trust. Replaceit with "-e GS_PASSWORD=password" instead to set a password in"docker run".********************************************************************************
EOWARNfi
}# usage: docker_process_init_files [file [file [...]]]
#    ie: docker_process_init_files /always-initdb.d/*
# process initializer files, based on file extensions and permissions
docker_process_init_files() {# gsql here for backwards compatiblilty "${gsql[@]}"gsql=(docker_process_sql)echolocal ffor f; docase "$f" in*.sh)if [ -x "$f" ]; thenecho "$0: running $f""$f"elseecho "$0: sourcing $f". "$f"fi;;*.sql)    echo "$0: running $f"; docker_process_sql -f "$f"; echo ;;*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;;*.sql.xz) echo "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;;*)        echo "$0: ignoring $f" ;;esacechodone
}# Execute sql script, passed via stdin (or -f flag of pqsl)
# usage: docker_process_sql [gsql-cli-args]
#    ie: docker_process_sql --dbname=mydb <<<'INSERT ...'
#    ie: docker_process_sql -f my-file.sql
#    ie: docker_process_sql <my-file.sql
docker_process_sql() {local query_runner=(gsql -v ON_ERROR_STOP=1 --username "$GS_USER" --password "$GS_PASSWORD")if [ -n "$GS_DB" ]; thenquery_runner+=(--dbname "$GS_DB")fiecho "Execute SQL: ${query_runner[@]} $@""${query_runner[@]}" "$@"
}# create initial database
# uses environment variables for input: GS_DB
docker_setup_db() {echo "GS_DB = $GS_DB"if [ "$GS_DB" != 'postgres' ]; thenGS_DB= docker_process_sql --dbname postgres --set db="$GS_DB" --set passwd="$GS_PASSWORD" <<- 'EOSQL'CREATE DATABASE :"db" ;create user gaussdb with login password :"passwd" ;grant all privileges to gaussdb;EOSQLechofi
}docker_setup_user() {if [ -n "$GS_USERNAME" ]; thenGS_DB= docker_process_sql --dbname postgres --set db="$GS_DB" --set passwd="$GS_PASSWORD" --set user="$GS_USERNAME" <<- 'EOSQL'create user :"user" with login password :"passwd" ;
EOSQLelseecho " default user is gaussdb"fi
}docker_setup_rep_user() {if [ -n "$SERVER_MODE" ] && [ "$SERVER_MODE" = "primary" ]; thenGS_DB= docker_process_sql --dbname postgres --set passwd="RepUser@2020" --set user="repuser" <<- 'EOSQL'create user :"user" SYSADMIN REPLICATION password :"passwd" ;
EOSQLelseecho " default no repuser created"fi
}# Loads various settings that are used elsewhere in the script
# This should be called before any other functions
docker_setup_env() {export GS_USER=ommfile_env 'GS_PASSWORD' 'Enmo@123'# file_env 'GS_USER' 'omm'file_env 'GS_DB' "$GS_USER"file_env 'POSTGRES_INITDB_ARGS'# default authentication method is md5: "${GS_HOST_AUTH_METHOD:=md5}"declare -g DATABASE_ALREADY_EXISTS# look specifically for OG_VERSION, as it is expected in the DB dirif [ -s "$PGDATA/PG_VERSION" ]; thenDATABASE_ALREADY_EXISTS='true'fi
}# append parameter to mot.conf
opengauss_setup_mot_conf() {echo "enable_numa = false" > "$PGDATA/mot.conf"
}# append parameter to pg_hba.conf
opengauss_setup_hba_conf() {{echoif [ 'trust' = "$GS_HOST_AUTH_METHOD" ]; thenecho '# warning trust is enabled for all connections'fiecho "host all all 0.0.0.0/0 $GS_HOST_AUTH_METHOD"echo "host replication gaussdb 0.0.0.0/0 md5"if [ -n "$SERVER_MODE" ]; thenecho "host replication repuser $OG_SUBNET trust"fi} >> "$PGDATA/pg_hba.conf"
}# append parameter to postgres.conf
opengauss_setup_postgresql_conf() {{echoif [ -n "$GS_PORT" ]; thenecho "port = $GS_PORT"echo "wal_level = logical"echo "password_encryption_type = 1"elseecho '# use default port 5432'echo "wal_level = logical"echo "password_encryption_type = 1"fiif [ -n "$SERVER_MODE" ]; thenecho "most_available_sync = on"echo "listen_addresses = '0.0.0.0'"echo "pgxc_node_name = '$NODE_NAME'"echo "remote_read_mode = non_authentication"echo -e "$REPL_CONN_INFO"if [ -n "$SYNCHRONOUS_STANDBY_NAMES" ]; thenecho "synchronous_standby_names=$SYNCHRONOUS_STANDBY_NAMES"fielseecho "listen_addresses = '0.0.0.0'"fiif [ -n "$OTHER_PG_CONF" ]; thenecho -e "$OTHER_PG_CONF"fi} >> "$PGDATA/postgresql.conf"
}docker_slave_full_backup() {gs_ctl build -D "$PGDATA" -b full
}# stop postgresql server after done setting up user and running scripts
docker_temp_server_stop() {PGUSER="${PGUSER:-$GS_USER}" gs_ctl -D "$PGDATA" -m fast -w stop
}# start socket-only postgresql server for setting up or running scripts
# all arguments will be passed along as arguments to `postgres` (via pg_ctl)
docker_temp_server_start() {if [ "$1" = 'gaussdb' ]; thenshiftfi# internal start of server in order to allow setup using gsql client# does not listen on external TCP/IP and waits until start finishesset -- "$@" -c listen_addresses='127.0.0.1' -p "${PGPORT:-5432}"PGUSER="${PGUSER:-$GS_USER}" gs_ctl -D "$PGDATA" -o "$(printf '%q ' "$@")" -w start
}# check arguments for an option that would cause opengauss to stop
# return true if there is one_opengauss_want_help() {local argcount=1for arg; docase "$arg" in# postgres --help | grep 'then exit'# leaving out -C on purpose since it always fails and is unhelpful:# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory-'?' | --help | --describe-config | -V | --version)return 0;;esacif [ "$arg" == "-M" ]; thenSERVER_MODE=${@:$count+1:1}echo "openGauss DB SERVER_MODE = $SERVER_MODE"shiftficount=$(($count + 1))donereturn 1
}_main() {# if first arg looks like a flag, assume we want to run postgres serverif [ "${1:0:1}" = '-' ]; thenset -- gaussdb "$@"fiif [ "$1" = 'gaussdb' ] && ! _opengauss_want_help "$@"; thendocker_setup_env# setup data directories and permissions (when run as root)docker_create_db_directoriesif [ "$(id -u)" = '0' ]; then# then restart script as postgres userexec gosu omm "$BASH_SOURCE" "$@"fi# only run initialization on an empty data directoryif [ -z "$DATABASE_ALREADY_EXISTS" ]; thendocker_verify_minimum_env# check dir permissions to reduce likelihood of half-initialized databasels /docker-entrypoint-initdb.d/ > /dev/nulldocker_init_database_diropengauss_setup_hba_confopengauss_setup_postgresql_confopengauss_setup_mot_conf# PGPASSWORD is required for gsql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGSexport PGPASSWORD="${PGPASSWORD:-$GS_PASSWORD}"docker_temp_server_start "$@"if [ -z "$SERVER_MODE" ] || [ "$SERVER_MODE" = "primary" ]; thendocker_setup_dbdocker_setup_userdocker_setup_rep_userdocker_process_init_files /docker-entrypoint-initdb.d/*fiif [ -n "$SERVER_MODE" ] && [ "$SERVER_MODE" != "primary" ]; thendocker_slave_full_backupfidocker_temp_server_stopunset PGPASSWORDechoecho 'openGauss  init process complete; ready for start up.'echoelseechoecho 'openGauss Database directory appears to contain a database; Skipping initialization'echofifiexec "$@"
}if ! _is_sourced; then_main "$@"
fi

2.2 环境变量配置说明

GS_PASSWORD:必须设置该参数。该参数值不能为空或者不定义。该参数设置了 openGauss 数据库的超级用户 omm 以及测试用户 gaussdb 的密码。openGauss 安装时默认会创建 omm 超级用户,该用户名暂时无法修改。测试用户 gaussdb 是在 entrypoint.sh 中自定义创建的用户。openGauss 镜像配置了本地信任机制,因此在容器内连接数据库无需密码,但是如果要从容器外部(其它主机或者其它容器)连接则必须要输入密码。openGauss 的密码有复杂度要求,需要:密码长度 8 个字符及以上,必须同时包含英文字母大小写,数字,以及特殊符号。

GS_NODENAME:指定数据库节点名称 默认为 gaussdb。

GS_USERNAME:指定数据库连接用户名 默认为 gaussdb。

GS_PORT:指定数据库端口,默认为 5432。

2.3 启动容器

启动命令如下:

docker run -d --name opengauss \--privileged=true \--restart=always \-v /home/ivan/data/opengauss:/var/lib/opengauss  \-u root \-p 15432:5432 \-e GS_NODENAME=gaussdb \-e GS_USERNAME=gaussdb \-e GS_PASSWORD='C*x#1a2b' \enmotech/opengauss:5.0.1

2.4 使用 gsql 连接数据库

示例如下:

gsql -d "host=127.0.0.1 port=5432 dbname=gaussdb user=omm password='C*x#1a2b'"

2.5 建库建表

示例如下:

CREATE USER IF NOT EXISTS cmams WITH PASSWORD 'ghaF&fZugC9y';
CREATE DATABASE IF NOT EXISTS cmams ENCODING 'UTF8' OWNER cmams;
CREATE SCHEMA IF NOT EXISTS cmams;
GRANT CREATE,USAGE ON SCHEMA cmams TO cmams;
GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO cmams;
GRANT USAGE,SELECT ON ALL SEQUENCES IN SCHEMA cmams TO cmams;
DROP TABLE IF EXISTS cmams.cmams_status;
CREATE TABLE cmams_status
(cmams_id               varchar(18) not null constraint cmams_status_pk primary key,cmams_province         varchar(20) not null,cmams_concurrency      integer   not null,cmams_successful_count integer   not null,cmams_failure_count    integer   not null,cmams_queue_length     integer   not null,cmams_update_time      timestamp   not null
);COMMENT ON COLUMN cmams_status.cmams_id IS '主键ID';
COMMENT ON COLUMN cmams_status.cmams_province IS '省份';
COMMENT ON COLUMN cmams_status.cmams_concurrency IS '当前并发数';
COMMENT ON COLUMN cmams_status.cmams_successful_count IS '成功调用次数';
COMMENT ON COLUMN cmams_status.cmams_failure_count IS '调用失败次数';
COMMENT ON COLUMN cmams_status.cmams_queue_length IS 'Redis队列长度';
COMMENT ON COLUMN cmams_status.cmams_update_time IS '数据更新时间';

2.6 Maven 项目引入相关驱动

<dependency><groupId>org.opengauss</groupId><artifactId>opengauss-jdbc</artifactId><version>5.1.0-og</version><scope>provided</scope>
</dependency>

2.7 主从集群搭建

按需修改并执行以下脚本:

#!/bin/bash -e
# Parameters
#!/bin/bash#set OG_SUBNET,GS_PASSWORD,MASTER_IP,SLAVE_1_IP,MASTER_HOST_PORT,MASTER_LOCAL_PORT,SLAVE_1_HOST_PORT,SLAVE_1_LOCAL_PORT,MASTER_NODENAME,SLAVE_NODENAMEread -p "Please input OG_SUBNET (容器所在网段) [172.11.0.0/24]: " OG_SUBNET
OG_SUBNET=${OG_SUBNET:-172.11.0.0/24}
echo "OG_SUBNET set $OG_SUBNET"read -p "Please input GS_PASSWORD (定义数据库密码)[Enmo@123]: " GS_PASSWORD
GS_PASSWORD=${GS_PASSWORD:-Enmo@123}
echo "GS_PASSWORD set $GS_PASSWORD"read -p "Please input MASTER_IP (主库IP)[172.11.0.101]: " MASTER_IP
MASTER_IP=${MASTER_IP:-172.11.0.101}
echo "MASTER_IP set $MASTER_IP"read -p "Please input SLAVE_1_IP (备库IP)[172.11.0.102]: " SLAVE_1_IP
SLAVE_1_IP=${SLAVE_1_IP:-172.11.0.102}
echo "SLAVE_1_IP set $SLAVE_1_IP"read -p "Please input MASTER_HOST_PORT (主库数据库服务端口)[5432]: " MASTER_HOST_PORT
MASTER_HOST_PORT=${MASTER_HOST_PORT:-5432}
echo "MASTER_HOST_PORT set $MASTER_HOST_PORT"read -p "Please input MASTER_LOCAL_PORT (主库通信端口)[5434]: " MASTER_LOCAL_PORT
MASTER_LOCAL_PORT=${MASTER_LOCAL_PORT:-5434}
echo "MASTER_LOCAL_PORT set $MASTER_LOCAL_PORT"read -p "Please input SLAVE_1_HOST_PORT (备库数据库服务端口)[6432]: " SLAVE_1_HOST_PORT
SLAVE_1_HOST_PORT=${SLAVE_1_HOST_PORT:-6432}
echo "SLAVE_1_HOST_PORT set $SLAVE_1_HOST_PORT"read -p "Please input SLAVE_1_LOCAL_PORT (备库通信端口)[6434]: " SLAVE_1_LOCAL_PORT
SLAVE_1_LOCAL_PORT=${SLAVE_1_LOCAL_PORT:-6434}
echo "SLAVE_1_LOCAL_PORT set $SLAVE_1_LOCAL_PORT"read -p "Please input MASTER_NODENAME [opengauss_master]: " MASTER_NODENAME
MASTER_NODENAME=${MASTER_NODENAME:-opengauss_master}
echo "MASTER_NODENAME set $MASTER_NODENAME"read -p "Please input SLAVE_NODENAME [opengauss_slave1]: " SLAVE_NODENAME
SLAVE_NODENAME=${SLAVE_NODENAME:-opengauss_slave1}
echo "SLAVE_NODENAME set $SLAVE_NODENAME"read -p "Please input openGauss VERSION [1.1.0]: " VERSION
VERSION=${VERSION:-1.1.0}
echo "openGauss VERSION set $VERSION"echo "starting  "docker network create --subnet=$OG_SUBNET opengaussnetwork \
|| {echo ""echo "ERROR: OpenGauss Database Network was NOT successfully created."echo "HINT: opengaussnetwork Maybe Already Exsist Please Execute 'docker network rm opengaussnetwork' "exit 1
}
echo "OpenGauss Database Network Created."docker run --network opengaussnetwork --ip $MASTER_IP --privileged=true \
--name $MASTER_NODENAME -h $MASTER_NODENAME -p $MASTER_HOST_PORT:$MASTER_HOST_PORT -d \
-e GS_PORT=$MASTER_HOST_PORT \
-e OG_SUBNET=$OG_SUBNET \
-e GS_PASSWORD=$GS_PASSWORD \
-e NODE_NAME=$MASTER_NODENAME \
-e REPL_CONN_INFO="replconninfo1 = 'localhost=$MASTER_IP localport=$MASTER_LOCAL_PORT localservice=$MASTER_HOST_PORT remotehost=$SLAVE_1_IP remoteport=$SLAVE_1_LOCAL_PORT remoteservice=$SLAVE_1_HOST_PORT'\n" \
enmotech/opengauss:$VERSION -M primary \
|| {echo ""echo "ERROR: OpenGauss Database Master Docker Container was NOT successfully created."exit 1
}
echo "OpenGauss Database Master Docker Container created."sleep 30sdocker run --network opengaussnetwork --ip $SLAVE_1_IP --privileged=true \
--name $SLAVE_NODENAME -h $SLAVE_NODENAME -p $SLAVE_1_HOST_PORT:$SLAVE_1_HOST_PORT -d \
-e GS_PORT=$SLAVE_1_HOST_PORT \
-e OG_SUBNET=$OG_SUBNET \
-e GS_PASSWORD=$GS_PASSWORD \
-e NODE_NAME=$SLAVE_NODENAME \
-e REPL_CONN_INFO="replconninfo1 = 'localhost=$SLAVE_1_IP localport=$SLAVE_1_LOCAL_PORT localservice=$SLAVE_1_HOST_PORT remotehost=$MASTER_IP remoteport=$MASTER_LOCAL_PORT remoteservice=$MASTER_HOST_PORT'\n" \
enmotech/opengauss:$VERSION -M standby \
|| {echo ""echo "ERROR: OpenGauss Database Slave1 Docker Container was NOT successfully created."exit 1
}
echo "OpenGauss Database Slave1 Docker Container created."

2.8 多节点URL配置

示例如下:

local.url=jdbc:opengauss://127.0.0.1:20001,127.0.0.2:20001/localtest?useUnicode=true&characterEncoding=utf8&useSSL=false&targetServerType=master&batchMode=off

三 参考资料

  1. 云和墨恩官方 OpenGauss GitHub 5.0.1 镜像构建相关内容

  2. 云和墨恩官方 OpenGauss 镜像

  3. OpenGauss 官方支持包和工具下载

相关文章:

通过 Docker 实现国产数据库 OpenGauss 开发环境搭建

通过 Docker 实现国产数据库 OpenGauss 开发环境搭建 一 前置准备 2.1 下载镜像 docker pull enmotech/opengauss:5.0.1构建镜像的 Dockerfile&#xff0c;方便后期实现个性化定制&#xff1a; FROM ubuntu:22.04 as builderARG TARGETARCHWORKDIR /warehouseRUN set -eux;…...

【Java】LinkedList模拟实现

目录 整体框架IMyLinkedList接口IndexNotLegalException异常类MyLinkedList类成员变量(节点信息)addFirst(头插)addLast(尾插)在指定位置插入数据判断是否存在移除第一个相等的节点移除所有相等的节点链表的长度打印链表释放回收链表 整体框架 IMyLinkedList接口 这个接口用来…...

ubuntu下mysql常用命令

1. 登录数据库 mysql -u root -p 2.创建数据库 create database 数据库名字 mysql> create database yourdb; Query OK, 1 row affected (0.03 sec)3.显示数据库 show databases; 实操结果如下 mysql> show databases; -------------------- | Database | ---…...

燃气官网安全运行监测系统-阀井燃气监测仪-旭华智能

近年来&#xff0c;燃气爆炸事故频发&#xff0c;造成了重大人员伤亡和财产损失。这也再次为我们敲响警钟&#xff0c;燃气是我们日常生活中不可或缺的能源&#xff0c;但其潜在的危险性也是不容小觑。因此在重要节点加装燃气阀井气体监测仪&#xff0c;并将数据上传到系统平台…...

vue 文件预览(docx、.xlsx、pdf)

1.ifream <iframe src"" ></iframe> 注: src里面是文件地址 2.vue-office 支持vue2和vue3提供docx、.xlsx、pdf多种文档的在线预览方案 2.1安装 #docx文档预览组件 npm install vue-office/docx vue-demi#excel文档预览组件 npm install vue-office…...

云架构(二) 大使模式

Ambassador pattern &#xff08;https://learn.microsoft.com/en-us/azure/architecture/patterns/ambassador&#xff09; 简单描述 创建一个助手服务&#xff0c;这个服务代表消费服务或者应用程序发送网络请求。大使服务可以看做是与客户机同一个位置的进程外代理。 这种…...

.NET Path类库的特殊方法

在.NET中Path类库是非常常用的一个类库&#xff0c;包含很多我们常用的方法&#xff0c;常用的方法这里就不详细说明了&#xff0c;这里记录下几个非常规的方法。 获取随机文件名&#xff1a; //将返回随机的文件名Console.WriteLine(Path.GetRandomFileName()); 获取禁止在路…...

【JVM】JVM常用性能调优参数详细介绍

JVM常用性能调优参数详细介绍 一、何时进行JVM调优二、性能调优三、JVM调优的基本原则四、JVM调优目标五、JVM调优的步骤六、JVM参数七、JVM参数解析及调优八、JVM参数使用手册8.1 内存相关8.2 GC策略相关8.3 GC日志相关8.4 异常相关8.5 问题定位及优化相关九、参考文档一、何时…...

React中的受控组件与非受控组件

受控组件与非受控组件 受控组件 组件(input, select)的状态与state的值绑定&#xff0c;组件的状态全程响应外部数据 class TestComponent extends React.Component {constructor (props) {super(props);this.state { username: lindaidai };}render () {return <input …...

uniapp实现u-datetime-picker时间选择器的默认日期定位,解决default-value不生效问题

uniapp实现u-datetime-picker&#xff0c;设置默认定位日期&#xff0c;解决default-value不生效问题 想实现的效果是点开时间选择器默认显示当前日期&#xff0c;而不是该选择器最早的日期 给选择器添加ref属性&#xff0c;如下&#xff1a; <u-datetime-picker :show&q…...

react native 使用ScrollView实现下拉更新,上拉加载更多

在React Native中&#xff0c;要实现下拉更新和上拉加载更多的功能&#xff0c;你需要自定义ScrollView组件&#xff0c;监听滚动事件并根据滚动的位置来判断何时触发更新和加载更多的操作。以下是一个基本的实现思路&#xff1a; 监听滚动事件&#xff1a;使用ScrollView的on…...

vue2完结

笔记 关于不同版本的Vue: 1.vue.js与vue.runtime.xxx.js的区别&#xff1a;&#xff08;1&#xff09;vue.js是完整版的Vue,包含&#xff1a;核心功能模板解析器&#xff08;2&#xff09;vue.runtime.xxx.js是运行版本的Vue,只包含核心功能&#xff0c;没有模板解析器 2.因为…...

前端网页之间传递参数

在多页面应用中&#xff0c;我们可能面临着前端页面之间传递参数的情况&#xff0c;在一个页面获取到一些参数信息后&#xff0c;到另一个页面去进行后续处理&#xff0c;需要将前一个页面得到的一些参数带到第二个页面。当参数较少时&#xff0c;可以在跳转第二个页面时通过se…...

【常见面试题】Golang中,协程数最多可以开多少个?

参考&#xff1a; Goroutine 究竟可以开多少&#xff1f; 一、先说结论&#xff1a; 能开多少个协程&#xff0c;取决于单个协程处理方法所占用的CPU和内存资源&#xff08;也就是看你计算机运行的应用程序的具体代码逻辑&#xff09;。 二、具体来说&#xff1a; 如果是C…...

RabbitMQ基础笔记

视频链接&#xff1a;【黑马程序员RabbitMQ入门到实战教程】 文章目录 1.初识MQ1.1.同步调用1.2.异步调用1.3.技术选型 2.RabbitMQ2.1.安装2.1.1 Docker2.1.1 Linux2.1.1 Windows 2.2.收发消息2.2.1.交换机2.2.2.队列2.2.3.绑定关系2.2.4.发送消息 2.3.数据隔离2.3.1.用户管理2…...

大型项目管理神器:掌握yarn monorepo的安装和使用

I. 引言 在当今的前端开发中&#xff0c;由于项目规模的不断增长和多团队协同&#xff0c;Monorepo成为了越来越流行的开发模式。Monorepo指的是将多个相关项目或者模块打包在一起的软件开发模式&#xff0c;它可以让开发人员更好地组织管理代码&#xff0c;减少重复的代码&am…...

算法打卡day28|贪心算法篇02|Leetcode 122.买卖股票的最佳时机 II、55. 跳跃游戏、45.跳跃游戏 II

算法题 Leetcode 122.买卖股票的最佳时机 II 题目链接:122.买卖股票的最佳时机 II 大佬视频讲解&#xff1a;买卖股票的最佳时机 II视频讲解 个人思路 因为只有一只股票&#xff0c;且两天作一个交易单元&#xff0c;那每次只收集正利润就可以最终最多可以获取的利润&#xf…...

2013年认证杯SPSSPRO杯数学建模A题(第一阶段)护岸框架全过程文档及程序

2013年认证杯SPSSPRO杯数学建模 A题 护岸框架 原题再现&#xff1a; 在江河中&#xff0c;堤岸、江心洲的迎水区域被水流长期冲刷侵蚀。在河道整治工程中&#xff0c;需要在受侵蚀严重的部位设置一些人工设施&#xff0c;以减弱水流的冲刷&#xff0c;促进该处泥沙的淤积&…...

【3】3道链表力扣题:删除链表中的节点、反转链表、判断一个链表是否有环

3道链表力扣题 一、删除链表中的节点&#x1f30f; 题目链接&#x1f4d5; 示例&#x1f340; 分析&#x1f4bb; 代码 二、反转链表&#x1f30f; 题目链接&#x1f4d5; 示例&#x1f340; 分析① 递归② 迭代 三、判断一个链表是否有环&#x1f30f; 题目链接&#x1f4d5; …...

mongodb sharding分片模式的集群数据库,日志治理缺失导致写入数据库报错MongoWriteConcernException的问题总结(上)

一、背景 常见的mongodb集群模式有以下三种&#xff1a; 主从复制&#xff08;Master-Slave&#xff09;模式副本集&#xff08;Replica Set&#xff09;模式分片&#xff08;Sharding&#xff09;模式 公司测试环境搭建的集群采用分片模式&#xff0c;有同事反馈说&#xf…...

苹果Mac OS系统上安装brew

1.命令行安装brew Homebrew是 mac的包管理器&#xff0c;仅需执行相应的命令,就能下载安装需要的软件包&#xff0c;可以省掉自己去下载、解压、拖拽(安装)等繁琐的步骤。 a. 打开HomeBrew官网&#xff1a;https://brew.sh/index.html b. 点击页面上的复制按钮&#xff0c;打…...

应用侧渲染流程

应用侧渲染流程 《Android应用程序UI硬件加速渲染环境初始化过程分析》 https://blog.csdn.net/Luoshengyang/article/details/45769759 《Android HWUI绘制流程》 https://wizzie.top/android/android_HWUI_Draw/#1-gpu%E6%B8%B2%E6%9F%93%E7%A1%AC%E4%BB%B6%E5%8A%A0%E9%…...

学生党开放式运动耳机怎么选?五款超高销量高性价比品牌推荐

开放式运动耳机成为了许多人的运动首选装备&#xff0c;想要在众多的开放式耳机中找到一款价格亲民&#xff0c;且性能在线高性价比的开放式运动耳机可并非那么简单&#xff0c;所以今天我就来为大家推荐五款超高销量、高性价比的运动耳机品牌。 在推荐之前&#xff0c;整理了…...

服务器中有g++,但是查询不到,Command ‘g++‘ not found

有gcc但是查询不到g&#xff0c;gcc版本为9.5.0 (base) zyICML:~$ g -V Command g not found, but can be installed with: apt install g Please ask your administrator. 突然就出现这个问题&#xff0c;导致detectron装不上&#xff0c;现在有时间了专门研究下怎么解决 这…...

count(“0“),split() ,sys.stdin.readline() ,matrix.append, input().strip()

目录 count() 方法主要用于计算一个序列(例如列表、元组或字符串)中某个元素出现的次数...

Flink on Kubernetes (flink-operator) 部署Flink

flink on k8s 官网 https://nightlies.apache.org/flink/flink-kubernetes-operator-docs-release-1.1/docs/try-flink-kubernetes-operator/quick-start/ 我的部署脚本和官网不一样&#xff0c;有些地方官网不够详细 部署k8s集群 注意&#xff0c;按照默认配置至少有两台wo…...

代码随想录算法训练营第三十二天|122.买卖股票的最佳时机II、55. 跳跃游戏、45.跳跃游戏II

122.买卖股票的最佳时机II - &#x1f517; 讲解 - &#x1f517; 方法一&#xff1a; &#x1f4a1;这道题自己想到的办法没有解析那么清晰&#xff0c;大致思路就是第一步先找到第一个可以买进的时间&#xff08;也就是第一个prices[i] < prices[i 1]的i&#xff09;&…...

常见数据库分类介绍及其适用场景

一、引言 数据库是指在计算机系统中&#xff0c;为了结构化地管理和存储数据而建立起来的一种数据管理系统。它以高效、安全和可靠的方式存储和管理用户所需的各种数据&#xff0c;并提供了强大的数据处理和查询功能。随着信息技术的不断发展&#xff0c;数据库已经成为现代计…...

周末总结(2024/03/30)

工作 接受破烂现状&#xff0c;改变状态 上周一周的工作都感觉是摸鱼状态&#xff0c;每天只有三个小时左右的时间聚焦在工作上&#xff0c;其他时间都在胡思乱想。但是我发现可以在工作中学习和下班相关的技术栈。我无意改变自己的工作状态&#xff0c;只想在5月底找好下家然后…...

(75)爬楼梯

文章目录 1. 每日一言2. 题目2.1 解题思路2.1.1 递归2.1.2 记忆化搜索2.1.3 动态规划2.1.4 动态规划空间优化 2.2 代码2.2.1 递归2.2.2 记忆化搜索2.2.3 动态规划2.2.4 动态规划空间优化 3. 结语 1. 每日一言 Happy life lies in a peaceful mind. 幸福的生活存在于心绪的宁静…...

化州网站建设/网站快速优化排名app

一、存储过程 存储过程&#xff08;Stored Procedure&#xff09;是在大型数据库系统中&#xff0c;一组为了完成特定功能的SQL语句集&#xff0c;经编译后存储在数据库中&#xff0c;用户 通过指定存储过程的名字并给出参数&#xff08;如果该存储过程带有参数&#xff09;来执…...

电子商务网站建设商城网站/360网站安全检测

电脑CPU散热器怎么选择 ?如何选择适合的散热器?这里为大家带来 热门风冷散热器推荐 &#xff0c;一起来看看。安钛克战虎A30 CPU散热器参考价格&#xff1a;29元战虎A30是一款入门热管散热器&#xff0c;沿用了ANTEC风冷散热器所配置的麒麟造型&#xff0c;稳定性更强的造型设…...

网站建设用户调查问卷/杭州seo中心

题型: 编程题 语言: G;GCC Description “丑数”是指除了质因子2,3&#xff0c;5&#xff0c;不含其它质因子的正整数&#xff0c;例如由小到大前10个“丑数”为 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ... 非“丑数”的前10个数为 7, 11, 13, 14, 17, 19, 21, 22, 23, 26, ... 现…...

北京建站公司兴田德润很好/云南疫情最新情况

前言 阿里巴巴&#xff0c;作为国内互联网公司的Top&#xff0c;算是业界的标杆&#xff0c;有阿里背景的程序员&#xff0c;也更具有权威性。作为程序员&#xff0c;都清楚阿里对于员工要求有多高&#xff0c;技术人员掌握的技术水平更是望尘莫及。所以&#xff0c;大厂程序员…...

标题翻译为英文wordpress/开一个免费网站

optimizer_index_caching调整基于成本的优化程序的假定值, 即在缓冲区高速缓存中期望用于嵌套循环联接的索引块的百分比。它将影响使用索引的嵌套循环联接的成本。将该参数设置为一个较高的值,可以使嵌套循环联接相对于优化程序来说成本更低。 索引在缓冲区中出现的机率(百分比…...

东莞南城网站建设/seo基础入门

目录 GUI图形用户编程&#xff08;四&#xff09; 其他组件 OptionMenu选择项 Scale移动滑块 颜色选择框 文件对话框 文件对话框包含如下一些常用函数&#xff1a; 命名参数options的常见值如下&#xff1a; 简单输入对话框 通用消息框 ttk子模块控件 菜单 GUI图形…...