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

104
kibana/ADD/ccmd Executable file
View File

@@ -0,0 +1,104 @@
#!/bin/bash
##################################################
# Mount dir #
# - /opt/kibana/config #
# - /opt/kibana/data #
# - /opt/kibana/logs #
# - /opt/kibana/offline-plugins #
# - /opt/kibana/plugins #
# ENV #
# - _CONF_* #
# - NODE_OPTIONS #
##################################################
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 node && Print killing node ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function Usage {
Print 'This container should run with
**root user**
**/opt/kibana/{config,data,logs,offline-plugins,plugins} mounted from host**
'
}
function RestoreConf {
if [ -z "$(ls config/)" ]; then
Print Restore default config files and quit ...
tar zxf config.tgz
exit
fi
}
function ModifyConf {
local kv=
local conf='config/kibana.yml'
Print Modify $conf ...
while read kv; do
[ -z "$kv" ] && break
sed -i "/^${kv%%=*}: /d" $conf
echo "${kv/=/: }" >> $conf
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
}
function InstallPlugin {
for f in $(ls -d offline-plugins/*.zip 2>/dev/null); do
Print Install 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/
}
function StartProc {
Print Start kibana ...
su - kibana -c "
export NODE_OPTIONS='${NODE_OPTIONS:-}'
/opt/kibana/bin/kibana
" &>> logs/kibana.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
cd /opt/kibana
Usage
RestoreConf
ModifyConf
InstallPlugin
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 @@
# 部署 kibana
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```
- 浏览器访问 http://127.0.0.1:5601

View File

@@ -0,0 +1,33 @@
version: "3.7"
services:
kibana:
image: harbor.colben.cn/general/kibana:7
container_name: kibana
restart: "on-failure"
stop_grace_period: 1m
environment:
_CONF_server.port: 5601
_CONF_server.host: 127.0.0.1
_CONF_server.name: kibana
_CONF_elasticsearch.hosts: '["http://127.0.1.1:9200","http://127.0.1.2:9200","http://127.0.1.3:9200"]'
_CONF_elasticsearch.username: kibana_system
_CONF_elasticsearch.password: Pass_1234
network_mode: host
volumes:
- type: bind
source: ./kibana/config
target: /opt/kibana/config
- type: bind
source: ./kibana/data
target: /opt/kibana/data
- type: bind
source: ./kibana/logs
target: /opt/kibana/logs
- type: bind
source: ./kibana/plugins
target: /opt/kibana/plugins
- type: bind
source: ./kibana/offline-plugins
target: /opt/kibana/offline-plugins

7
kibana/Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
ARG ARCH
FROM harbor.colben.cn/general/photon$ARCH
MAINTAINER Colben colbenlee@gmail.com
RUN useradd -s /bin/bash -Um -u 1011 kibana
ADD --chown=kibana:kibana /ADD/ /opt/
CMD ["/opt/ccmd"]

23
kibana/README.md Normal file
View File

@@ -0,0 +1,23 @@
# 构建 kibana 镜像
## 导入文件
- [下载 kibana-$VERSION-linux${ARCH:--x86_64}.tar.gz](https://www.elastic.co/cn/downloads/kibana)
## 定制
- 创建日志目录和插件目录
- 在启动参数中指定数据目录和日志目录,覆盖配置文件
## 外挂目录和文件
- /opt/kibana/config: kibana 配置目录
- /opt/kibana/data: kibana 数据目录
- /opt/kibana/logs: kibana 日志目录
- /opt/kibana/plugins: kibana 插件目录
- /opt/kibana/offline-plugins: kibana 离线插件目录,把离线插件文件(xxxx.zip)放在该目录下,重启容器后可以自动安装
## 引入环境变量
- NODE_OPTIONS: kibana 启动参数
- \_CONF\_\*: kibana 配置
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 启动 kibana

77
kibana/kibana.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/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="$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"; }
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 kibana $VERSION ...
cd $ROOT_DIR/ADD
rm -rf $(ls | grep -v ccmd || true)
tar zxf /release/RUNTIME/kibana-$VERSION-linux${ARCH:--x86_64}.tar.gz -C .
mv kibana-$VERSION-linux${ARCH:--x86_64} kibana
cd kibana
mkdir logs offline-plugins
echo -e '\n# Custom' >> config/kibana.yml
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