From 0b6c876a0f6c3be3b434b17cd9e162240d86280c Mon Sep 17 00:00:00 2001 From: colben Date: Sun, 16 Apr 2023 21:38:32 +0800 Subject: [PATCH] update --- alpine-3.15/Dockerfile | 14 ++ alpine-3.15/README.md | 11 ++ alpine-3.15/alpine.sh | 69 +++++++++ alpine/Dockerfile | 9 +- chromedriver/ADD/ccmd | 7 +- cloudreve/ADD/ccmd | 5 +- datax-web/ADD/ccmd | 7 +- datax/ADD/ccmd | 8 +- datax/datax.sh | 7 +- elasticsearch6/ADD/ccmd | 17 ++- elasticsearch7/ADD/ccmd | 19 +-- elasticsearch7/README.md | 2 +- gitea/ADD/ccmd | 138 +++++++++++++++--- gitea/Dockerfile | 18 +-- gitea/gitea.sh | 7 +- kafka/ADD/ccmd | 7 +- keepalived/ADD/ccmd | 3 +- kibana/ADD/ccmd | 13 +- letsencrypt/ADD/ccmd | 14 +- logstash6/ADD/ccmd | 7 +- mariadb/ADD/ccmd | 10 +- mariadb/Dockerfile | 2 +- mongodb/ADD/ccmd | 6 +- mysql/ADD/ccmd | 24 +-- mysql/Dockerfile | 2 +- mysql/Dockerfile-centos7 | 2 +- nginx-1.20.2/ADD/ccmd | 91 ++++++++++++ nginx-1.20.2/Demo/SingleNode/README.md | 17 +++ .../Demo/SingleNode/docker-compose.yml | 22 +++ .../Demo/SingleNode/nginx/http.d/80.conf | 5 + nginx-1.20.2/Demo/TwoNodes/README.md | 19 +++ nginx-1.20.2/Demo/TwoNodes/docker-compose.yml | 38 +++++ .../TwoNodes/keepalived/conf/keepalived.conf | 33 +++++ .../Demo/TwoNodes/nginx/http.d/80.conf | 5 + nginx-1.20.2/Dockerfile | 20 +++ nginx-1.20.2/README.md | 20 +++ nginx-1.20.2/nginx.sh | 67 +++++++++ nginx-php-7.4/ADD/ccmd | 96 ++++++++++++ nginx-php-7.4/Demo/SingleNode/README.md | 17 +++ .../Demo/SingleNode/docker-compose.yml | 25 ++++ .../Demo/SingleNode/nginx/http.d/80.conf | 25 ++++ nginx-php-7.4/Dockerfile | 26 ++++ nginx-php-7.4/README.md | 17 +++ nginx-php-7.4/nginx-php.sh | 67 +++++++++ nginx-php/ADD/ccmd | 17 ++- nginx-php/Dockerfile | 15 +- nginx-php/Dockerfile-3.9 | 2 +- nginx/ADD/ccmd | 11 +- nginx/Dockerfile | 11 +- prometheus/ADD/ccmd | 14 +- redis/ADD/ccmd | 12 +- redis/Dockerfile | 5 +- rsync/ADD/ccmd | 3 +- svn/ADD/ccmd | 3 +- tomcat/ADD/ccmd | 5 +- xxl-job/ADD/ccmd | 15 +- zabbix/ADD/ccmd | 51 ++++--- zabbix/Dockerfile | 4 +- zookeeper/ADD/ccmd | 9 +- 59 files changed, 1026 insertions(+), 189 deletions(-) create mode 100644 alpine-3.15/Dockerfile create mode 100644 alpine-3.15/README.md create mode 100755 alpine-3.15/alpine.sh create mode 100755 nginx-1.20.2/ADD/ccmd create mode 100644 nginx-1.20.2/Demo/SingleNode/README.md create mode 100644 nginx-1.20.2/Demo/SingleNode/docker-compose.yml create mode 100644 nginx-1.20.2/Demo/SingleNode/nginx/http.d/80.conf create mode 100644 nginx-1.20.2/Demo/TwoNodes/README.md create mode 100644 nginx-1.20.2/Demo/TwoNodes/docker-compose.yml create mode 100644 nginx-1.20.2/Demo/TwoNodes/keepalived/conf/keepalived.conf create mode 100644 nginx-1.20.2/Demo/TwoNodes/nginx/http.d/80.conf create mode 100644 nginx-1.20.2/Dockerfile create mode 100644 nginx-1.20.2/README.md create mode 100755 nginx-1.20.2/nginx.sh create mode 100755 nginx-php-7.4/ADD/ccmd create mode 100644 nginx-php-7.4/Demo/SingleNode/README.md create mode 100644 nginx-php-7.4/Demo/SingleNode/docker-compose.yml create mode 100644 nginx-php-7.4/Demo/SingleNode/nginx/http.d/80.conf create mode 100644 nginx-php-7.4/Dockerfile create mode 100644 nginx-php-7.4/README.md create mode 100755 nginx-php-7.4/nginx-php.sh diff --git a/alpine-3.15/Dockerfile b/alpine-3.15/Dockerfile new file mode 100644 index 0000000..026959b --- /dev/null +++ b/alpine-3.15/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine:3.15 +MAINTAINER Colben colbenlee@gmail.com +ADD --chown=root:root /ADD/ /etc/ +RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/main\n\ +https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/community\n\ +' > /etc/apk/repositories \ + && apk update \ + && apk add --no-cache bash curl coreutils iproute2 \ + && echo "alias ls='ls --color=auto'" >> /root/.bashrc \ + && rm -rf /var/cache/apk/* +ENV PS1='\[\e[33;1;1m\][\[\e[0m\]\[\e[35;1m\]\u\[\e[0m\]\[\e[33;1;1m\]@\[\e[0m\]\[\e[31;1;1m\]docker\[\e[0m\]\[\e[32;1;1m\](\h)\[\e[0m\]\[\e[33;1;1m\]:\[\e[0m\]\[\e[32m\]\w\[\e[0m\]\[\e[33;1;1m\]]\[\e[0m\]\[\e[36m\]\$\[\e[0m\] ' +ENV PS2='\[\e[36m\]>\[\e[0m\] ' +ENV LANG=en_US.UTF-8 + diff --git a/alpine-3.15/README.md b/alpine-3.15/README.md new file mode 100644 index 0000000..26d5d4e --- /dev/null +++ b/alpine-3.15/README.md @@ -0,0 +1,11 @@ +# 构建 alpine 镜像 + +## 导入文件 +- 本机时区 /etc/localtime + +## 定制 +- 使用 Asia/Shanghai 时区 +- 修改软件源,开启 edge +- 安装 bash curl coreutils iproute2 +- 默认语言 en_US.UTF-8 + diff --git a/alpine-3.15/alpine.sh b/alpine-3.15/alpine.sh new file mode 100755 index 0000000..f460068 --- /dev/null +++ b/alpine-3.15/alpine.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +#========================================= +# Author : colben +#========================================= + +set -euo pipefail +export LANG=en_US.UTF-8 + +[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" +ROOT_DIR="$(cd $(dirname $0) && pwd)" +IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:3.15" + +if [ -t 0 ]; then + function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } + function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; } + function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; } +else + function Print { echo -e "$(date +'[%F %T INFO]') $*"; } + function Warn { echo -e "$(date +'[%F %T WARN]') $*"; } + function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; } +fi + +function Quit { + local exitCode=$? + [ 0 -ne $exitCode ] && Error Failed to build or push image! + [ -z "${END:-}" ] && echo && Error Interrupted manually! + Print Succeeded to build and push image. +} + +function YesOrNo { + Warn $* + local sw= + while :; do + read -p '(Yes/No/Quit) ' -n1 sw + [[ "$sw" =~ ^Y|y$ ]] && echo && return 0 + [[ "$sw" =~ ^N|n$ ]] && echo && return 1 + [[ "$sw" =~ ^Q|q$ ]] && echo && exit 0 + [ -n "$sw" ] && echo + done +} + +function Update { + Warn Preparing localtime ... + cd $ROOT_DIR + cp -f /etc/localtime ADD/ +} + +function Build { + local yn + cd $ROOT_DIR + docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \ + && Warn Removing image $IMAGE ... \ + && docker rmi $IMAGE + Warn Building image: $IMAGE ... + docker build --force-rm -t $IMAGE . + YesOrNo Push image: $IMAGE? && docker push $IMAGE +} + +function Main { + trap Quit EXIT + Update + Build + END=1 +} + +# Start here +Main + diff --git a/alpine/Dockerfile b/alpine/Dockerfile index c498fd3..e666628 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -1,11 +1,8 @@ -FROM alpine:3.14 +FROM alpine:3.17 MAINTAINER Colben colbenlee@gmail.com ADD --chown=root:root /ADD/ /etc/ -RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.14/main\n\ -https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.14/community\n\ -https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community\n\ -https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main\n\ -https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing\n\ +RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/main\n\ +https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/community\n\ ' > /etc/apk/repositories \ && apk update \ && apk add --no-cache bash curl coreutils iproute2 \ diff --git a/chromedriver/ADD/ccmd b/chromedriver/ADD/ccmd index 13ae2d6..fc2b5d3 100755 --- a/chromedriver/ADD/ccmd +++ b/chromedriver/ADD/ccmd @@ -34,20 +34,21 @@ function Quit { function ModifyConf { local kv= - Print Modify $JAR.properties ... + Print Modifying $JAR.properties ... while read kv; do [ -z "$kv" ] && return 0 - Print Modify property: ${kv%%=*} ... + Print Modifying property: ${kv%%=*} ... sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" } function StartProc { - Print Start chromedriver ... + Print Starting chromedriver ... ./chromedriver --allowed-ips $OPTS \ >/dev/null \ 2>>logs/chromedriver.out & PIDS="$PIDS $!" + Print Chromedriver started. } function Main { diff --git a/cloudreve/ADD/ccmd b/cloudreve/ADD/ccmd index 928ba00..81b5ef6 100755 --- a/cloudreve/ADD/ccmd +++ b/cloudreve/ADD/ccmd @@ -33,7 +33,7 @@ function Quit { function ModifyConf { [ -e $DATA_DIR/cloudreve.ini ] && return 0 - Print Generate cloudreve.ini ... + Print Generating cloudreve.ini ... cat > $DATA_DIR/cloudreve.ini <<-EOF [System] Debug = false @@ -70,10 +70,11 @@ EOF } function StartProc { - Print Start cloudreve ... + Print Starting cloudreve ... rm -f /socket/cloudreve /opt/cloudreve -c $DATA_DIR/cloudreve.ini &>> $LOG_DIR/cloudreve.out & PIDS="$PIDS $!" + Print Cloudreve started. } function Main { diff --git a/datax-web/ADD/ccmd b/datax-web/ADD/ccmd index 65b0b5c..85686cc 100755 --- a/datax-web/ADD/ccmd +++ b/datax-web/ADD/ccmd @@ -40,18 +40,19 @@ function Quit { function ModifyConf { local kv= - Print Modify bootstrap.properties ... + Print Modifying bootstrap.properties ... while read kv; do [ -z "$kv" ] && return 0 - Print Modify property: ${kv%%=*} ... + Print Modifying property: ${kv%%=*} ... sed -i "/^#${kv%%=*} *=/c$kv" /opt/datax-web-2.1.2/modules/datax-admin/conf/bootstrap.properties done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" } function StartProc { - Print Start datax-web + Print Starting datax-web cd /opt/datax-web-2.1.2 /usr/bin/bash bin/start-all.sh + Print Datax-web started. tail -f /dev/null } diff --git a/datax/ADD/ccmd b/datax/ADD/ccmd index eded8b1..53c2c74 100755 --- a/datax/ADD/ccmd +++ b/datax/ADD/ccmd @@ -44,7 +44,7 @@ function Usage { } function InitPipe { - Print Init named pipe ... + Print Initing named pipe ... rm -rf pool.pipe mkfifo pool.pipe exec 1022<> pool.pipe @@ -55,7 +55,7 @@ function InitPipe { function StartJob { local job="$1" local code=0 - Print Start job $job with timeout $TIMEOUT ... + Print Starting job $job with timeout $TIMEOUT ... timeout ${TIMEOUT} java \ -server \ -Xms1g \ @@ -89,14 +89,14 @@ function StartJob { } function StartProc { - Print Start datax with max $MAX_PROCS parallel jobs ... + Print Starting datax with max $MAX_PROCS parallel jobs ... local job= for job in $(ls job/ | grep '\.json$'); do read -n 1 -u 1022 StartJob "${job%.json}" & done wait - [ -n "$job" ] || Print Not found any job! + [ -n "$job" ] && Print All jobs finished. || Print Not found any job! } function Main { diff --git a/datax/datax.sh b/datax/datax.sh index 1cd62a7..b46963a 100755 --- a/datax/datax.sh +++ b/datax/datax.sh @@ -9,7 +9,8 @@ export LANG=en_US.UTF-8 [ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" ROOT_DIR="$(cd $(dirname $0) && pwd)" -IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest" +#IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest" +IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:202303" if [ -t 0 ]; then function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } @@ -46,8 +47,8 @@ function Update { rm -rf $(ls | grep -v ccmd || true) tar zxf /release/RUNTIME/datax.tar.gz -C . rm -rf datax/tmp datax/job/*.json - rm -f datax/plugin/writer/mysqlwriter/libs/mysql-connector-java-5.1.34.jar - rm -f datax/plugin/reader/mysqlreader/libs/mysql-connector-java-5.1.34.jar + rm -f datax/plugin/writer/mysqlwriter/libs/mysql-connector-java-5.*.jar + rm -f datax/plugin/reader/mysqlreader/libs/mysql-connector-java-5.*.jar cp /release/RUNTIME/mysql-connector-java-8.0.27.jar datax/plugin/reader/mysqlreader/libs/ cp /release/RUNTIME/mysql-connector-java-8.0.27.jar datax/plugin/writer/mysqlwriter/libs/ find datax/ -type f | xargs chmod 0644 diff --git a/elasticsearch6/ADD/ccmd b/elasticsearch6/ADD/ccmd index 7b59a8b..3ec7106 100755 --- a/elasticsearch6/ADD/ccmd +++ b/elasticsearch6/ADD/ccmd @@ -46,14 +46,14 @@ function Usage { function RestoreConf { if [ -z "$(ls config/)" ]; then - Print Restore default config files and quit ... + Print Restoring default config files and quit ... tar zxf config.tgz exit fi } function ModifyConf { - Print Modify $conf ... + Print Modifying $conf ... local kv= local conf='config/elasticsearch.yml' while read kv; do @@ -61,30 +61,30 @@ function ModifyConf { sed -i "/^${kv%%=*}: /d" $conf echo "${kv/=/: }" >> $conf done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" - Print Remove path.data and path.log in $conf ... + Print Removing path.data and path.log in $conf ... sed -i -e '/^path\.data/d' -e '/^path\.logs/d' $conf } function InstallPlugin { for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do - Print Install plugins from offline file: $f ... + Print Installing plugins from offline file: $f ... ./bin/elasticsearch-plugin install file://$f mv $f $f.installed done } function ChangeOwner { - Print Change file owner ... - chown -R es.es config/ data/ logs/ plugins/ + Print Changing file owner ... + chown -R es:es config/ data/ logs/ plugins/ } function ChangeSysConf { - Print Change system conf ... + Print Changing system conf ... echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged". } function StartProc { - Print Start elasticsearch ... + Print Starting elasticsearch ... su - es -c " export JAVA_HOME=$JAVA_HOME export PATH=$PATH @@ -92,6 +92,7 @@ function StartProc { /opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs " &> /dev/null & PIDS="$PIDS $!" + Print Elasticsearch started. } function Main { diff --git a/elasticsearch7/ADD/ccmd b/elasticsearch7/ADD/ccmd index ed8ffba..7a49f53 100755 --- a/elasticsearch7/ADD/ccmd +++ b/elasticsearch7/ADD/ccmd @@ -54,7 +54,7 @@ function Usage { function RestoreConf { if [ -z "$(ls config/)" ]; then - Print Restore default config files and quit ... + Print Restoring default config files and quit ... tar zxf config.tgz exit fi @@ -63,36 +63,36 @@ function RestoreConf { function ModifyConf { local kv= local conf='config/elasticsearch.yml' - Print Modify $conf ... + Print Modifying $conf ... while read kv; do [ -z "$kv" ] && break sed -i "/^${kv%%=*}: /d" $conf echo "${kv/=/: }" >> $conf done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" - Print Remove path.data and path.log in $conf ... + Print Removing path.data and path.log in $conf ... sed -i -e '/^path\.data/d' -e '/^path\.logs/d' $conf if grep -q '^cluster\.initial_master_nodes' $conf; then [ -z "$(ls data/)" -a -n "${ELASTIC_PASSWORD:-}" ] && BOOTSTRAP=1 && return 0 - Print Remove cluster.initial_master_nodes in $conf ... + Print Removing cluster.initial_master_nodes in $conf ... sed -i '/^cluster\.initial_master_nodes/d' $conf fi } function InstallPlugin { for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do - Print Install plugins from offline file: $f ... + Print Installing plugins from offline file: $f ... ./bin/elasticsearch-plugin install file://$f mv $f $f.installed done } function ChangeOwner { - Print Change file owner ... - chown -R es.es config/ data/ logs/ plugins/ + Print Changing file owner ... + chown -R es:es config/ data/ logs/ plugins/ } function ChangeSysConf { - Print Change system conf ... + Print Changing system conf ... echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged". } @@ -125,12 +125,13 @@ ${REMOTE_MONITORING_USER_PASSWORD:-$ELASTIC_PASSWORD} } function StartProc { - Print Start elasticsearch ... + Print Starting elasticsearch ... su - es -c " export ES_JAVA_OPTS='${ES_JAVA_OPTS:-}' /opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs " &> /dev/null & PIDS="$PIDS $!" + Print Elasticsearch started. [ -z "$BOOTSTRAP" ] || SetupPassword } diff --git a/elasticsearch7/README.md b/elasticsearch7/README.md index e9aabda..1da71b5 100644 --- a/elasticsearch7/README.md +++ b/elasticsearch7/README.md @@ -24,6 +24,6 @@ ## 案例 - [Demo/SingleNode/](Demo/SingleNode/)部署单节点 -- [Demo/MultiNodes/](Demo/MultiNodes/)部署三节点 es 集群 +- [Demo/ThreeNodes/](Demo/ThreeNodes/)部署三节点 es 集群 - [Demo/MultiRoles/](Demo/MultiRoles/)部署多角色 es 集群 diff --git a/gitea/ADD/ccmd b/gitea/ADD/ccmd index bcd0d29..35f0cab 100755 --- a/gitea/ADD/ccmd +++ b/gitea/ADD/ccmd @@ -2,8 +2,7 @@ ################################################## # Mount dir # -# - /var/lib/gitea # -# - /var/log/gitea # +# - /opt/gitea # ################################################## set -euo pipefail @@ -31,39 +30,140 @@ function Quit { function Usage { Print 'This container should run with **root user** - **/var/{lib,log}/gitea mounted from host** + **/opt/gitea mounted from host** ' } -function RestoreConf { - if [ -z "$(ls gitea/)" ]; then - Print Restore default config files and quit ... - tar zxf gitea.tgz - exit - fi +function GenerateConf { + Print Generating app.ini ... + mkdir -p custom/conf + cat > custom/conf/app.ini <<-EOF +APP_NAME = Gitea +RUN_USER = gitea +RUN_MODE = prod + +[repository] +ROOT = /opt/gitea/repos +SCRIPT_TYPE = bash + +[security] +PASSWORD_COMPLEXITY = off +DISABLE_GIT_HOOKS = false + +[indexer] +ISSUE_INDEXER_TYPE = bleve +ISSUE_INDEXER_PATH = /opt/gitea/indexers/issues.bleve +REPO_INDEXER_ENABLED = true +REPO_INDEXER_PATH = /opt/gitea/indexers/repos.bleve +MAX_FILE_SIZE = 1048576 +REPO_INDEXER_INCLUDE = **.go,**.yml,**.toml,**.c,**.h,**makefile,**.py,**.txt,**.ini,**.rs,**.sh,**.md,**Dockerfile*,**docker-entrypoint*,**.cnf,**.conf,**.json,**.sql,**.xml,**.js,**.jsx,**.vue,**.ts,**.tsx,**.html,**.css,**.scss,**.less + +[queue.issue_indexer] +ISSUE_INDEXER_QUEUE_TYPE = levelqueue +ISSUE_INDEXER_QUEUE_DIR = /opt/gitea/indexers/issues.queue +UPDATE_BUFFER_LEN = 20 + +[server] +APP_DATA_PATH = /opt/gitea/data +PROTOCOL = http +HTTP_ADDR = 0.0.0.0 +HTTP_PORT = 3000 +#PROTOCOL = unix +#HTTP_ADDR = /sock/gitea +#UNIX_SOCKET_PERMISSION = 666 +#DOMAIN = x.x.x +#ROOT_URL = http://x.x.x +DISABLE_SSH = true +START_SSH_SERVER = false +SSH_DOMAIN = x.x.x +SSH_PORT = 3622 +LFS_START_SERVER = true +OFFLINE_MODE = false +ENABLE_GZIP = true + +[database] +DB_TYPE = sqlite3 +PATH = /opt/gitea/data/gitea.db +SSL_MODE = disable + +[mailer] +ENABLED = false + +[service] +REGISTER_EMAIL_CONFIRM = false +ENABLE_NOTIFY_MAIL = false +DISABLE_REGISTRATION = true +ALLOW_ONLY_EXTERNAL_REGISTRATION = false +ENABLE_CAPTCHA = true +REQUIRE_SIGNIN_VIEW = true +DEFAULT_KEEP_EMAIL_PRIVATE = true +DEFAULT_ALLOW_CREATE_ORGANIZATION = false +DEFAULT_ENABLE_TIMETRACKING = true +NO_REPLY_ADDRESS = + +[picture] +DISABLE_GRAVATAR = true +ENABLE_FEDERATED_AVATAR = false + +[openid] +ENABLE_OPENID_SIGNIN = false +ENABLE_OPENID_SIGNUP = false + +[attachment] +ENABLED = true +ALLOWED_TYPES = */* +MAX_SIZE = 1024 +MAX_FILES = 5 +STORAGE_TYPE = local +PATH = /opt/gitea/attachments + +[session] +PROVIDER = memory + +[time] +FORMAT = RFC3339 + +[log] +ROOT_PATH = /opt/gitea/log +MODE = file +LEVEL = warn +ROUTER = file + +[git] +PATH = +HOME_PATH = /opt/gitea/data/git-home + +[lfs] +PATH = /opt/gitea/lfs + +[webhook] +ALLOWED_HOST_LIST = * +EOF } function ChangeOwner { - Print Change file owner ... - chown -R gitea.www-data gitea/ /var/log/gitea/ + Print Changing file owner ... + chown -R gitea:gitea /opt/gitea } function StartProc { - Print Start gitea ... + Print Starting gitea ... su - gitea -c ' - gitea web \ - --work-path /var/lib/gitea \ - --custom-path /var/lib/gitea/custom \ - --config /var/lib/gitea/custom/conf/app.ini - ' &>> /var/log/gitea/gitea.out & + gitea \ + --work-path /opt/gitea \ + --custom-path /opt/gitea/custom \ + --config /opt/gitea/custom/conf/app.ini \ + web + ' &>> /opt/gitea/log/gitea.out & PIDS="$PIDS $!" + Print Gitea started. } function Main { local pid= - cd /var/lib + cd /opt/gitea Usage - RestoreConf + [ -e custom/conf ] || GenerateConf ChangeOwner StartProc trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM diff --git a/gitea/Dockerfile b/gitea/Dockerfile index d586ae3..c15b9e5 100644 --- a/gitea/Dockerfile +++ b/gitea/Dockerfile @@ -1,14 +1,12 @@ ARG ARCH -FROM harbor.colben.cn/general/alpine$ARCH +FROM harbor.colben.cn/general/photon$ARCH MAINTAINER Colben colbenlee@gmail.com -ADD --chown=root:root /ADD/ /opt/ -RUN sed -i -e '/testing/d' -e 's/edge/latest-stable/' /etc/apk/repositories \ - && apk update \ - && apk add --no-cache gitea \ - && sed -i 's,/ash,/bash,' /etc/passwd \ - && cd /var/lib \ - && mv /etc/gitea gitea/custom/conf \ - && tar zcf gitea.tgz gitea/ \ - && rm -rf /var/cache/apk/* gitea/* +ADD --chown=root:root /ADD/ccmd /opt/ +ADD --chown=root:root /ADD/gitea /usr/bin/gitea +RUN tdnf makecache \ + && tdnf -y install git \ + && rm -rf /var/cache/tdnf \ + && useradd -m -U gitea \ + && mkdir -p /opt/gitea/{attachments,custom,data,repos,indexers,lfs,log} CMD ["/opt/ccmd"] diff --git a/gitea/gitea.sh b/gitea/gitea.sh index 7c036fd..fb6533f 100755 --- a/gitea/gitea.sh +++ b/gitea/gitea.sh @@ -9,7 +9,8 @@ export LANG=en_US.UTF-8 [ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" ROOT_DIR="$(cd $(dirname $0) && pwd)" -IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest" +VERSION=$1 +IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:$VERSION" if [ -t 0 ]; then function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } @@ -41,7 +42,9 @@ function YesOrNo { } function Update { - : + cd $ROOT_DIR + cp -f ADD/gitea-$VERSION ADD/gitea + chmod 0755 ADD/gitea } function Build { diff --git a/kafka/ADD/ccmd b/kafka/ADD/ccmd index 90d82c9..bf3139f 100755 --- a/kafka/ADD/ccmd +++ b/kafka/ADD/ccmd @@ -39,22 +39,23 @@ function Usage { } function ModifyConf { - Print Modify server.properties ... + Print Modifying server.properties ... local kv= local conf='config/server.properties' while read kv; do [ -z "$kv" ] && break - Print Modify property: ${kv%%=*} ... + Print Modifying property: ${kv%%=*} ... sed -i "/^${kv%%=*} *=/d" $conf echo "$kv" >> $conf done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" } function StartProc { - Print Start kafka ... + Print Starting kafka ... ./bin/kafka-server-start.sh ./config/server.properties --override log.dirs=./data \ &>> logs/kafka.out & PIDS="$PIDS $!" + Print Kafka started. } function Main { diff --git a/keepalived/ADD/ccmd b/keepalived/ADD/ccmd index 494203b..91e89c1 100755 --- a/keepalived/ADD/ccmd +++ b/keepalived/ADD/ccmd @@ -34,10 +34,11 @@ function Quit { } function StartProc { - Print Start keeplived ... + Print Starting keeplived ... rm -rf /var/run/keepalived keepalived -f /etc/keepalived/keepalived.conf -lDGn &>> $LOG_DIR/keepalived.log & PIDS="$PIDS $!" + Print Keeplived started. } function Main { diff --git a/kibana/ADD/ccmd b/kibana/ADD/ccmd index 28f0ec2..9e5319f 100755 --- a/kibana/ADD/ccmd +++ b/kibana/ADD/ccmd @@ -43,7 +43,7 @@ function Usage { function RestoreConf { if [ -z "$(ls config/)" ]; then - Print Restore default config files and quit ... + Print Restoring default config files and quit ... tar zxf config.tgz exit fi @@ -52,7 +52,7 @@ function RestoreConf { function ModifyConf { local kv= local conf='config/kibana.yml' - Print Modify $conf ... + Print Modifying $conf ... while read kv; do [ -z "$kv" ] && break sed -i "/^${kv%%=*}: /d" $conf @@ -62,24 +62,25 @@ function ModifyConf { function InstallPlugin { for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do - Print Install plugins from offline file: $f ... + Print Installing plugins from offline file: $f ... ./bin/kibana-plugin install file://$f mv $f $f.installed done } function ChangeOwner { - Print Change file owner ... - chown -R kibana.kibana config/ data/ logs/ plugins/ + Print Changing file owner ... + chown -R kibana:kibana config/ data/ logs/ plugins/ } function StartProc { - Print Start kibana ... + Print Starting kibana ... su - kibana -c " export NODE_OPTIONS='${NODE_OPTIONS:-}' /opt/kibana/bin/kibana " &>> logs/kibana.out & PIDS="$PIDS $!" + Print Kibana started. } function Main { diff --git a/letsencrypt/ADD/ccmd b/letsencrypt/ADD/ccmd index 6f8d0d3..79c2fa3 100755 --- a/letsencrypt/ADD/ccmd +++ b/letsencrypt/ADD/ccmd @@ -39,32 +39,34 @@ function Usage { function StartProc { if [ ! -e /etc/letsencrypt/accounts ]; then - Print Register ... + Print Registering ... certbot register --register-unsafely-without-email --agree-tos if echo "$DOMAINS" | grep -qo '^*'; then - Print Request wildcard certificate ... + Print Requesting wildcard certificate ... certbot certonly -q --manual \ --manual-auth-hook /etc/letsencrypt/manual-hook.sh \ -d "$DOMAINS" --preferred-challenges dns \ --server https://acme-v02.api.letsencrypt.org/directory else - Print Request certificate ... + Print Requesting certificate ... certbot certonly -q -n --standalone -d $DOMAINS fi - Print Generate dhparam.pem ... + Print Generating dhparam.pem ... openssl dhparam -out /etc/letsencrypt/dhparam.pem 2048 \ &>/var/log/letsencrypt/dhparam.out + Print Succeeded to request certificate. else if echo "$DOMAINS" | grep -qo '^*'; then - Print Renew wildcard certificate ... + Print Renewing wildcard certificate ... certbot certonly --force-renewal -q --manual \ --manual-auth-hook /etc/letsencrypt/manual-hook.sh \ -d "$DOMAINS" --preferred-challenges dns \ --server https://acme-v02.api.letsencrypt.org/directory else - Print Renew certificate ... + Print Renewing certificate ... certbot renew -q --force-renewal fi + Print Succeeded to renew certificate. fi } diff --git a/logstash6/ADD/ccmd b/logstash6/ADD/ccmd index 79d91ea..6dcbd6c 100755 --- a/logstash6/ADD/ccmd +++ b/logstash6/ADD/ccmd @@ -39,7 +39,7 @@ function Usage { function RestoreConf { if [ -z "$(ls config/)" ]; then - Print Restore default config files and quit ... + Print Restoring default config files and quit ... tar zxf config.tgz GOT_SIGTERM=1 exit 0 @@ -48,20 +48,21 @@ function RestoreConf { function InstallPlugin { for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do - Print Install plugins from offline file: $f ... + Print Installing plugins from offline file: $f ... ./bin/logstash-plugin install file://$f mv $f $f.installed done } function StartProc { - Print Start logstash ... + Print Starting logstash ... ./bin/logstash \ --path.data /opt/logstash/data \ --path.logs /opt/logstash/logs \ --path.settings /opt/logstash/config \ &>> logs/logstash.out & PIDS="$PIDS $!" + Print Logstash started. } function Main { diff --git a/mariadb/ADD/ccmd b/mariadb/ADD/ccmd index 647f62f..733401f 100755 --- a/mariadb/ADD/ccmd +++ b/mariadb/ADD/ccmd @@ -41,9 +41,9 @@ function Quit { function Init { rm -f $SOCK_FILE $PID_FILE - chown -R mysql.mysql $LOG_DIR $BINLOG_DIR $DATA_DIR + chown -R mysql:mysql $LOG_DIR $BINLOG_DIR $DATA_DIR if [ ! -d "$DATA_DIR/mysql" ]; then - Print Init mysql db files ... + Print Initing mysql db files ... mysql_install_db --user=mysql > /dev/null INIT_FLAG=1 fi @@ -52,7 +52,7 @@ function Init { function StartProc { local sql_file= local sql_files= - Print Start mysql ... + Print Starting mysql ... mysqld -u mysql & PIDS="$PIDS $!" while sleep 1; do @@ -61,12 +61,12 @@ function StartProc { done echo if [ -n "$INIT_FLAG" ]; then - Print Secure database ... + Print Securing database ... mysql_secure_installation <<< "$(echo -e '\nn\nn\n\n\n\n\n')" > /dev/null mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'" mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost" if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then - Print Import the sql files ... + Print Importing the sql files ... for sql_file in $sql_files; do Print Importing $sql_file ... mysql < $sql_file diff --git a/mariadb/Dockerfile b/mariadb/Dockerfile index 243e185..9c76083 100644 --- a/mariadb/Dockerfile +++ b/mariadb/Dockerfile @@ -26,6 +26,6 @@ password = China_19$(10)!\n\ ' > /etc/mysql/my.cnf \ && sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \ && mkdir -p /var/log/mysql /var/lib/mysql-bin /run/mysqld \ - && chown -R mysql.mysql /var/log/mysql /var/lib/mysql-bin /run/mysqld + && chown -R mysql:mysql /var/log/mysql /var/lib/mysql-bin /run/mysqld CMD ["/opt/ccmd"] diff --git a/mongodb/ADD/ccmd b/mongodb/ADD/ccmd index ef9b04f..14c7d48 100755 --- a/mongodb/ADD/ccmd +++ b/mongodb/ADD/ccmd @@ -36,13 +36,13 @@ function Quit { } function Init { - Print Init mongod ... - chown -R mongod.mongod $LOG_DIR $DATA_DIR + Print Initing mongod ... + chown -R mongod:mongod $LOG_DIR $DATA_DIR rm -f /tmp/mongodb-27017.sock } function StartProc { - Print Start mongodb ... + Print Starting mongodb ... su - mongod -c "mongod \ --port 27017 \ --dbpath $DATA_DIR \ diff --git a/mysql/ADD/ccmd b/mysql/ADD/ccmd index 8c8a89e..60de37e 100755 --- a/mysql/ADD/ccmd +++ b/mysql/ADD/ccmd @@ -62,7 +62,7 @@ function ProbeSeeds { [ "$all_seeds" = "$other_seeds" ] \ && Print Not found local_address in group_seeds! \ && exit 1 - Print Probe connection to other seeds ... + Print Probing connection to other seeds ... for seed in $other_seeds; do echo -n "Connecting $seed ... " curl -s --connect-timeout 8 ftp://$seed || seed_return=$? @@ -76,10 +76,10 @@ function ProbeSeeds { function Init { rm -f ${SOCK_FILE}* ${PID_FILE} - chown -R mysql.mysql $LOG_DIR $BINLOG_DIR $DATA_DIR + chown -R mysql:mysql $LOG_DIR $BINLOG_DIR $DATA_DIR if [ ! -d "$DATA_DIR/mysql" ]; then - Print Write essential server config to /etc/mysql/my.cnf ... - Print Init mysql db files ... + Print Writing essential server config to /etc/mysql/my.cnf ... + Print Initing mysql db files ... mysqld_pre_systemd INIT_FLAG=1 fi @@ -87,7 +87,7 @@ function Init { function InitGroupReplication { if ! grep -i '^group[-_]replication' /etc/my.cnf; then - Print Write advisable group replication config to /etc/my.cnf ... + Print Writing advisable group replication config to /etc/my.cnf ... grep -i '^binlog[-_]expire[-_]logs[-_]seconds' /etc/my.cnf \ || echo 'binlog-expire-logs-seconds = 172800' >> /etc/my.cnf echo 'group-replication-consistency = BEFORE_ON_PRIMARY_FAILOVER @@ -98,7 +98,7 @@ group-replication-exit-state-action = OFFLINE_MODE ' >> /etc/my.cnf fi if ! grep -i '^group[-_]replication' /etc/mysql/my.cnf; then - Print Write essential group replication config to /etc/mysql/my.cnf ... + Print Writing essential group replication config to /etc/mysql/my.cnf ... cat >> /etc/mysql/my.cnf <<-EOF server-id = $SERVER_ID gtid-mode = ON @@ -127,7 +127,7 @@ function ImportInitSql { mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'" mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost" if sql_files="$(ls $LOG_DIR/init_sql/*.sql 2>/dev/null)"; then - Print Import the sql files ... + Print Importing the sql files ... for sql_file in $sql_files; do Print Importing $sql_file ... mysql < $sql_file @@ -138,20 +138,20 @@ function ImportInitSql { function StartGroupReplication { if [ -n "$BOOTSTRAP_GROUP" ]; then - Print Bootstrap new group replication ... + Print Bootstraping new group replication ... mysql -e " SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF; " else - Print Join a running group replication ... + Print Joining a running group replication ... mysql -e "START GROUP_REPLICATION;" fi } function CreateGroupReplicationChannel { - Print Create user and channel of group replication ... + Print Creating user and channel of group replication ... mysql -e "SET SQL_LOG_BIN=0; CREATE USER rpl@'%' IDENTIFIED BY 'Rpl_1234'; GRANT REPLICATION SLAVE ON *.* TO rpl@'%'; @@ -166,7 +166,7 @@ function CreateGroupReplicationChannel { } function StartExtraScripts { - Print Start extra scripts ... + Print Starting extra scripts ... while sleep 2; do for script in $(find $LOG_DIR/extra_scripts/ -type f -executable \ 2>/dev/null || true); do @@ -176,7 +176,7 @@ function StartExtraScripts { } function StartProc { - Print Start mysql ... + Print Starting mysql ... mysqld -u mysql & PIDS="$PIDS $!" while sleep 1; do diff --git a/mysql/Dockerfile b/mysql/Dockerfile index bfc7cde..4d52143 100644 --- a/mysql/Dockerfile +++ b/mysql/Dockerfile @@ -32,7 +32,7 @@ gpgcheck=0\n\ && mkdir -p /var/log/mysql \ /var/lib/mysql-bin \ /etc/mysql \ - && chown -R mysql.mysql \ + && chown -R mysql:mysql \ /var/log/mysql \ /var/lib/mysql-bin \ && sed -i -e 's,--initialize,&-insecure,g' \ diff --git a/mysql/Dockerfile-centos7 b/mysql/Dockerfile-centos7 index ae037fa..312cd14 100644 --- a/mysql/Dockerfile-centos7 +++ b/mysql/Dockerfile-centos7 @@ -32,7 +32,7 @@ gpgcheck=0\n\ && mkdir -p /var/log/mysql \ /var/lib/mysql-bin \ /etc/mysql \ - && chown -R mysql.mysql \ + && chown -R mysql:mysql \ /var/log/mysql \ /var/lib/mysql-bin \ && sed -i -e 's,--initialize,&-insecure,g' \ diff --git a/nginx-1.20.2/ADD/ccmd b/nginx-1.20.2/ADD/ccmd new file mode 100755 index 0000000..f8f8860 --- /dev/null +++ b/nginx-1.20.2/ADD/ccmd @@ -0,0 +1,91 @@ +#!/bin/bash + +################################################## +# Mount dir # +# - /etc/nginx/stream.d # +# - /etc/nginx/http.d # +# - /var/lib/nginx/html # +# - /var/log/nginx # +# ENV # +# - GLOBAL_DIRECTIVES # +################################################## + +set -euo pipefail +export LANG=en_US.UTF-8 +trap Quit EXIT + +PIDS= +GOT_SIGTERM= +GLOBAL_DIRECTIVES="${GLOBAL_DIRECTIVES:-user nginx;worker_processes auto;}" + +function Print { + local file=/dev/null + [ '-f' = "$1" ] && file=$2 && shift && shift + date +"[%F %T] $*" | tee -a $file +} + +function Quit { + local running + Print killing nginx ... + nginx -s quit || true + while running= ; do + pkill -f sleep && running=1 && Print killing sleep ... + pkill -f nginx && running=1 && Print killing nginx ... + [ -z "$running" ] && break + sleep 1 + done + Print Container stopped. + test -n "$GOT_SIGTERM" +} + +function ChangeOwner { + Print Changing file owner ... + chown nginx:root /var/log/nginx/ +} + +function SideCar { + local day= last_day=$(date +%d) + local md5= last_md5=$(find /etc/nginx/ -type f -name "*.conf" \ + | xargs -I ^ md5sum ^ | md5sum) + while sleep 10; do + day=$(date +%d) \ + && [ "$day" != "$last_day" ] \ + && last_day=$day \ + && find /var/log/nginx/ -type f -name "*.log" \ + | xargs -I ^ mv -f ^ ^.$(date +%F -d yesterday) \ + && nginx -s reopen + md5=$(find /etc/nginx/ -type f -name "*.conf" | xargs -I ^ md5sum ^ \ + | md5sum) \ + && [ "$md5" != "$last_md5" ] \ + && last_md5=$md5 \ + && nginx -tq \ + && Print Reloading nginx conf ... \ + && nginx -s reload + done +} + +function StartProc { + Print Starting nginx ... + nginx -g "$GLOBAL_DIRECTIVES" & + PIDS="$PIDS $!" + Print Starting nginx sidecar ... + SideCar & + PIDS="$PIDS $!" + Print Nginx started. +} + +function Main { + local pid= + ChangeOwner + StartProc + trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM + while [ -z "$GOT_SIGTERM" ] && sleep 1; do + for pid in $PIDS; do + [ ! -e /proc/$pid ] && Print Unexpected error! && exit + done + done +} + +# Start here +Main + diff --git a/nginx-1.20.2/Demo/SingleNode/README.md b/nginx-1.20.2/Demo/SingleNode/README.md new file mode 100644 index 0000000..b4919b0 --- /dev/null +++ b/nginx-1.20.2/Demo/SingleNode/README.md @@ -0,0 +1,17 @@ +# 部署单节点 nginx + +- 根据实际环境修改 + - docker-compose.yml + - nginx/http.d/80.conf + +- 创建目录 + ``` + grep '\'" + interval 10 + weight 0 + fall 2 + rise 2 +} + +vrrp_instance VI_1 { + state BACKUP + virtual_router_id 14 + priority 150 # 在另一台服务器中,这里配置100 + advert_int 2 + nopreempt + interface eth0 # 这里的 eth0 是服务器的网卡名 + track_script { + chk_nginx + } + authentication { + auth_type PASS + auth_pass El_en_nginx_1234 + } + virtual_ipaddress { + 虚拟IP/掩码 dev eth0 # 这里的eth0是服务器的网卡名 + } +} + diff --git a/nginx-1.20.2/Demo/TwoNodes/nginx/http.d/80.conf b/nginx-1.20.2/Demo/TwoNodes/nginx/http.d/80.conf new file mode 100644 index 0000000..46b4e36 --- /dev/null +++ b/nginx-1.20.2/Demo/TwoNodes/nginx/http.d/80.conf @@ -0,0 +1,5 @@ +server { + listen 80; + location / {} +} + diff --git a/nginx-1.20.2/Dockerfile b/nginx-1.20.2/Dockerfile new file mode 100644 index 0000000..8d95f02 --- /dev/null +++ b/nginx-1.20.2/Dockerfile @@ -0,0 +1,20 @@ +ARG ARCH +FROM harbor.colben.cn/general/alpine$ARCH:3.15 +MAINTAINER Colben colbenlee@gmail.com +ADD --chown=root:root /ADD/ /opt/ +RUN apk update \ + && apk add --no-cache nginx nginx-mod-stream \ + && sed -i \ + -e '1a\\n# Added by Dockerfile' \ + -e '1adaemon off;' \ + -e '1apid /run/nginx/nginx.pid;' \ + -e '1aworker_rlimit_nofile 65535;' \ + -e '/^user /s/^/#/' \ + -e '/^worker_processes /s/^/#/' \ + -e '/worker_connections/s/[0-9]\+/10240/' \ + /etc/nginx/nginx.conf \ + && chown nginx:nginx /run/nginx \ + && chmod 0755 /var/lib/nginx \ + && rm -rf /var/cache/apk/* /etc/nginx/http.d/* +CMD ["/opt/ccmd"] + diff --git a/nginx-1.20.2/README.md b/nginx-1.20.2/README.md new file mode 100644 index 0000000..c838605 --- /dev/null +++ b/nginx-1.20.2/README.md @@ -0,0 +1,20 @@ +# 构建 nginx 镜像 + +## 定制 +- 安装 nginx +- 固定一些常用配置 +- 每 10 秒扫描一次配置文件,有变更会立即 reload + +## 外挂目录和文件 +- /etc/nginx/stream.d: nginx stream 配置文件 +- /etc/nginx/http.d: nginx http 配置文件 +- /var/lib/nginx/html: nginx 前端文件存放目录 +- /var/log/nginx: nginx 日志目录 + +## 引入环境变量 +- GLOBAL_DIRECTIVES: 一般用不到 + +## 案例 +- [Demo/SingleNode/](Demo/SingleNode/): 单节点 +- [Demo/TwoNodes/](Demo/TwoNodes/): 两节点+高可用 + diff --git a/nginx-1.20.2/nginx.sh b/nginx-1.20.2/nginx.sh new file mode 100755 index 0000000..460c5f3 --- /dev/null +++ b/nginx-1.20.2/nginx.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +#========================================= +# Author : colben +#========================================= + +set -euo pipefail +export LANG=en_US.UTF-8 + +[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" +ROOT_DIR="$(cd $(dirname $0) && pwd)" +IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:1.20.2" + +if [ -t 0 ]; then + function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } + function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; } + function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; } +else + function Print { echo -e "$(date +'[%F %T INFO]') $*"; } + function Warn { echo -e "$(date +'[%F %T WARN]') $*"; } + function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; } +fi + +function Quit { + local exitCode=$? + [ 0 -ne $exitCode ] && Error Failed to build or push image! + [ -z "${END:-}" ] && echo && Error Interrupted manually! + Print Succeeded to build and push image. +} + +function YesOrNo { + Warn $* + local sw= + while :; do + read -p '(Yes/No/Quit) ' -n1 sw + [[ "$sw" =~ ^Y|y$ ]] && echo && return 0 + [[ "$sw" =~ ^N|n$ ]] && echo && return 1 + [[ "$sw" =~ ^Q|q$ ]] && echo && exit 0 + [ -n "$sw" ] && echo + done +} + +function Update { + : +} + +function Build { + local yn + cd $ROOT_DIR + docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \ + && Warn Removing image $IMAGE ... \ + && docker rmi $IMAGE + Warn Building image: $IMAGE ... + docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE . + YesOrNo Push image: $IMAGE? && docker push $IMAGE +} + +function Main { + trap Quit EXIT + Update + Build + END=1 +} + +# Start here +Main + diff --git a/nginx-php-7.4/ADD/ccmd b/nginx-php-7.4/ADD/ccmd new file mode 100755 index 0000000..9b9780f --- /dev/null +++ b/nginx-php-7.4/ADD/ccmd @@ -0,0 +1,96 @@ +#!/bin/bash + +################################################## +# Mount dir # +# - /etc/nginx/stream.d # +# - /etc/nginx/http.d # +# - /var/lib/nginx/html # +# - /var/log/nginx # +# - /var/log/php7 # +# ENV # +# - GLOBAL_DIRECTIVES # +################################################## + +set -euo pipefail +export LANG=en_US.UTF-8 +trap Quit EXIT + +PIDS= +GOT_SIGTERM= +GLOBAL_DIRECTIVES="${GLOBAL_DIRECTIVES:-user nginx;worker_processes auto;}" + +function Print { + local file=/dev/null + [ '-f' = "$1" ] && file=$2 && shift && shift + date +"[%F %T] $*" | tee -a $file +} + +function Quit { + local running + Print killing nginx ... + nginx -s quit || true + while running= ; do + pkill -f php-fpm7 && running=1 && Print killing php-fpm7 ... + pkill -f sleep && running=1 && Print killing sleep ... + pkill -f nginx && running=1 && Print killing nginx ... + [ -z "$running" ] && break + sleep 1 + done + Print Container stopped. + test -n "$GOT_SIGTERM" +} + +function ChangeOwner { + Print Changing file owner ... + chown nginx:root /var/log/nginx/ +} + +function SideCar { + local day= last_day=$(date +%d) + local md5= last_md5=$(find /etc/nginx/ -type f -name "*.conf" \ + | xargs -I ^ md5sum ^ | md5sum) + while sleep 10; do + day=$(date +%d) \ + && [ "$day" != "$last_day" ] \ + && last_day=$day \ + && find /var/log/nginx/ -type f -name "*.log" \ + | xargs -I ^ mv -f ^ ^.$(date +%F -d yesterday) \ + && nginx -s reopen + md5=$(find /etc/nginx/ -type f -name "*.conf" | xargs -I ^ md5sum ^ \ + | md5sum) \ + && [ "$md5" != "$last_md5" ] \ + && last_md5=$md5 \ + && nginx -tq \ + && Print Reloading nginx conf ... \ + && nginx -s reload + done +} + +function StartProc { + Print Start php ... + php-fpm7 -F -y /etc/php7/php-fpm.conf & + PIDS="$PIDS $!" + Print Start nginx ... + nginx -g "$GLOBAL_DIRECTIVES" & + PIDS="$PIDS $!" + Print Start nginx sidecar ... + SideCar & + PIDS="$PIDS $!" + Print Nginx and php started. +} + +function Main { + local pid= + ChangeOwner + StartProc + trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM + while [ -z "$GOT_SIGTERM" ] && sleep 1; do + for pid in $PIDS; do + [ ! -e /proc/$pid ] && Print Unexpected error! && exit + done + done +} + +# Start here +Main + diff --git a/nginx-php-7.4/Demo/SingleNode/README.md b/nginx-php-7.4/Demo/SingleNode/README.md new file mode 100644 index 0000000..29dbe9c --- /dev/null +++ b/nginx-php-7.4/Demo/SingleNode/README.md @@ -0,0 +1,17 @@ +# 部署单节点 nginx-php + +- 根据实际环境修改 + - docker-compose.yml + - nginx/http.d/80.conf + +- 创建目录 + ``` + grep '\> $LOG_DIR/loki.out & PIDS="$PIDS $!" sleep 2 - Print Start sidecar ... + Print Starting sidecar ... SideCar & PIDS="$PIDS $!" + + Print All components started. } function Main { diff --git a/redis/ADD/ccmd b/redis/ADD/ccmd index ba13f2c..d744bee 100755 --- a/redis/ADD/ccmd +++ b/redis/ADD/ccmd @@ -52,8 +52,8 @@ function Quit { function ModifyConf { local kv= local clusterEnabled= - [ -e /etc/redis.conf ] && Print /etc/redis.conf already exists && return 0 - Print Modify conf ... + [ -e /etc/redis.conf ] && Print /etc/redis.conf already exists. && return 0 + Print Modifying conf ... echo "bind 0.0.0.0 protected-mode no maxmemory 6442450944 @@ -69,7 +69,7 @@ maxmemory-policy volatile-random } function DeployCluster { - Print Deploy redis cluster ... + Print Deploying redis cluster ... local i= local node= local nodesId= @@ -91,11 +91,11 @@ function DeployCluster { Print $node not enable cluster mode! && exit 100 done done - Print Create redis cluster with master nodes: ${MASTER_NODES[@]} + Print Creating redis cluster with master nodes: ${MASTER_NODES[@]} $redisCliCmd --cluster-yes --cluster create ${MASTER_NODES[@]} nodesId="$($redisCliCmd -s $SOCK_FILE cluster nodes | cut -d@ -f1)" for i in ${!SLAVE_NODES[@]}; do - Print Add slave node ${SLAVE_NODES[$i]} with master: ${MASTER_NODES[$i]} + Print Adding slave node ${SLAVE_NODES[$i]} with master: ${MASTER_NODES[$i]} $redisCliCmd --cluster-yes --cluster add-node ${SLAVE_NODES[$i]} \ ${MASTER_NODES[0]} --cluster-slave \ --cluster-master-id $(echo "$nodesId" \ @@ -112,7 +112,7 @@ function Init { } function StartProc { - Print Start Redis ... + Print Starting Redis ... redis-server /etc/redis.conf \ --daemonize no \ --dir $DATA_DIR \ diff --git a/redis/Dockerfile b/redis/Dockerfile index 753e88a..75fbae2 100644 --- a/redis/Dockerfile +++ b/redis/Dockerfile @@ -3,8 +3,9 @@ FROM harbor.colben.cn/general/alpine$ARCH MAINTAINER Colben colbenlee@gmail.com ADD --chown=root:root /ADD/ /opt/ RUN apk update \ - && apk add --no-cache redis \ + && curl -sSLO https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/main/x86_64/redis-6.2.9-r0.apk \ + && apk add --allow-untrusted redis-6.2.9-r0.apk \ && mv /etc/redis.conf /etc/redis.conf.origin \ - && rm -rf /var/cache/apk/* + && rm -rf /var/cache/apk/* redis-6.2.9-r0.apk CMD ["/opt/ccmd"] diff --git a/rsync/ADD/ccmd b/rsync/ADD/ccmd index 9aceee9..f59bd67 100755 --- a/rsync/ADD/ccmd +++ b/rsync/ADD/ccmd @@ -33,7 +33,7 @@ function Quit { } function StartProc { - Print Start rsync ... + Print Starting rsync ... rm -f /var/run/rsyncd.pid rsync --daemon \ --no-detach \ @@ -42,6 +42,7 @@ function StartProc { --dparam=pidfile=/var/run/rsyncd.pid \ &>> $LOG_DIR/rsyncd.out & PIDS="$PIDS $!" + Print Rsync started. } function Main { diff --git a/svn/ADD/ccmd b/svn/ADD/ccmd index bdee1b7..562b8b4 100755 --- a/svn/ADD/ccmd +++ b/svn/ADD/ccmd @@ -34,7 +34,7 @@ function Quit { } function StartProc { - Print Start svn ${EXTRA_ARGS:-} ... + Print Starting svn ${EXTRA_ARGS:-} ... svnserve \ ${EXTRA_ARGS:-} \ -d --foreground \ @@ -44,6 +44,7 @@ function StartProc { --log-file $LOG_DIR/svn.log \ &>> $LOG_DIR/svn.out & PIDS="$PIDS $!" + Print Svn started. } function Main { diff --git a/tomcat/ADD/ccmd b/tomcat/ADD/ccmd index f7d2dff..789fa3a 100755 --- a/tomcat/ADD/ccmd +++ b/tomcat/ADD/ccmd @@ -36,16 +36,17 @@ function Quit { function RestoreConf { if [ -z "$(ls conf/)" ]; then - Print Restore default config files and quit ... + Print Restoring default config files and quit ... tar zxf conf.tgz exit fi } function StartProc { - Print Start tomcat ... + Print Starting tomcat ... ./bin/catalina.sh run &>> $CATALINA_OUT & PIDS="$PIDS $!" + Print Tomcat started. } function Main { diff --git a/xxl-job/ADD/ccmd b/xxl-job/ADD/ccmd index 5ea6a45..aac82cb 100755 --- a/xxl-job/ADD/ccmd +++ b/xxl-job/ADD/ccmd @@ -34,22 +34,23 @@ function Quit { function ModifyConf { sed -i 's/^M//g' $JAR.properties local kv= - Print Modify $JAR.properties ... + Print Modifying $JAR.properties ... while read kv; do [ -z "$kv" ] && return 0 - Print Modify property: ${kv%%=*} ... + Print Modifying property: ${kv%%=*} ... sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" } function StartProc { - Print Start $JAR ... + Print Starting $JAR ... java $JAVA_OPTS \ - -jar $JAR.jar \ - --spring.config.location=$JAR.properties \ - >/dev/null \ - 2>>logs/$JAR.out & + -jar $JAR.jar \ + --spring.config.location=$JAR.properties \ + >/dev/null \ + 2>>logs/$JAR.out & PIDS="$PIDS $!" + Print $JAR started. } function Main { diff --git a/zabbix/ADD/ccmd b/zabbix/ADD/ccmd index 7467097..3874b64 100755 --- a/zabbix/ADD/ccmd +++ b/zabbix/ADD/ccmd @@ -12,6 +12,8 @@ # - /var/log/nginx # # - /var/log/php7 # # - /var/log/zabbix # +# ENV # +# - GLOBAL_DIERECTIVES # ################################################## set -euo pipefail @@ -26,6 +28,7 @@ BINLOG_DIR='/var/lib/mysql-bin' INIT_FLAG=${INIT_FLAG:-} SOCK_FILE='/run/mysqld/mysqld.sock' PID_FILE='/run/mysqld/mysqld.pid' +GLOBAL_DIRECTIVES="${GLOBAL_DIRECTIVES:-user nginx;worker_processes auto;}" function Print { local file=/dev/null @@ -49,14 +52,14 @@ function Quit { } function RestoreConf { - ! ls /etc/nginx/conf.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \ - && Print Restore /etc/nginx/conf.d/zabbix.conf ... \ - && cp /usr/share/zabbix/nginx.conf /etc/nginx/conf.d/zabbix.conf + ! ls /etc/nginx/http.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \ + && Print Restoring /etc/nginx/http.d/zabbix.conf ... \ + && cp /usr/share/zabbix/nginx.conf /etc/nginx/http.d/zabbix.conf [ ! -e /etc/zabbix/zabbix_proxy.conf ] \ - && Print Restore /etc/zabbix/zabbix_proxy.conf ... \ + && Print Restoring /etc/zabbix/zabbix_proxy.conf ... \ && cp /usr/share/zabbix/zabbix_proxy.conf /etc/zabbix/zabbix_proxy.conf [ ! -e /etc/zabbix/zabbix_server.conf ] \ - && Print Restore /etc/zabbix/zabbix_server.conf ... \ + && Print Restoring /etc/zabbix/zabbix_server.conf ... \ && cp /usr/share/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf return 0 } @@ -77,23 +80,23 @@ function SideCar { && [ "$md5" != "$last_md5" ] \ && last_md5=$md5 \ && nginx -tq \ - && Print Reload nginx conf ... \ + && Print Reloading nginx conf ... \ && nginx -s reload done } function InitDB { rm -f $SOCK_FILE $PID_FILE - chown -R mysql.mysql $LOG_DIR $BINLOG_DIR $DATA_DIR + chown -R mysql:mysql $LOG_DIR $BINLOG_DIR $DATA_DIR if [ ! -d "$DATA_DIR/mysql" ]; then - Print Install database ... + Print Installing database ... mysql_install_db --user=mysql > /dev/null INIT_FLAG=1 fi } function StartProc { - Print Start mysql ... + Print Starting mysql ... mysqld -u mysql & PIDS="$PIDS $!" while sleep 1; do @@ -102,20 +105,24 @@ function StartProc { done echo if [ -n "$INIT_FLAG" ]; then - Print Secure database ... + Print Securing database ... mysql_secure_installation <<< "$(echo -e '\nn\nn\n\n\n\n\n')" > /dev/null - Print Create zabbix db and user ... + Print Creating zabbix db and user ... mysql -e "CREATE DATABASE zabbix DEFAULT CHARSET UTF8 COLLATE UTF8_BIN" mysql -e "CREATE USER zabbix@localhost" mysql -e "GRANT ALL ON zabbix.* TO zabbix@localhost" - Print Import zabbix schema.sql ... + Print Importing zabbix schema.sql ... mysql -Dzabbix < /usr/share/zabbix/database/mysql/schema.sql - Print Import zabbix images.sql ... + Print Importing zabbix images.sql ... mysql -Dzabbix < /usr/share/zabbix/database/mysql/images.sql - Print Import zabbix data.sql ... + Print Importing zabbix history_pk_prepare.sql ... + mysql -Dzabbix < /usr/share/zabbix/database/mysql/history_pk_prepare.sql + Print Importing zabbix double.sql ... + mysql -Dzabbix < /usr/share/zabbix/database/mysql/double.sql + Print Importing zabbix data.sql ... mysql -Dzabbix < /usr/share/zabbix/database/mysql/data.sql if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then - Print Import the sql files ... + Print Importing the sql files ... for sql_file in $sql_files; do Print Importing $sql_file ... mysql < $sql_file @@ -127,21 +134,23 @@ function StartProc { RestoreConf - Print Start php ... - php-fpm7 -F -y /etc/php7/php-fpm.conf & + Print Starting php ... + php-fpm81 -F -y /etc/php81/php-fpm.conf & PIDS="$PIDS $!" - Print Start zabbix ... + Print Starting zabbix ... zabbix_server -f & PIDS="$PIDS $!" - Print Start nginx ... - nginx -g 'daemon off;pid /run/nginx/nginx.pid;' & + Print Starting nginx ... + nginx -g "$GLOBAL_DIRECTIVES" & PIDS="$PIDS $!" - Print Start nginx sidecar ... + Print Starting nginx sidecar ... SideCar & PIDS="$PIDS $!" + + Print All components started. } function Main { diff --git a/zabbix/Dockerfile b/zabbix/Dockerfile index f65a668..035d250 100644 --- a/zabbix/Dockerfile +++ b/zabbix/Dockerfile @@ -21,7 +21,7 @@ lower-case-table-names = 1\n\ ' > /etc/mysql/my.cnf \ && sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \ && mkdir -p /var/log/mysql /var/lib/mysql-bin /run/mysqld \ - && chown -R mysql.mysql /var/log/mysql /var/lib/mysql-bin /run/mysqld \ + && chown -R mysql:mysql /var/log/mysql /var/lib/mysql-bin /run/mysqld \ && chmod -R 0777 /usr/share/webapps/zabbix/conf \ && sed -i '/^#* *AllowRoot *=/cAllowRoot=1' /etc/zabbix/zabbix_server.conf \ && mv /etc/zabbix/* /usr/share/zabbix/ \ @@ -41,7 +41,7 @@ lower-case-table-names = 1\n\ expires -1s;\n\ include fastcgi_params;\n\ try_files $uri =404;\n\ - fastcgi_pass unix:/var/lib/php7/phpfpm.sock;\n\ + fastcgi_pass unix:/var/lib/php81/phpfpm.sock;\n\ fastcgi_index index.php;\n\ fastcgi_param PATH_INFO $fastcgi_path_info;\n\ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n\ diff --git a/zookeeper/ADD/ccmd b/zookeeper/ADD/ccmd index abaac88..a50bbc4 100755 --- a/zookeeper/ADD/ccmd +++ b/zookeeper/ADD/ccmd @@ -41,27 +41,28 @@ function Usage { } function ModifyConf { - Print Modify server.properties ... + Print Modifying server.properties ... local kv= local conf='conf/zoo.cfg' while read kv; do [ -z "$kv" ] && break - Print Modify property: ${kv%%=*} ... + Print Modifying property: ${kv%%=*} ... sed -i "/^${kv%%=*} *=/d" $conf echo "$kv" >> $conf done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" sed -i -e '/^dataDir/d' -e '/^dataLogDir/d' $conf echo -e 'dataDir=/opt/zk/data\ndataLogDir=/opt/zk/dataLog' >> $conf if [ ! -e data/myid ]; then - Print Generate myid ... + Print Generating myid ... echo $MYID > data/myid fi } function StartProc { - Print Start zookeeper ... + Print Starting zookeeper ... ./bin/zkServer.sh start-foreground &>> logs/zk.out & PIDS="$PIDS $!" + Print Zookeeper started. } function Main {