通过 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 官方支持包和工具下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/773495.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

已解决AmqpChannelClosedException: AMQP通道关闭异常的正确解决方法,亲测有效!!!

已解决AmqpChannelClosedException: AMQP通道关闭异常的正确解决方法&#xff0c;亲测有效&#xff01;&#xff01;&#xff01; 目录 问题分析 报错原因 解决思路 解决方法 总结 博主v&#xff1a;XiaoMing_Java 在使用Spring AMQP与RabbitMQ等消息中间件进行交互时&am…

使用npm仓库的优先级以及.npmrc配置文件的使用

使用npm仓库的优先级以及.npmrc配置文件的使用 概念如何设置 registry&#xff08;包管理仓库&#xff09;1. 设置项目配置文件2. 设置用户配置文件3. 设置全局配置文件4. .npmrc文件可以配置的常见选项 概念 npm&#xff08;Node Package Manager&#xff09;是一个Node.js的…

008-如何支持各种语言的项目

我们之前看到&#xff0c; AutoCoder 最简化的配置是这样的&#xff1a; source_dir: /tmp/t-py target_file: /home/winubuntu/projects/ByzerRawCopilot/output.txt query: >修改 server.py &#xff0c;在代码 app FastAPI()后增加 ray 的初始化连接代码。 默认他会只处…

探索Python中的推荐系统:协同过滤

在推荐系统领域&#xff0c;协同过滤是一种经典且有效的方法&#xff0c;它根据用户的历史行为数据或偏好信息&#xff0c;找到与其相似的其他用户或物品&#xff0c;并利用这种相似性来进行个性化推荐。本文将详细介绍协同过滤的原理、实现方式以及如何在Python中应用。 什么…

C语言文件操作(详细)

⽬录 一. 为什么使⽤⽂件&#xff1f; 二. 什么是⽂件&#xff1f; 三. ⼆进制⽂件和⽂本⽂件&#xff1f; 四. ⽂件的打开和关闭 五. ⽂件的顺序读写 六. ⽂件的随机读写 七. ⽂件读取结束的判定 八. ⽂件缓冲区 一. 为什么使⽤⽂件&#xff1f; 如果没有⽂件&#…

kubernetes-k9s一个基于Linux 终端的集群管理工具

效果预览 下载 github 版本 此文档使用的版本是 v0.32.4&#xff0c;下载地址&#xff1a; https://github.com/derailed/k9s/releases/download/v0.32.4/k9s_linux_amd64.rpm 安装 rpm -ivh k9s_linux_amd64.rpm使用 启动 终端直接执行命令 k9s k9s基本操作 1 选择目…

“选项按钮”的妙用

背景&#xff1a;是否厌倦了下拉菜单&#xff1f;现在可以使用更好玩的选项按钮了。 操作&#xff1a;点击“开发工具”&#xff0c;插入“选项按钮”的窗体控件。 插入一个选项按钮以后&#xff0c;右键“设置控件格式”&#xff0c;设定单元格链接&#xff0c;比如说本次设定…

数学分析复习:振荡型级数的收敛判别

文章目录 振荡型级数的收敛判别 本篇文章适合个人复习翻阅&#xff0c;不建议新手入门使用 振荡型级数的收敛判别 直观上&#xff0c;振荡型级数说的是级数各项有正有负&#xff0c;求和的时候可以相互抵消&#xff0c;故可能收敛 命题&#xff1a;Abel求和公式 设复数列 { …

C++经典面试题目(六)

1、C中的循环结构有哪些&#xff1f;请举例说明它们的用法。 C 中的循环结构包括 for 循环、while 循环和 do-while 循环。 for 循环用于按指定的次数重复执行代码块。while 循环用于在条件为真时重复执行代码块。do-while 循环与 while 循环类似&#xff0c;但它先执行一次代…

vue3从精通到入门3:patch函数源码实现方式

Vue3中的patch函数是Vue渲染系统的核心部分&#xff0c;它负责比较新旧虚拟DOM&#xff08;VNode&#xff09;节点&#xff0c;并根据比较结果更新实际的DOM: 先了解下patch函数源码&#xff0c;再进行对其中的解析&#xff1a; function patch( n1: VNode | null, // 旧虚…

