This commit is contained in:
2022-04-18 11:21:20 +08:00
commit 45a7af638f
210 changed files with 8997 additions and 0 deletions

84
logstash6/ADD/ccmd Executable file
View File

@@ -0,0 +1,84 @@
#!/bin/bash
##################################################
# Mount dir #
# - /opt/logstash/config #
# - /opt/logstash/data #
# - /opt/logstash/logs #
# - /opt/logstash/offline-plugins #
##################################################
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
PIDS=
GOT_SIGTERM=
function Print {
local file=/dev/null
[ '-f' = "$1" ] && file=$2 && shift && shift
date +"[%F %T] $*" | tee -a $file
}
function Quit {
while :; do
pkill -f java && Print killing java ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function Usage {
Print 'This container should run with
**root user**
**/opt/logstash/{config,data,logs,offline-plugins} mounted from host**
'
}
function RestoreConf {
if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ...
tar zxf config.tgz
GOT_SIGTERM=1
exit 0
fi
}
function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do
Print Install plugins from offline file: $f ...
./bin/logstash-plugin install file://$f
mv $f $f.installed
done
}
function StartProc {
Print Start logstash ...
./bin/logstash \
--path.data /opt/logstash/data \
--path.logs /opt/logstash/logs \
--path.settings /opt/logstash/config \
&>> logs/logstash.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
cd /opt/logstash
Usage
RestoreConf
InstallPlugin
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,21 @@
# 部署 logstash6
- 为域名 x1.xx.com 和 x2.xx.com 申请 ssl 证书,并在每月的 31 号晚上十一点更新一次
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```
- 创建定时任务
```
0 23 31 * * docker-compose -f /compose/docker-compose.yml up -d letsencrypt
```

View File

@@ -0,0 +1,23 @@
version: "3.7"
services:
logstash:
image: harbor.colben.cn/general/logstash:6
container_name: logstash
restart: "on-failure"
stop_grace_period: 2m
network_mode: host
volumes:
- type: bind
source: ./es/config
target: /opt/es/config
- type: bind
source: ./es/data
target: /opt/es/data
- type: bind
source: ./es/logs
target: /opt/es/logs
- type: bind
source: ./es/offline-plugins
target: /opt/es/offline-plugins

6
logstash6/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
ARG ARCH
FROM harbor.colben.cn/general/jdk$ARCH:8
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/
CMD ["/opt/ccmd"]

18
logstash6/README.md Normal file
View File

@@ -0,0 +1,18 @@
# 构建 logstash6 镜像
## 导入文件
- [logstash-$VERSION.tar.gz](https://www.elastic.co/cn/downloads/logstash)
## 定制
- 创建日志目录和插件目录
- 在启动参数中指定数据目录和日志目录,覆盖配置文件
## 外挂目录和文件
- /opt/logstash/config: logstash 配置目录
- /opt/logstash/data: logstash 数据目录
- /opt/logstash/logs: logstash 日志目录
- /opt/logstash/offline-plugins: logstash 离线插件目录,把离线插件文件(xxxx.zip)放在该目录下,重启容器后可以自动安装
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 部署 logstash6

76
logstash6/logstash.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
#=========================================
# Author : colben
#=========================================
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)"
VERSION="6.${1#6.}"
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"; }
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 logstash $VERSION ...
cd $ROOT_DIR/ADD
rm -rf $(ls | grep -v ccmd || true)
tar zxf /release/RUNTIME/logstash-$VERSION.tar.gz -C .
mv logstash-$VERSION logstash
cd logstash
mkdir logs offline-plugins
tar zcf config.tgz config
rm -rf config/*
}
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 {
Update
Build
END=1
}
# Start here
Main