This commit is contained in:
colben 2023-04-16 21:38:32 +08:00
parent a0849e40ef
commit 0b6c876a0f
59 changed files with 1026 additions and 189 deletions

14
alpine-3.15/Dockerfile Normal file
View File

@ -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

11
alpine-3.15/README.md Normal file
View File

@ -0,0 +1,11 @@
# 构建 alpine 镜像
## 导入文件
- 本机时区 /etc/localtime
## 定制
- 使用 Asia/Shanghai 时区
- 修改软件源,开启 edge
- 安装 bash curl coreutils iproute2
- 默认语言 en_US.UTF-8

69
alpine-3.15/alpine.sh Executable file
View File

@ -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

View File

@ -1,11 +1,8 @@
FROM alpine:3.14 FROM alpine:3.17
MAINTAINER Colben colbenlee@gmail.com MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /etc/ ADD --chown=root:root /ADD/ /etc/
RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.14/main\n\ RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/main\n\
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.14/community\n\ https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/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\
' > /etc/apk/repositories \ ' > /etc/apk/repositories \
&& apk update \ && apk update \
&& apk add --no-cache bash curl coreutils iproute2 \ && apk add --no-cache bash curl coreutils iproute2 \

View File

@ -34,20 +34,21 @@ function Quit {
function ModifyConf { function ModifyConf {
local kv= local kv=
Print Modify $JAR.properties ... Print Modifying $JAR.properties ...
while read kv; do while read kv; do
[ -z "$kv" ] && return 0 [ -z "$kv" ] && return 0
Print Modify property: ${kv%%=*} ... Print Modifying property: ${kv%%=*} ...
sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
} }
function StartProc { function StartProc {
Print Start chromedriver ... Print Starting chromedriver ...
./chromedriver --allowed-ips $OPTS \ ./chromedriver --allowed-ips $OPTS \
>/dev/null \ >/dev/null \
2>>logs/chromedriver.out & 2>>logs/chromedriver.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Chromedriver started.
} }
function Main { function Main {

View File

@ -33,7 +33,7 @@ function Quit {
function ModifyConf { function ModifyConf {
[ -e $DATA_DIR/cloudreve.ini ] && return 0 [ -e $DATA_DIR/cloudreve.ini ] && return 0
Print Generate cloudreve.ini ... Print Generating cloudreve.ini ...
cat > $DATA_DIR/cloudreve.ini <<-EOF cat > $DATA_DIR/cloudreve.ini <<-EOF
[System] [System]
Debug = false Debug = false
@ -70,10 +70,11 @@ EOF
} }
function StartProc { function StartProc {
Print Start cloudreve ... Print Starting cloudreve ...
rm -f /socket/cloudreve rm -f /socket/cloudreve
/opt/cloudreve -c $DATA_DIR/cloudreve.ini &>> $LOG_DIR/cloudreve.out & /opt/cloudreve -c $DATA_DIR/cloudreve.ini &>> $LOG_DIR/cloudreve.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Cloudreve started.
} }
function Main { function Main {

View File

@ -40,18 +40,19 @@ function Quit {
function ModifyConf { function ModifyConf {
local kv= local kv=
Print Modify bootstrap.properties ... Print Modifying bootstrap.properties ...
while read kv; do while read kv; do
[ -z "$kv" ] && return 0 [ -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 sed -i "/^#${kv%%=*} *=/c$kv" /opt/datax-web-2.1.2/modules/datax-admin/conf/bootstrap.properties
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
} }
function StartProc { function StartProc {
Print Start datax-web Print Starting datax-web
cd /opt/datax-web-2.1.2 cd /opt/datax-web-2.1.2
/usr/bin/bash bin/start-all.sh /usr/bin/bash bin/start-all.sh
Print Datax-web started.
tail -f /dev/null tail -f /dev/null
} }

View File

@ -44,7 +44,7 @@ function Usage {
} }
function InitPipe { function InitPipe {
Print Init named pipe ... Print Initing named pipe ...
rm -rf pool.pipe rm -rf pool.pipe
mkfifo pool.pipe mkfifo pool.pipe
exec 1022<> pool.pipe exec 1022<> pool.pipe
@ -55,7 +55,7 @@ function InitPipe {
function StartJob { function StartJob {
local job="$1" local job="$1"
local code=0 local code=0
Print Start job $job with timeout $TIMEOUT ... Print Starting job $job with timeout $TIMEOUT ...
timeout ${TIMEOUT} java \ timeout ${TIMEOUT} java \
-server \ -server \
-Xms1g \ -Xms1g \
@ -89,14 +89,14 @@ function StartJob {
} }
function StartProc { function StartProc {
Print Start datax with max $MAX_PROCS parallel jobs ... Print Starting datax with max $MAX_PROCS parallel jobs ...
local job= local job=
for job in $(ls job/ | grep '\.json$'); do for job in $(ls job/ | grep '\.json$'); do
read -n 1 -u 1022 read -n 1 -u 1022
StartJob "${job%.json}" & StartJob "${job%.json}" &
done done
wait wait
[ -n "$job" ] || Print Not found any job! [ -n "$job" ] && Print All jobs finished. || Print Not found any job!
} }
function Main { function Main {

View File

@ -9,7 +9,8 @@ export LANG=en_US.UTF-8
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" [ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)" 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 if [ -t 0 ]; then
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } 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) rm -rf $(ls | grep -v ccmd || true)
tar zxf /release/RUNTIME/datax.tar.gz -C . tar zxf /release/RUNTIME/datax.tar.gz -C .
rm -rf datax/tmp datax/job/*.json 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/writer/mysqlwriter/libs/mysql-connector-java-5.*.jar
rm -f datax/plugin/reader/mysqlreader/libs/mysql-connector-java-5.1.34.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/reader/mysqlreader/libs/
cp /release/RUNTIME/mysql-connector-java-8.0.27.jar datax/plugin/writer/mysqlwriter/libs/ cp /release/RUNTIME/mysql-connector-java-8.0.27.jar datax/plugin/writer/mysqlwriter/libs/
find datax/ -type f | xargs chmod 0644 find datax/ -type f | xargs chmod 0644

View File

@ -46,14 +46,14 @@ function Usage {
function RestoreConf { function RestoreConf {
if [ -z "$(ls config/)" ]; then if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ... Print Restoring default config files and quit ...
tar zxf config.tgz tar zxf config.tgz
exit exit
fi fi
} }
function ModifyConf { function ModifyConf {
Print Modify $conf ... Print Modifying $conf ...
local kv= local kv=
local conf='config/elasticsearch.yml' local conf='config/elasticsearch.yml'
while read kv; do while read kv; do
@ -61,30 +61,30 @@ function ModifyConf {
sed -i "/^${kv%%=*}: /d" $conf sed -i "/^${kv%%=*}: /d" $conf
echo "${kv/=/: }" >> $conf echo "${kv/=/: }" >> $conf
done <<< "$(env | grep '^_CONF_' | sed 's/_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 sed -i -e '/^path\.data/d' -e '/^path\.logs/d' $conf
} }
function InstallPlugin { function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do 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 ./bin/elasticsearch-plugin install file://$f
mv $f $f.installed mv $f $f.installed
done done
} }
function ChangeOwner { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown -R es.es config/ data/ logs/ plugins/ chown -R es:es config/ data/ logs/ plugins/
} }
function ChangeSysConf { function ChangeSysConf {
Print Change system conf ... Print Changing system conf ...
echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged". echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged".
} }
function StartProc { function StartProc {
Print Start elasticsearch ... Print Starting elasticsearch ...
su - es -c " su - es -c "
export JAVA_HOME=$JAVA_HOME export JAVA_HOME=$JAVA_HOME
export PATH=$PATH export PATH=$PATH
@ -92,6 +92,7 @@ function StartProc {
/opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs /opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs
" &> /dev/null & " &> /dev/null &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Elasticsearch started.
} }
function Main { function Main {

View File

@ -54,7 +54,7 @@ function Usage {
function RestoreConf { function RestoreConf {
if [ -z "$(ls config/)" ]; then if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ... Print Restoring default config files and quit ...
tar zxf config.tgz tar zxf config.tgz
exit exit
fi fi
@ -63,36 +63,36 @@ function RestoreConf {
function ModifyConf { function ModifyConf {
local kv= local kv=
local conf='config/elasticsearch.yml' local conf='config/elasticsearch.yml'
Print Modify $conf ... Print Modifying $conf ...
while read kv; do while read kv; do
[ -z "$kv" ] && break [ -z "$kv" ] && break
sed -i "/^${kv%%=*}: /d" $conf sed -i "/^${kv%%=*}: /d" $conf
echo "${kv/=/: }" >> $conf echo "${kv/=/: }" >> $conf
done <<< "$(env | grep '^_CONF_' | sed 's/_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 sed -i -e '/^path\.data/d' -e '/^path\.logs/d' $conf
if grep -q '^cluster\.initial_master_nodes' $conf; then if grep -q '^cluster\.initial_master_nodes' $conf; then
[ -z "$(ls data/)" -a -n "${ELASTIC_PASSWORD:-}" ] && BOOTSTRAP=1 && return 0 [ -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 sed -i '/^cluster\.initial_master_nodes/d' $conf
fi fi
} }
function InstallPlugin { function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do 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 ./bin/elasticsearch-plugin install file://$f
mv $f $f.installed mv $f $f.installed
done done
} }
function ChangeOwner { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown -R es.es config/ data/ logs/ plugins/ chown -R es:es config/ data/ logs/ plugins/
} }
function ChangeSysConf { function ChangeSysConf {
Print Change system conf ... Print Changing system conf ...
echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged". echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged".
} }
@ -125,12 +125,13 @@ ${REMOTE_MONITORING_USER_PASSWORD:-$ELASTIC_PASSWORD}
} }
function StartProc { function StartProc {
Print Start elasticsearch ... Print Starting elasticsearch ...
su - es -c " su - es -c "
export ES_JAVA_OPTS='${ES_JAVA_OPTS:-}' export ES_JAVA_OPTS='${ES_JAVA_OPTS:-}'
/opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs /opt/es/bin/elasticsearch -Epath.data=/opt/es/data -Epath.logs=/opt/es/logs
" &> /dev/null & " &> /dev/null &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Elasticsearch started.
[ -z "$BOOTSTRAP" ] || SetupPassword [ -z "$BOOTSTRAP" ] || SetupPassword
} }

View File

@ -24,6 +24,6 @@
## 案例 ## 案例
- [Demo/SingleNode/](Demo/SingleNode/)部署单节点 - [Demo/SingleNode/](Demo/SingleNode/)部署单节点
- [Demo/MultiNodes/](Demo/MultiNodes/)部署三节点 es 集群 - [Demo/ThreeNodes/](Demo/ThreeNodes/)部署三节点 es 集群
- [Demo/MultiRoles/](Demo/MultiRoles/)部署多角色 es 集群 - [Demo/MultiRoles/](Demo/MultiRoles/)部署多角色 es 集群

View File

@ -2,8 +2,7 @@
################################################## ##################################################
# Mount dir # # Mount dir #
# - /var/lib/gitea # # - /opt/gitea #
# - /var/log/gitea #
################################################## ##################################################
set -euo pipefail set -euo pipefail
@ -31,39 +30,140 @@ function Quit {
function Usage { function Usage {
Print 'This container should run with Print 'This container should run with
**root user** **root user**
**/var/{lib,log}/gitea mounted from host** **/opt/gitea mounted from host**
' '
} }
function RestoreConf { function GenerateConf {
if [ -z "$(ls gitea/)" ]; then Print Generating app.ini ...
Print Restore default config files and quit ... mkdir -p custom/conf
tar zxf gitea.tgz cat > custom/conf/app.ini <<-EOF
exit APP_NAME = Gitea
fi 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 { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown -R gitea.www-data gitea/ /var/log/gitea/ chown -R gitea:gitea /opt/gitea
} }
function StartProc { function StartProc {
Print Start gitea ... Print Starting gitea ...
su - gitea -c ' su - gitea -c '
gitea web \ gitea \
--work-path /var/lib/gitea \ --work-path /opt/gitea \
--custom-path /var/lib/gitea/custom \ --custom-path /opt/gitea/custom \
--config /var/lib/gitea/custom/conf/app.ini --config /opt/gitea/custom/conf/app.ini \
' &>> /var/log/gitea/gitea.out & web
' &>> /opt/gitea/log/gitea.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Gitea started.
} }
function Main { function Main {
local pid= local pid=
cd /var/lib cd /opt/gitea
Usage Usage
RestoreConf [ -e custom/conf ] || GenerateConf
ChangeOwner ChangeOwner
StartProc StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM

View File

@ -1,14 +1,12 @@
ARG ARCH ARG ARCH
FROM harbor.colben.cn/general/alpine$ARCH FROM harbor.colben.cn/general/photon$ARCH
MAINTAINER Colben colbenlee@gmail.com MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/ ADD --chown=root:root /ADD/ccmd /opt/
RUN sed -i -e '/testing/d' -e 's/edge/latest-stable/' /etc/apk/repositories \ ADD --chown=root:root /ADD/gitea /usr/bin/gitea
&& apk update \ RUN tdnf makecache \
&& apk add --no-cache gitea \ && tdnf -y install git \
&& sed -i 's,/ash,/bash,' /etc/passwd \ && rm -rf /var/cache/tdnf \
&& cd /var/lib \ && useradd -m -U gitea \
&& mv /etc/gitea gitea/custom/conf \ && mkdir -p /opt/gitea/{attachments,custom,data,repos,indexers,lfs,log}
&& tar zcf gitea.tgz gitea/ \
&& rm -rf /var/cache/apk/* gitea/*
CMD ["/opt/ccmd"] CMD ["/opt/ccmd"]

View File

@ -9,7 +9,8 @@ export LANG=en_US.UTF-8
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)" [ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)" 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 if [ -t 0 ]; then
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; } function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
@ -41,7 +42,9 @@ function YesOrNo {
} }
function Update { function Update {
: cd $ROOT_DIR
cp -f ADD/gitea-$VERSION ADD/gitea
chmod 0755 ADD/gitea
} }
function Build { function Build {

View File

@ -39,22 +39,23 @@ function Usage {
} }
function ModifyConf { function ModifyConf {
Print Modify server.properties ... Print Modifying server.properties ...
local kv= local kv=
local conf='config/server.properties' local conf='config/server.properties'
while read kv; do while read kv; do
[ -z "$kv" ] && break [ -z "$kv" ] && break
Print Modify property: ${kv%%=*} ... Print Modifying property: ${kv%%=*} ...
sed -i "/^${kv%%=*} *=/d" $conf sed -i "/^${kv%%=*} *=/d" $conf
echo "$kv" >> $conf echo "$kv" >> $conf
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
} }
function StartProc { function StartProc {
Print Start kafka ... Print Starting kafka ...
./bin/kafka-server-start.sh ./config/server.properties --override log.dirs=./data \ ./bin/kafka-server-start.sh ./config/server.properties --override log.dirs=./data \
&>> logs/kafka.out & &>> logs/kafka.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Kafka started.
} }
function Main { function Main {

View File

@ -34,10 +34,11 @@ function Quit {
} }
function StartProc { function StartProc {
Print Start keeplived ... Print Starting keeplived ...
rm -rf /var/run/keepalived rm -rf /var/run/keepalived
keepalived -f /etc/keepalived/keepalived.conf -lDGn &>> $LOG_DIR/keepalived.log & keepalived -f /etc/keepalived/keepalived.conf -lDGn &>> $LOG_DIR/keepalived.log &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Keeplived started.
} }
function Main { function Main {

View File

@ -43,7 +43,7 @@ function Usage {
function RestoreConf { function RestoreConf {
if [ -z "$(ls config/)" ]; then if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ... Print Restoring default config files and quit ...
tar zxf config.tgz tar zxf config.tgz
exit exit
fi fi
@ -52,7 +52,7 @@ function RestoreConf {
function ModifyConf { function ModifyConf {
local kv= local kv=
local conf='config/kibana.yml' local conf='config/kibana.yml'
Print Modify $conf ... Print Modifying $conf ...
while read kv; do while read kv; do
[ -z "$kv" ] && break [ -z "$kv" ] && break
sed -i "/^${kv%%=*}: /d" $conf sed -i "/^${kv%%=*}: /d" $conf
@ -62,24 +62,25 @@ function ModifyConf {
function InstallPlugin { function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do 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 ./bin/kibana-plugin install file://$f
mv $f $f.installed mv $f $f.installed
done done
} }
function ChangeOwner { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown -R kibana.kibana config/ data/ logs/ plugins/ chown -R kibana:kibana config/ data/ logs/ plugins/
} }
function StartProc { function StartProc {
Print Start kibana ... Print Starting kibana ...
su - kibana -c " su - kibana -c "
export NODE_OPTIONS='${NODE_OPTIONS:-}' export NODE_OPTIONS='${NODE_OPTIONS:-}'
/opt/kibana/bin/kibana /opt/kibana/bin/kibana
" &>> logs/kibana.out & " &>> logs/kibana.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Kibana started.
} }
function Main { function Main {

View File

@ -39,32 +39,34 @@ function Usage {
function StartProc { function StartProc {
if [ ! -e /etc/letsencrypt/accounts ]; then if [ ! -e /etc/letsencrypt/accounts ]; then
Print Register ... Print Registering ...
certbot register --register-unsafely-without-email --agree-tos certbot register --register-unsafely-without-email --agree-tos
if echo "$DOMAINS" | grep -qo '^*'; then if echo "$DOMAINS" | grep -qo '^*'; then
Print Request wildcard certificate ... Print Requesting wildcard certificate ...
certbot certonly -q --manual \ certbot certonly -q --manual \
--manual-auth-hook /etc/letsencrypt/manual-hook.sh \ --manual-auth-hook /etc/letsencrypt/manual-hook.sh \
-d "$DOMAINS" --preferred-challenges dns \ -d "$DOMAINS" --preferred-challenges dns \
--server https://acme-v02.api.letsencrypt.org/directory --server https://acme-v02.api.letsencrypt.org/directory
else else
Print Request certificate ... Print Requesting certificate ...
certbot certonly -q -n --standalone -d $DOMAINS certbot certonly -q -n --standalone -d $DOMAINS
fi fi
Print Generate dhparam.pem ... Print Generating dhparam.pem ...
openssl dhparam -out /etc/letsencrypt/dhparam.pem 2048 \ openssl dhparam -out /etc/letsencrypt/dhparam.pem 2048 \
&>/var/log/letsencrypt/dhparam.out &>/var/log/letsencrypt/dhparam.out
Print Succeeded to request certificate.
else else
if echo "$DOMAINS" | grep -qo '^*'; then if echo "$DOMAINS" | grep -qo '^*'; then
Print Renew wildcard certificate ... Print Renewing wildcard certificate ...
certbot certonly --force-renewal -q --manual \ certbot certonly --force-renewal -q --manual \
--manual-auth-hook /etc/letsencrypt/manual-hook.sh \ --manual-auth-hook /etc/letsencrypt/manual-hook.sh \
-d "$DOMAINS" --preferred-challenges dns \ -d "$DOMAINS" --preferred-challenges dns \
--server https://acme-v02.api.letsencrypt.org/directory --server https://acme-v02.api.letsencrypt.org/directory
else else
Print Renew certificate ... Print Renewing certificate ...
certbot renew -q --force-renewal certbot renew -q --force-renewal
fi fi
Print Succeeded to renew certificate.
fi fi
} }

View File

@ -39,7 +39,7 @@ function Usage {
function RestoreConf { function RestoreConf {
if [ -z "$(ls config/)" ]; then if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ... Print Restoring default config files and quit ...
tar zxf config.tgz tar zxf config.tgz
GOT_SIGTERM=1 GOT_SIGTERM=1
exit 0 exit 0
@ -48,20 +48,21 @@ function RestoreConf {
function InstallPlugin { function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do 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 ./bin/logstash-plugin install file://$f
mv $f $f.installed mv $f $f.installed
done done
} }
function StartProc { function StartProc {
Print Start logstash ... Print Starting logstash ...
./bin/logstash \ ./bin/logstash \
--path.data /opt/logstash/data \ --path.data /opt/logstash/data \
--path.logs /opt/logstash/logs \ --path.logs /opt/logstash/logs \
--path.settings /opt/logstash/config \ --path.settings /opt/logstash/config \
&>> logs/logstash.out & &>> logs/logstash.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Logstash started.
} }
function Main { function Main {

View File

@ -41,9 +41,9 @@ function Quit {
function Init { function Init {
rm -f $SOCK_FILE $PID_FILE 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 if [ ! -d "$DATA_DIR/mysql" ]; then
Print Init mysql db files ... Print Initing mysql db files ...
mysql_install_db --user=mysql > /dev/null mysql_install_db --user=mysql > /dev/null
INIT_FLAG=1 INIT_FLAG=1
fi fi
@ -52,7 +52,7 @@ function Init {
function StartProc { function StartProc {
local sql_file= local sql_file=
local sql_files= local sql_files=
Print Start mysql ... Print Starting mysql ...
mysqld -u mysql & mysqld -u mysql &
PIDS="$PIDS $!" PIDS="$PIDS $!"
while sleep 1; do while sleep 1; do
@ -61,12 +61,12 @@ function StartProc {
done done
echo echo
if [ -n "$INIT_FLAG" ]; then 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_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 "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost" mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost"
if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then 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 for sql_file in $sql_files; do
Print Importing $sql_file ... Print Importing $sql_file ...
mysql < $sql_file mysql < $sql_file

View File

@ -26,6 +26,6 @@ password = China_19$(10)!\n\
' > /etc/mysql/my.cnf \ ' > /etc/mysql/my.cnf \
&& sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \ && sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \
&& mkdir -p /var/log/mysql /var/lib/mysql-bin /run/mysqld \ && 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"] CMD ["/opt/ccmd"]

View File

@ -36,13 +36,13 @@ function Quit {
} }
function Init { function Init {
Print Init mongod ... Print Initing mongod ...
chown -R mongod.mongod $LOG_DIR $DATA_DIR chown -R mongod:mongod $LOG_DIR $DATA_DIR
rm -f /tmp/mongodb-27017.sock rm -f /tmp/mongodb-27017.sock
} }
function StartProc { function StartProc {
Print Start mongodb ... Print Starting mongodb ...
su - mongod -c "mongod \ su - mongod -c "mongod \
--port 27017 \ --port 27017 \
--dbpath $DATA_DIR \ --dbpath $DATA_DIR \

View File

@ -62,7 +62,7 @@ function ProbeSeeds {
[ "$all_seeds" = "$other_seeds" ] \ [ "$all_seeds" = "$other_seeds" ] \
&& Print Not found local_address in group_seeds! \ && Print Not found local_address in group_seeds! \
&& exit 1 && exit 1
Print Probe connection to other seeds ... Print Probing connection to other seeds ...
for seed in $other_seeds; do for seed in $other_seeds; do
echo -n "Connecting $seed ... " echo -n "Connecting $seed ... "
curl -s --connect-timeout 8 ftp://$seed || seed_return=$? curl -s --connect-timeout 8 ftp://$seed || seed_return=$?
@ -76,10 +76,10 @@ function ProbeSeeds {
function Init { function Init {
rm -f ${SOCK_FILE}* ${PID_FILE} 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 if [ ! -d "$DATA_DIR/mysql" ]; then
Print Write essential server config to /etc/mysql/my.cnf ... Print Writing essential server config to /etc/mysql/my.cnf ...
Print Init mysql db files ... Print Initing mysql db files ...
mysqld_pre_systemd mysqld_pre_systemd
INIT_FLAG=1 INIT_FLAG=1
fi fi
@ -87,7 +87,7 @@ function Init {
function InitGroupReplication { function InitGroupReplication {
if ! grep -i '^group[-_]replication' /etc/my.cnf; then 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 \ grep -i '^binlog[-_]expire[-_]logs[-_]seconds' /etc/my.cnf \
|| echo 'binlog-expire-logs-seconds = 172800' >> /etc/my.cnf || echo 'binlog-expire-logs-seconds = 172800' >> /etc/my.cnf
echo 'group-replication-consistency = BEFORE_ON_PRIMARY_FAILOVER echo 'group-replication-consistency = BEFORE_ON_PRIMARY_FAILOVER
@ -98,7 +98,7 @@ group-replication-exit-state-action = OFFLINE_MODE
' >> /etc/my.cnf ' >> /etc/my.cnf
fi fi
if ! grep -i '^group[-_]replication' /etc/mysql/my.cnf; then 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 cat >> /etc/mysql/my.cnf <<-EOF
server-id = $SERVER_ID server-id = $SERVER_ID
gtid-mode = ON gtid-mode = ON
@ -127,7 +127,7 @@ function ImportInitSql {
mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'" mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost" mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost"
if sql_files="$(ls $LOG_DIR/init_sql/*.sql 2>/dev/null)"; then 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 for sql_file in $sql_files; do
Print Importing $sql_file ... Print Importing $sql_file ...
mysql < $sql_file mysql < $sql_file
@ -138,20 +138,20 @@ function ImportInitSql {
function StartGroupReplication { function StartGroupReplication {
if [ -n "$BOOTSTRAP_GROUP" ]; then if [ -n "$BOOTSTRAP_GROUP" ]; then
Print Bootstrap new group replication ... Print Bootstraping new group replication ...
mysql -e " mysql -e "
SET GLOBAL group_replication_bootstrap_group=ON; SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION; START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF; SET GLOBAL group_replication_bootstrap_group=OFF;
" "
else else
Print Join a running group replication ... Print Joining a running group replication ...
mysql -e "START GROUP_REPLICATION;" mysql -e "START GROUP_REPLICATION;"
fi fi
} }
function CreateGroupReplicationChannel { 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; mysql -e "SET SQL_LOG_BIN=0;
CREATE USER rpl@'%' IDENTIFIED BY 'Rpl_1234'; CREATE USER rpl@'%' IDENTIFIED BY 'Rpl_1234';
GRANT REPLICATION SLAVE ON *.* TO rpl@'%'; GRANT REPLICATION SLAVE ON *.* TO rpl@'%';
@ -166,7 +166,7 @@ function CreateGroupReplicationChannel {
} }
function StartExtraScripts { function StartExtraScripts {
Print Start extra scripts ... Print Starting extra scripts ...
while sleep 2; do while sleep 2; do
for script in $(find $LOG_DIR/extra_scripts/ -type f -executable \ for script in $(find $LOG_DIR/extra_scripts/ -type f -executable \
2>/dev/null || true); do 2>/dev/null || true); do
@ -176,7 +176,7 @@ function StartExtraScripts {
} }
function StartProc { function StartProc {
Print Start mysql ... Print Starting mysql ...
mysqld -u mysql & mysqld -u mysql &
PIDS="$PIDS $!" PIDS="$PIDS $!"
while sleep 1; do while sleep 1; do

View File

@ -32,7 +32,7 @@ gpgcheck=0\n\
&& mkdir -p /var/log/mysql \ && mkdir -p /var/log/mysql \
/var/lib/mysql-bin \ /var/lib/mysql-bin \
/etc/mysql \ /etc/mysql \
&& chown -R mysql.mysql \ && chown -R mysql:mysql \
/var/log/mysql \ /var/log/mysql \
/var/lib/mysql-bin \ /var/lib/mysql-bin \
&& sed -i -e 's,--initialize,&-insecure,g' \ && sed -i -e 's,--initialize,&-insecure,g' \

View File

@ -32,7 +32,7 @@ gpgcheck=0\n\
&& mkdir -p /var/log/mysql \ && mkdir -p /var/log/mysql \
/var/lib/mysql-bin \ /var/lib/mysql-bin \
/etc/mysql \ /etc/mysql \
&& chown -R mysql.mysql \ && chown -R mysql:mysql \
/var/log/mysql \ /var/log/mysql \
/var/lib/mysql-bin \ /var/lib/mysql-bin \
&& sed -i -e 's,--initialize,&-insecure,g' \ && sed -i -e 's,--initialize,&-insecure,g' \

91
nginx-1.20.2/ADD/ccmd Executable file
View File

@ -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

View File

@ -0,0 +1,17 @@
# 部署单节点 nginx
- 根据实际环境修改
- docker-compose.yml
- nginx/http.d/80.conf
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 上传可能需要的前端文件到 nginx/html/ 下
- 启动
```
docker-compose up -d
```

View File

@ -0,0 +1,22 @@
version: "3.7"
services:
nginx:
image: harbor.colben.cn/general/nginx:1.20.2
container_name: nginx
restart: "on-failure"
stop_grace_period: 5m
privileged: true
ports:
- 80:80
volumes:
- type: bind
source: ./nginx/html
target: /var/lib/nginx/html
- type: bind
source: ./nginx/http.d
target: /etc/nginx/http.d
- type: bind
source: ./nginx/log
target: /var/log/nginx

View File

@ -0,0 +1,5 @@
server {
listen 80;
location / {}
}

View File

@ -0,0 +1,19 @@
# 部署 nginx 双节点+高可用
- 在两台服务器上都执行下面操作
- 根据实际环境修改
- docker-compose.yml
- keepalived/conf/keepalived.conf
- nginx/http.d/80.conf
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 上传可能需要的前端文件到 nginx/html/ 下
- 启动
```
docker-compose up -d
```

View File

@ -0,0 +1,38 @@
version: "3.7"
services:
keepalived:
image: harbor.colben.cn/general/keepalived
container_name: keepalived
restart: "on-failure"
stop_grace_period: 1m
privileged: true
network_mode: host
volumes:
- type: bind
source: ./keepalived/conf
target: /etc/keepalived
- type: bind
source: ./keepalived/log
target: /var/log/keepalived
nginx:
image: harbor.colben.cn/general/nginx:1.20.2
container_name: nginx
restart: "on-failure"
stop_grace_period: 1m
network_mode: host
volumes:
- type: bind
source: ./nginx/html
target: /var/lib/nginx/html
- type: bind
source: ./nginx/http.d
target: /etc/nginx/http.d
- type: bind
source: ./nginx/stream.d
target: /etc/nginx/stream.d
- type: bind
source: ./nginx/log
target: /var/log/nginx

View File

@ -0,0 +1,33 @@
global_defs {
router_id nginx1 # 在另一台服务器中,这里配置 nginx2
script_user root
enable_script_security
}
vrrp_script chk_nginx {
script "/sbin/ss -lnt | grep -q ':80\>'"
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是服务器的网卡名
}
}

View File

@ -0,0 +1,5 @@
server {
listen 80;
location / {}
}

20
nginx-1.20.2/Dockerfile Normal file
View File

@ -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"]

20
nginx-1.20.2/README.md Normal file
View File

@ -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/): 两节点+高可用

67
nginx-1.20.2/nginx.sh Executable file
View File

@ -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

96
nginx-php-7.4/ADD/ccmd Executable file
View File

@ -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

View File

@ -0,0 +1,17 @@
# 部署单节点 nginx-php
- 根据实际环境修改
- docker-compose.yml
- nginx/http.d/80.conf
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 上传可能需要的前端文件到 nginx/html/ 下
- 启动
```
docker-compose up -d
```

View File

@ -0,0 +1,25 @@
version: "3.7"
services:
nginx-php:
image: harbor.colben.cn/general/nginx-php
container_name: nginx-php
restart: "on-failure"
stop_grace_period: 5m
privileged: true
ports:
- 80:80
volumes:
- type: bind
source: ./nginx/html
target: /var/lib/nginx/html
- type: bind
source: ./nginx/http.d
target: /etc/nginx/http.d
- type: bind
source: ./nginx/log
target: /var/log/nginx
- type: bind
source: ./php7/log
target: /var/log/php7

View File

@ -0,0 +1,25 @@
server {
listen 80;
location /xxxx/ {}
location ~ ^/xxxx/.+\.php$ {
client_max_body_size 1024m;
client_body_buffer_size 1024m;
fastcgi_buffer_size 256k;
fastcgi_buffers 8 256k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 512k;
expires -1s;
include fastcgi_params;
try_files $uri =404;
fastcgi_pass unix:/var/lib/php7/phpfpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
break;
}
location / {
return 403;
}
}

26
nginx-php-7.4/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
ARG ARCH
FROM harbor.colben.cn/general/nginx$ARCH:1.20.2
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/
RUN sed -i '/edge/d' /etc/apk/repositories \
&& apk update \
&& apk add --no-cache php7 php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \
php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \
php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7-fpm \
php7-mbstring php7-mysqlnd php7-bcmath php7-session php7-openssl php7-opcache composer \
&& sed -i -e '/^;* *max_execution_time *=/cmax_execution_time = 300' \
-e '/^;* *memory_limit *=/cmemory_limit = 1024M' \
-e '/^;* *post_max_size *=/cpost_max_size = 1024M' \
-e '/^;* *upload_max_filesize *=/cupload_max_filesize = 1024M' \
-e '/^;* *max_input_time *=/cmax_input_time = 300' \
-e '/^;* *max_input_vars *=/cmax_input_vars = 10000' \
-e '/^;* *date.timezone *=/cdate.timezone = PRC' \
-e '/^;* *pdo_mysql.default_socket *=/cpdo_mysql.default_socket = /run/mysqld/mysqld.sock' \
-e '/^;* *mysqli.default_socket *=/cmysqli.default_socket = /run/mysqld/mysqld.sock' \
/etc/php7/php.ini \
&& sed -i -e '/^;* *listen *=/clisten = /var/lib/php7/phpfpm.sock' \
-e '/^;* *listen.mode *=/clisten.mode = 0666' \
/etc/php7/php-fpm.d/www.conf \
&& rm -rf /var/cache/apk/*
CMD ["/opt/ccmd"]

17
nginx-php-7.4/README.md Normal file
View File

@ -0,0 +1,17 @@
# 构建 nginx-php 镜像
## 定制
- 安装 nginx 和 php7
- 固定一些常用配置
- 每 10 秒扫描一次配置文件,有变更会立即 reload
## 外挂目录和文件
- /etc/nginx/stream.d: nginx stream 配置文件
- /etc/nginx/http.d: nginx http 配置文件
- /var/lib/nginx/html: nginx 前端文件存放目录
- /var/log/nginx: nginx 日志目录
- /var/log/php7: php7 日志目录
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 部署 nginx-php

67
nginx-php-7.4/nginx-php.sh Executable file
View File

@ -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:7.4"
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

View File

@ -30,10 +30,10 @@ function Quit {
Print killing nginx ... Print killing nginx ...
nginx -s quit || true nginx -s quit || true
while running= ; do while running= ; do
pkill -f php-fpm7 && running=1 && Print killing php-fpm7 ... pkill -f php-fpm81 && running=1 && Print killing php-fpm81 ...
pkill -f sleep && running=1 && Print killing sleep ... pkill -f sleep && running=1 && Print killing sleep ...
pkill -f nginx && running=1 && Print killing nginx ... pkill -f nginx && running=1 && Print killing nginx ...
[ -z "$running" ] && break [ -z "$running" ] && break
sleep 1 sleep 1
done done
Print Container stopped. Print Container stopped.
@ -41,8 +41,8 @@ function Quit {
} }
function ChangeOwner { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown nginx.root /var/log/nginx/ chown nginx:root /var/log/nginx/
} }
function SideCar { function SideCar {
@ -61,14 +61,14 @@ function SideCar {
&& [ "$md5" != "$last_md5" ] \ && [ "$md5" != "$last_md5" ] \
&& last_md5=$md5 \ && last_md5=$md5 \
&& nginx -tq \ && nginx -tq \
&& Print Reload nginx conf ... \ && Print Reloading nginx conf ... \
&& nginx -s reload && nginx -s reload
done done
} }
function StartProc { function StartProc {
Print Start php ... Print Start php ...
php-fpm7 -F -y /etc/php7/php-fpm.conf & php-fpm81 -F -y /etc/php81/php-fpm.conf &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Start nginx ... Print Start nginx ...
nginx -g "$GLOBAL_DIRECTIVES" & nginx -g "$GLOBAL_DIRECTIVES" &
@ -76,6 +76,7 @@ function StartProc {
Print Start nginx sidecar ... Print Start nginx sidecar ...
SideCar & SideCar &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Nginx and php started.
} }
function Main { function Main {

View File

@ -4,10 +4,11 @@ MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/ ADD --chown=root:root /ADD/ /opt/
RUN sed -i '/edge/d' /etc/apk/repositories \ RUN sed -i '/edge/d' /etc/apk/repositories \
&& apk update \ && apk update \
&& apk add --no-cache php7 php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \ && apk add --no-cache php81 php81-common php81-iconv php81-json php81-gd php81-curl \
php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \ php81-xml php81-mysqli php81-imap php81-cgi fcgi php81-pdo php81-pdo_mysql \
php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7-fpm \ php81-soap php81-posix php81-gettext php81-ldap php81-ctype php81-dom php81-fpm \
php7-mbstring php7-mysqlnd php7-bcmath php7-session php7-openssl php7-opcache composer \ php81-mbstring php81-mysqlnd php81-bcmath php81-session php81-openssl php81-opcache \
composer \
&& sed -i -e '/^;* *max_execution_time *=/cmax_execution_time = 300' \ && sed -i -e '/^;* *max_execution_time *=/cmax_execution_time = 300' \
-e '/^;* *memory_limit *=/cmemory_limit = 1024M' \ -e '/^;* *memory_limit *=/cmemory_limit = 1024M' \
-e '/^;* *post_max_size *=/cpost_max_size = 1024M' \ -e '/^;* *post_max_size *=/cpost_max_size = 1024M' \
@ -17,10 +18,10 @@ RUN sed -i '/edge/d' /etc/apk/repositories \
-e '/^;* *date.timezone *=/cdate.timezone = PRC' \ -e '/^;* *date.timezone *=/cdate.timezone = PRC' \
-e '/^;* *pdo_mysql.default_socket *=/cpdo_mysql.default_socket = /run/mysqld/mysqld.sock' \ -e '/^;* *pdo_mysql.default_socket *=/cpdo_mysql.default_socket = /run/mysqld/mysqld.sock' \
-e '/^;* *mysqli.default_socket *=/cmysqli.default_socket = /run/mysqld/mysqld.sock' \ -e '/^;* *mysqli.default_socket *=/cmysqli.default_socket = /run/mysqld/mysqld.sock' \
/etc/php7/php.ini \ /etc/php81/php.ini \
&& sed -i -e '/^;* *listen *=/clisten = /var/lib/php7/phpfpm.sock' \ && sed -i -e '/^;* *listen *=/clisten = /var/lib/php81/phpfpm.sock' \
-e '/^;* *listen.mode *=/clisten.mode = 0666' \ -e '/^;* *listen.mode *=/clisten.mode = 0666' \
/etc/php7/php-fpm.d/www.conf \ /etc/php81/php-fpm.d/www.conf \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*
CMD ["/opt/ccmd"] CMD ["/opt/ccmd"]

View File

@ -20,7 +20,7 @@ RUN ln -s /opt/localtime /etc/localtime \
-e '/^;* *listen.mode *=/clisten.mode = 0666' \ -e '/^;* *listen.mode *=/clisten.mode = 0666' \
/etc/php7/php-fpm.d/www.conf \ /etc/php7/php-fpm.d/www.conf \
&& mkdir /run/nginx \ && mkdir /run/nginx \
&& chown nginx.nginx /run/nginx \ && chown nginx:nginx /run/nginx \
&& rm -rf /var/cache/apk/* /etc/nginx/conf.d/* && rm -rf /var/cache/apk/* /etc/nginx/conf.d/*
CMD ["/opt/ccmd"] CMD ["/opt/ccmd"]

View File

@ -39,8 +39,8 @@ function Quit {
} }
function ChangeOwner { function ChangeOwner {
Print Change file owner ... Print Changing file owner ...
chown nginx.root /var/log/nginx/ chown nginx:root /var/log/nginx/
} }
function SideCar { function SideCar {
@ -59,18 +59,19 @@ function SideCar {
&& [ "$md5" != "$last_md5" ] \ && [ "$md5" != "$last_md5" ] \
&& last_md5=$md5 \ && last_md5=$md5 \
&& nginx -tq \ && nginx -tq \
&& Print Reload nginx conf ... \ && Print Reloading nginx conf ... \
&& nginx -s reload && nginx -s reload
done done
} }
function StartProc { function StartProc {
Print Start nginx ... Print Starting nginx ...
nginx -g "$GLOBAL_DIRECTIVES" & nginx -g "$GLOBAL_DIRECTIVES" &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Start nginx sidecar ... Print Starting nginx sidecar ...
SideCar & SideCar &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Nginx started.
} }
function Main { function Main {

View File

@ -8,10 +8,13 @@ RUN apk update \
-e '1a\\n# Added by Dockerfile' \ -e '1a\\n# Added by Dockerfile' \
-e '1adaemon off;' \ -e '1adaemon off;' \
-e '1apid /run/nginx/nginx.pid;' \ -e '1apid /run/nginx/nginx.pid;' \
-e '/^user /,/^worker_processes /d' \ -e '1aworker_rlimit_nofile 65535;' \
-e '/^#include /s/^#//' \ -e '/^user /s/^/#/' \
-e '/^worker_processes /s/^/#/' \
-e '/worker_connections/s/[0-9]\+/10240/' \
/etc/nginx/nginx.conf \ /etc/nginx/nginx.conf \
&& rm -rf /var/cache/apk/* /etc/nginx/http.d/* \ && chown nginx:nginx /run/nginx \
&& chown nginx.nginx /run/nginx && chmod 0755 /var/lib/nginx \
&& rm -rf /var/cache/apk/* /etc/nginx/http.d/*
CMD ["/opt/ccmd"] CMD ["/opt/ccmd"]

View File

@ -51,7 +51,7 @@ function SideCar {
-regex ".*\.yml\|.*\.tmpl" | xargs -I ^ md5sum ^ | md5sum) -regex ".*\.yml\|.*\.tmpl" | xargs -I ^ md5sum ^ | md5sum)
[ "$md5" != "$last_md5" ] \ [ "$md5" != "$last_md5" ] \
&& last_md5=$md5 \ && last_md5=$md5 \
&& Print Reload conf ... \ && Print Reloading conf ... \
&& pkill -HUP -f prometheus \ && pkill -HUP -f prometheus \
&& pkill -HUP -f alertmanager && pkill -HUP -f alertmanager
done done
@ -193,7 +193,7 @@ ruler:
} }
function StartProc { function StartProc {
Print Start alertmanager ... Print Starting alertmanager ...
alertmanager \ alertmanager \
--config.file=$CONF_DIR/alertmanager.yml \ --config.file=$CONF_DIR/alertmanager.yml \
--storage.path=$DATA_DIR/alertmanager \ --storage.path=$DATA_DIR/alertmanager \
@ -202,7 +202,7 @@ function StartProc {
PIDS="$PIDS $!" PIDS="$PIDS $!"
sleep 2 sleep 2
Print Start prometheus ... Print Starting prometheus ...
prometheus \ prometheus \
--config.file=$CONF_DIR/prometheus.yml \ --config.file=$CONF_DIR/prometheus.yml \
--web.external-url=prometheus \ --web.external-url=prometheus \
@ -213,7 +213,7 @@ function StartProc {
PIDS="$PIDS $!" PIDS="$PIDS $!"
sleep 2 sleep 2
Print Start grafana-server ... Print Starting grafana-server ...
grafana-server \ grafana-server \
-homepath /usr/share/grafana \ -homepath /usr/share/grafana \
-config $CONF_DIR/grafana.ini \ -config $CONF_DIR/grafana.ini \
@ -221,16 +221,18 @@ function StartProc {
PIDS="$PIDS $!" PIDS="$PIDS $!"
sleep 2 sleep 2
Print Start loki ... Print Starting loki ...
loki \ loki \
--config.file=$CONF_DIR/loki.yml \ --config.file=$CONF_DIR/loki.yml \
${LOKI_OPTS:-} &>> $LOG_DIR/loki.out & ${LOKI_OPTS:-} &>> $LOG_DIR/loki.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
sleep 2 sleep 2
Print Start sidecar ... Print Starting sidecar ...
SideCar & SideCar &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print All components started.
} }
function Main { function Main {

View File

@ -52,8 +52,8 @@ function Quit {
function ModifyConf { function ModifyConf {
local kv= local kv=
local clusterEnabled= local clusterEnabled=
[ -e /etc/redis.conf ] && Print /etc/redis.conf already exists && return 0 [ -e /etc/redis.conf ] && Print /etc/redis.conf already exists. && return 0
Print Modify conf ... Print Modifying conf ...
echo "bind 0.0.0.0 echo "bind 0.0.0.0
protected-mode no protected-mode no
maxmemory 6442450944 maxmemory 6442450944
@ -69,7 +69,7 @@ maxmemory-policy volatile-random
} }
function DeployCluster { function DeployCluster {
Print Deploy redis cluster ... Print Deploying redis cluster ...
local i= local i=
local node= local node=
local nodesId= local nodesId=
@ -91,11 +91,11 @@ function DeployCluster {
Print $node not enable cluster mode! && exit 100 Print $node not enable cluster mode! && exit 100
done done
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[@]} $redisCliCmd --cluster-yes --cluster create ${MASTER_NODES[@]}
nodesId="$($redisCliCmd -s $SOCK_FILE cluster nodes | cut -d@ -f1)" nodesId="$($redisCliCmd -s $SOCK_FILE cluster nodes | cut -d@ -f1)"
for i in ${!SLAVE_NODES[@]}; do 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]} \ $redisCliCmd --cluster-yes --cluster add-node ${SLAVE_NODES[$i]} \
${MASTER_NODES[0]} --cluster-slave \ ${MASTER_NODES[0]} --cluster-slave \
--cluster-master-id $(echo "$nodesId" \ --cluster-master-id $(echo "$nodesId" \
@ -112,7 +112,7 @@ function Init {
} }
function StartProc { function StartProc {
Print Start Redis ... Print Starting Redis ...
redis-server /etc/redis.conf \ redis-server /etc/redis.conf \
--daemonize no \ --daemonize no \
--dir $DATA_DIR \ --dir $DATA_DIR \

View File

@ -3,8 +3,9 @@ FROM harbor.colben.cn/general/alpine$ARCH
MAINTAINER Colben colbenlee@gmail.com MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/ ADD --chown=root:root /ADD/ /opt/
RUN apk update \ 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 \ && 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"] CMD ["/opt/ccmd"]

View File

@ -33,7 +33,7 @@ function Quit {
} }
function StartProc { function StartProc {
Print Start rsync ... Print Starting rsync ...
rm -f /var/run/rsyncd.pid rm -f /var/run/rsyncd.pid
rsync --daemon \ rsync --daemon \
--no-detach \ --no-detach \
@ -42,6 +42,7 @@ function StartProc {
--dparam=pidfile=/var/run/rsyncd.pid \ --dparam=pidfile=/var/run/rsyncd.pid \
&>> $LOG_DIR/rsyncd.out & &>> $LOG_DIR/rsyncd.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Rsync started.
} }
function Main { function Main {

View File

@ -34,7 +34,7 @@ function Quit {
} }
function StartProc { function StartProc {
Print Start svn ${EXTRA_ARGS:-} ... Print Starting svn ${EXTRA_ARGS:-} ...
svnserve \ svnserve \
${EXTRA_ARGS:-} \ ${EXTRA_ARGS:-} \
-d --foreground \ -d --foreground \
@ -44,6 +44,7 @@ function StartProc {
--log-file $LOG_DIR/svn.log \ --log-file $LOG_DIR/svn.log \
&>> $LOG_DIR/svn.out & &>> $LOG_DIR/svn.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Svn started.
} }
function Main { function Main {

View File

@ -36,16 +36,17 @@ function Quit {
function RestoreConf { function RestoreConf {
if [ -z "$(ls conf/)" ]; then if [ -z "$(ls conf/)" ]; then
Print Restore default config files and quit ... Print Restoring default config files and quit ...
tar zxf conf.tgz tar zxf conf.tgz
exit exit
fi fi
} }
function StartProc { function StartProc {
Print Start tomcat ... Print Starting tomcat ...
./bin/catalina.sh run &>> $CATALINA_OUT & ./bin/catalina.sh run &>> $CATALINA_OUT &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Tomcat started.
} }
function Main { function Main {

View File

@ -34,22 +34,23 @@ function Quit {
function ModifyConf { function ModifyConf {
sed -i 's/^M//g' $JAR.properties sed -i 's/^M//g' $JAR.properties
local kv= local kv=
Print Modify $JAR.properties ... Print Modifying $JAR.properties ...
while read kv; do while read kv; do
[ -z "$kv" ] && return 0 [ -z "$kv" ] && return 0
Print Modify property: ${kv%%=*} ... Print Modifying property: ${kv%%=*} ...
sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
} }
function StartProc { function StartProc {
Print Start $JAR ... Print Starting $JAR ...
java $JAVA_OPTS \ java $JAVA_OPTS \
-jar $JAR.jar \ -jar $JAR.jar \
--spring.config.location=$JAR.properties \ --spring.config.location=$JAR.properties \
>/dev/null \ >/dev/null \
2>>logs/$JAR.out & 2>>logs/$JAR.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print $JAR started.
} }
function Main { function Main {

View File

@ -12,6 +12,8 @@
# - /var/log/nginx # # - /var/log/nginx #
# - /var/log/php7 # # - /var/log/php7 #
# - /var/log/zabbix # # - /var/log/zabbix #
# ENV #
# - GLOBAL_DIERECTIVES #
################################################## ##################################################
set -euo pipefail set -euo pipefail
@ -26,6 +28,7 @@ BINLOG_DIR='/var/lib/mysql-bin'
INIT_FLAG=${INIT_FLAG:-} INIT_FLAG=${INIT_FLAG:-}
SOCK_FILE='/run/mysqld/mysqld.sock' SOCK_FILE='/run/mysqld/mysqld.sock'
PID_FILE='/run/mysqld/mysqld.pid' PID_FILE='/run/mysqld/mysqld.pid'
GLOBAL_DIRECTIVES="${GLOBAL_DIRECTIVES:-user nginx;worker_processes auto;}"
function Print { function Print {
local file=/dev/null local file=/dev/null
@ -49,14 +52,14 @@ function Quit {
} }
function RestoreConf { function RestoreConf {
! ls /etc/nginx/conf.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \ ! ls /etc/nginx/http.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \
&& Print Restore /etc/nginx/conf.d/zabbix.conf ... \ && Print Restoring /etc/nginx/http.d/zabbix.conf ... \
&& cp /usr/share/zabbix/nginx.conf /etc/nginx/conf.d/zabbix.conf && cp /usr/share/zabbix/nginx.conf /etc/nginx/http.d/zabbix.conf
[ ! -e /etc/zabbix/zabbix_proxy.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 && cp /usr/share/zabbix/zabbix_proxy.conf /etc/zabbix/zabbix_proxy.conf
[ ! -e /etc/zabbix/zabbix_server.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 && cp /usr/share/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf
return 0 return 0
} }
@ -77,23 +80,23 @@ function SideCar {
&& [ "$md5" != "$last_md5" ] \ && [ "$md5" != "$last_md5" ] \
&& last_md5=$md5 \ && last_md5=$md5 \
&& nginx -tq \ && nginx -tq \
&& Print Reload nginx conf ... \ && Print Reloading nginx conf ... \
&& nginx -s reload && nginx -s reload
done done
} }
function InitDB { function InitDB {
rm -f $SOCK_FILE $PID_FILE 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 if [ ! -d "$DATA_DIR/mysql" ]; then
Print Install database ... Print Installing database ...
mysql_install_db --user=mysql > /dev/null mysql_install_db --user=mysql > /dev/null
INIT_FLAG=1 INIT_FLAG=1
fi fi
} }
function StartProc { function StartProc {
Print Start mysql ... Print Starting mysql ...
mysqld -u mysql & mysqld -u mysql &
PIDS="$PIDS $!" PIDS="$PIDS $!"
while sleep 1; do while sleep 1; do
@ -102,20 +105,24 @@ function StartProc {
done done
echo echo
if [ -n "$INIT_FLAG" ]; then 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_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 DATABASE zabbix DEFAULT CHARSET UTF8 COLLATE UTF8_BIN"
mysql -e "CREATE USER zabbix@localhost" mysql -e "CREATE USER zabbix@localhost"
mysql -e "GRANT ALL ON zabbix.* TO 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 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 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 mysql -Dzabbix < /usr/share/zabbix/database/mysql/data.sql
if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then 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 for sql_file in $sql_files; do
Print Importing $sql_file ... Print Importing $sql_file ...
mysql < $sql_file mysql < $sql_file
@ -127,21 +134,23 @@ function StartProc {
RestoreConf RestoreConf
Print Start php ... Print Starting php ...
php-fpm7 -F -y /etc/php7/php-fpm.conf & php-fpm81 -F -y /etc/php81/php-fpm.conf &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Start zabbix ... Print Starting zabbix ...
zabbix_server -f & zabbix_server -f &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Start nginx ... Print Starting nginx ...
nginx -g 'daemon off;pid /run/nginx/nginx.pid;' & nginx -g "$GLOBAL_DIRECTIVES" &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Start nginx sidecar ... Print Starting nginx sidecar ...
SideCar & SideCar &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print All components started.
} }
function Main { function Main {

View File

@ -21,7 +21,7 @@ lower-case-table-names = 1\n\
' > /etc/mysql/my.cnf \ ' > /etc/mysql/my.cnf \
&& sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \ && sed -i 's/stty/#stty/' /usr/bin/mysql_secure_installation \
&& mkdir -p /var/log/mysql /var/lib/mysql-bin /run/mysqld \ && 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 \ && chmod -R 0777 /usr/share/webapps/zabbix/conf \
&& sed -i '/^#* *AllowRoot *=/cAllowRoot=1' /etc/zabbix/zabbix_server.conf \ && sed -i '/^#* *AllowRoot *=/cAllowRoot=1' /etc/zabbix/zabbix_server.conf \
&& mv /etc/zabbix/* /usr/share/zabbix/ \ && mv /etc/zabbix/* /usr/share/zabbix/ \
@ -41,7 +41,7 @@ lower-case-table-names = 1\n\
expires -1s;\n\ expires -1s;\n\
include fastcgi_params;\n\ include fastcgi_params;\n\
try_files $uri =404;\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_index index.php;\n\
fastcgi_param PATH_INFO $fastcgi_path_info;\n\ fastcgi_param PATH_INFO $fastcgi_path_info;\n\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n\ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n\

View File

@ -41,27 +41,28 @@ function Usage {
} }
function ModifyConf { function ModifyConf {
Print Modify server.properties ... Print Modifying server.properties ...
local kv= local kv=
local conf='conf/zoo.cfg' local conf='conf/zoo.cfg'
while read kv; do while read kv; do
[ -z "$kv" ] && break [ -z "$kv" ] && break
Print Modify property: ${kv%%=*} ... Print Modifying property: ${kv%%=*} ...
sed -i "/^${kv%%=*} *=/d" $conf sed -i "/^${kv%%=*} *=/d" $conf
echo "$kv" >> $conf echo "$kv" >> $conf
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')" done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
sed -i -e '/^dataDir/d' -e '/^dataLogDir/d' $conf sed -i -e '/^dataDir/d' -e '/^dataLogDir/d' $conf
echo -e 'dataDir=/opt/zk/data\ndataLogDir=/opt/zk/dataLog' >> $conf echo -e 'dataDir=/opt/zk/data\ndataLogDir=/opt/zk/dataLog' >> $conf
if [ ! -e data/myid ]; then if [ ! -e data/myid ]; then
Print Generate myid ... Print Generating myid ...
echo $MYID > data/myid echo $MYID > data/myid
fi fi
} }
function StartProc { function StartProc {
Print Start zookeeper ... Print Starting zookeeper ...
./bin/zkServer.sh start-foreground &>> logs/zk.out & ./bin/zkServer.sh start-foreground &>> logs/zk.out &
PIDS="$PIDS $!" PIDS="$PIDS $!"
Print Zookeeper started.
} }
function Main { function Main {