车载以太网AVB交换机 TSN交换机 时间敏感网络 6端口 百兆 SW100TSN

SW100 TSN时间敏感网络AVB交换机 为6端口百兆车载以太网交换机&#xff0c;其中包含5通道100BASE-T1泰科MATEnet接口和1个通道100/1000BASE-T标准以太网(RJ45接口)&#xff0c;可以实现纳米级时间同步&#xff0c;车载以太网多通道交换&#xff0c;Bypass数据采集和监控等功能&…

代码格式上对齐的方法

昨天看到课程老师在sourceinsight中的操作&#xff0c;他不到两秒就把每行缩进字符数不同的代码行给统一对齐了。 我觉得这个很有用&#xff0c;虽然只是一个操作问题&#xff0c;而非技术问题。后来查了网络&#xff0c;记录一下这个方法。 比如有下面每行缩进不一样的代码&…

亲身体验!人工智能对话无障碍 —— BRClient 使用指南

01 概述 BRClient 这个名字来源于“Bedrock Client”的简称&#xff0c;寓意是为用户提供一个坚实的基础。BRClient 作为一个开源的桌面应用&#xff0c;为用户提供了友好的图形界面&#xff0c;让每个人都能够轻松访问和使用 Claude 3 的强大功能。用户可以自定义 Claude 3 的…

Vue.js 模板语法

Vue.js 使用了基于 HTML 的模板语法&#xff0c;允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据。 Vue.js 的核心是一个允许你采用简洁的模板语法来声明式的将数据渲染进 DOM 的系统。 结合响应系统&#xff0c;在应用状态改变时&#xff0c; Vue 能够智能地计算出重新…

Web APIs知识点讲解(阶段三)

DOM- 节点操作 一.节点操作 1.DOM节点 目标&#xff1a;能说出DOM节点的类型 DOM节点 DOM树里每一个内容都称之为节点 节点类型 元素节点 所有的标签 比如 body、 div html 是根节点 属性节点 所有的属性 比如 href 文本节点 所有的文本 document树&#xff1a; 总结&…

docker - 删除TAG为<none>的镜像

1.查看所有标记为 none 的镜像 docker images -f "danglingtrue"2. 获取镜像id docker images -f "danglingtrue" -q3、移除所有标记为 none 的镜像 docker rmi $(docker images -f "danglingtrue" -q)无法解决&#xff1a; 直接使用 docke…

Wireshark 抓包

启动时选择一个有信号的网卡双击打开&#xff0c;或者在 捕获选择里打开选择网卡。 然后输出下面的规则就可以抓到报文了。 最上面的三条是建立连接时的三次握手&#xff0c; 下面是发送数据hello 对应两条数据 最下面的4条是断时的4次挥手

Si24R2F+2.4GHz ISM 频段低功耗无线集成嵌入式发射基带无线

Si24R2F在原有Si24R2F的基础上&#xff1a;优化了射频性能、增加NTC测温、增加自动唤醒间隔、优化了蓝牙性能。在固定资产管理、冷链物流和牛羊畜牧业标签市场更具竞争力。 在原有SI24R2E做白卡/校徽的群体&#xff0c;在新的卡片机应用&#xff0c;更加推荐用SI24R2F&#xff…

[串联] MySQL 存储原理 B+树

InnoDB 是一种兼顾高可靠性和高性能的通用存储引擎&#xff0c;在 MySQL 5.5 之后&#xff0c;InnoDB 是默认的 MySQL 存储引擎。 InnoDB 对每张表在磁盘中的存储以 xxx.ibd 后缀结尾&#xff0c;innoDB 引擎的每张表都会对应这样一个表空间文件&#xff0c;用来存储该表的表结…

AXI-Stream——草稿版

参考自哔站&#xff1a;FPGA IP之AXI4-Lite AXI4-Stream_哔哩哔哩_bilibili 信号 传输层级从小到大 包(----------transfer--transfer--------)------delay--------包(----------transfer--transfer--------) TKEEP和TSTRB共同决定了是哪种数据流