commit ccdfb85fb6410e7140a4b7ece566175753fd70f6 Author: wanggang <76527413@qq.com> Date: Wed Jun 9 16:18:14 2021 +0800 update diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..35e54b0 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +#https://github.com/tangyibo/greenplum_docker +kind: pipeline +type: docker +name: default +platform: + arch: amd64 + os: linux +steps: + - name: publish + image: plugins/docker:19.03.8 + environment: + PLUGIN_REGISTRY: 10.10.14.176:5000 + PLUGIN_REPO: 10.10.14.176:5000/docker/greenplum + settings: + insecure: true + tags: + - 6.16.2 + - ${DRONE_COMMIT_SHA:0:8} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c225f2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode +log +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7c3cea9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM centos:centos7 +ENV GPDBVER=6.16.2 \ + DATADIR=/data + +COPY install.sh /tmp/install.sh +COPY entrypoint.sh /entrypoint.sh +COPY open-source-greenplum-db-6.16.2-rhel7-x86_64.rpm / + +RUN yum -y install passwd openssl openssh-server openssh-clients &&\ + mkdir /var/run/sshd/ &&\ + ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' && \ + ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && \ + ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key && \ + echo -e '#!/bin/bash\n/usr/sbin/sshd -D &' > /var/run/sshd/sshd_start.sh && \ + chmod u+x /var/run/sshd/sshd_start.sh + +RUN /var/run/sshd/sshd_start.sh && \ + sleep 10s && cd /tmp && sh install.sh && \ + rm -rf /tmp/install.sh && rm -rf /tmp/files + +EXPOSE 5432 22 + +USER root + +CMD [ "sh" , "/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..350e430 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +docker push 76527413/greenplum:6.16.2 \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..56a6cfc --- /dev/null +++ b/build.cmd @@ -0,0 +1,2 @@ +docker build --progress=plain -t 76527413/greenplum:6.16.2 . +docker push 76527413/greenplum:6.16.2 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..517b5de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3.8" +services: + dev: + image: 76527413/greenplum:6.16.2 + build: . + ports: + - 5432:5432 + volumes: + - ./data:/data \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..94433d3 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash +/var/run/sshd/sshd_start.sh && sleep 5s + +if [ "$(ls -A $DATADIR)" = "" ]; then + + mkdir -p $DATADIR/master + mkdir -p $DATADIR/primary + chown -R gpadmin:gpadmin $DATADIR + + su - gpadmin -l -c "echo -e 'source /usr/local/greenplum-db/greenplum_path.sh' >> ~/.bashrc" + su - gpadmin -l -c "echo -e 'export MASTER_DATA_DIRECTORY=$DATADIR/master/gpseg-1/' >> ~/.bashrc" + su - gpadmin -l -c "echo -e 'export PGPORT=5432' >> ~/.bashrc" + su - gpadmin -l -c "echo -e 'export PGUSER=gpadmin' >> ~/.bashrc" + su - gpadmin -l -c "echo -e 'export PGDATABASE=postgres' >> ~/.bashrc" + + su - gpadmin -l -c "source ~/.bashrc;gpinitsystem -a --ignore-warnings -c /home/gpadmin/gpinitsystem_config_singlenode -h /home/gpadmin/gp_hosts_list" + su - gpadmin -l -c "source ~/.bashrc;psql -d postgres -U gpadmin -f /home/gpadmin/initdb_gpdb.sql" + su - gpadmin -l -c "source ~/.bashrc;gpconfig -c log_statement -v none" + su - gpadmin -l -c "source ~/.bashrc;gpconfig -c gp_enable_global_deadlock_detector -v on" + su - gpadmin -l -c "echo \"host all all 0.0.0.0/0 password\" >> $DATADIR/master/gpseg-1/pg_hba.conf" + su - gpadmin -l -c "source ~/.bashrc && sleep 5s && gpstop -u && tail -f gpAdminLogs/*.log" +else + su - gpadmin -l -c "source ~/.bashrc && gpstart -a && tail -f gpAdminLogs/*.log" +fi diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..47c970e --- /dev/null +++ b/install.sh @@ -0,0 +1,83 @@ +#!/bin/bash +#https://gitee.com/inrgihc/greenplum_docker/tree/main + +PASSWORD=gpadmin + +ERROR_MSG="[ERROR] " +INFO_MSG="[INFO] " + +function log() { + TIME=$(date +"%Y-%m-%d %H:%M:%S") + echo "$TIME $1" +} + +function package_install() { + log "$INFO_MSG check command package : [ $1 ]" + if ! rpm -qa | grep -q "^$1"; then + yum install -y $1 + package_check_ok + else + log "$INFO_MSG command [ $1 ] already installed." + fi +} + +function package_check_ok() { + ret=$? + if [ $ret != 0 ]; then + log "$ERROR_MSG Install failed, error code is $ret, Check the error log." + exit 1 + fi +} + +function gpdb_install(){ + log "$INFO_MSG Start to install greenplum for single node." + + package=(epel-release wget) + for p in ${package[@]}; do + package_install $p + done + + /usr/sbin/groupadd gpadmin + /usr/sbin/useradd gpadmin -g gpadmin + usermod -G gpadmin gpadmin + echo "${PASSWORD}" | passwd --stdin gpadmin + + sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config + sed -i -r 's/^.*StrictHostKeyChecking\s+\w+/StrictHostKeyChecking no/' /etc/ssh/ssh_config + sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd + systemctl restart sshd + + su gpadmin -l -c "ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -P \"\"" + su gpadmin -l -c "cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys" + su gpadmin -l -c "chmod 600 ~/.ssh/authorized_keys" && \ + su gpadmin -l -c "ssh-keyscan -H localhost 2>/dev/null | grep rsa | awk '{print \"localhost \" \$2 \" \" \$3 }' >> ~/.ssh/known_hosts" + + #wget "https://github.com.cnpmjs.org/greenplum-db/gpdb/releases/download/$GPDBVER/open-source-greenplum-db-$GPDBVER-rhel7-x86_64.rpm" + yum install -y "/open-source-greenplum-db-$GPDBVER-rhel7-x86_64.rpm" + rm -rf "/open-source-greenplum-db-$GPDBVER-rhel7-x86_64.rpm" + + rm -f /home/gpadmin/gpinitsystem_config_singlenode + cat > /home/gpadmin/gpinitsystem_config_singlenode << EOF +ARRAY_NAME="Greenplum Data Platform" +SEG_PREFIX=gpseg +PORT_BASE=6000 +declare -a DATA_DIRECTORY=($DATADIR/primary $DATADIR/primary $DATADIR/primary $DATADIR/primary) +MASTER_HOSTNAME=localhost +MASTER_DIRECTORY=$DATADIR/master +MASTER_PORT=5432 +TRUSTED_SHELL=ssh +CHECK_POINT_SEGMENTS=8 +ENCODING=UNICODE +EOF +cat > /home/gpadmin/gp_hosts_list << EOF +localhost +EOF +cat > /home/gpadmin/initdb_gpdb.sql << EOF +ALTER ROLE "gpadmin" WITH PASSWORD '$PASSWORD'; +EOF + chown -R gpadmin:gpadmin /home/gpadmin + + log "$INFO_MSG Install single node Greenplum cluster success!" +} + +gpdb_install \ No newline at end of file diff --git a/open-source-greenplum-db-6.16.2-rhel7-x86_64.rpm b/open-source-greenplum-db-6.16.2-rhel7-x86_64.rpm new file mode 100644 index 0000000..3ac851e Binary files /dev/null and b/open-source-greenplum-db-6.16.2-rhel7-x86_64.rpm differ diff --git a/start.dev.cmd b/start.dev.cmd new file mode 100644 index 0000000..a466f5b --- /dev/null +++ b/start.dev.cmd @@ -0,0 +1 @@ +docker-compose build --no-cache && docker-compose up --remove-orphans --force-recreate -d \ No newline at end of file diff --git a/stop.dev.cmd b/stop.dev.cmd new file mode 100644 index 0000000..356959e --- /dev/null +++ b/stop.dev.cmd @@ -0,0 +1 @@ +docker-compose down --remove-orphans \ No newline at end of file