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

117
elasticsearch6/ADD/ccmd Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
##################################################
# Docker #
# -- privileged #
# Mount dir #
# - /opt/es/config #
# - /opt/es/data #
# - /opt/es/logs #
# - /opt/es/offline-plugins #
# - /opt/es/plugins #
# ENV #
# - _CONF_* #
# - ES_JAVA_OPTS #
##################################################
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**
**privileted**
**/opt/es/{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 {
Print Modify $conf ...
local kv=
local conf='config/elasticsearch.yml'
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 ...
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 ...
./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/
}
function ChangeSysConf {
Print Change system conf ...
echo 262144 > /proc/sys/vm/max_map_count || Print Not specified "--privileged".
}
function StartProc {
Print Start elasticsearch ...
su - es -c "
export JAVA_HOME=$JAVA_HOME
export PATH=$PATH
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 $!"
}
function Main {
local pid=
cd /opt/es
Usage
RestoreConf
ModifyConf
InstallPlugin
ChangeOwner
ChangeSysConf
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,15 @@
# 部署单节点 es
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```

View File

@@ -0,0 +1,31 @@
version: "3.7"
services:
es:
image: harbor.colben.cn/general/elasticsearch:6
container_name: es
restart: "on-failure"
stop_grace_period: 5m
privileged: true
environment:
_CONF_network.host: 127.0.0.1
_CONF_http.port: 9200
_CONF_transport.port: 9300
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/plugins
target: /opt/es/plugins
- type: bind
source: ./es/offline-plugins
target: /opt/es/offline-plugins

View File

@@ -0,0 +1,18 @@
# 部署三节点 es 集群
- 部署集群,有三个节点,每个节点有三个 ip
- 每个节点的 127.0.1.x 和 127.0.2.x 用于 http 请求
- 每个节点的 127.0.3.x 用于节点间通信
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```

View File

@@ -0,0 +1,108 @@
version: "3.7"
services:
es1:
image: harbor.colben.cn/general/elasticsearch:6
container_name: es1
restart: "on-failure"
stop_grace_period: 5m
privileged: true
environment:
ES_JAVA_OPTS: "-Xms8g -Xmx8g"
_CONF_cluster.name: myes
_CONF_node.name: es1
_CONF_network.bind_host: '[127.0.1.1,127.0.2.1]'
_CONF_network.publish_host: 127.0.3.1
_CONF_http.port: 9200
_CONF_transport.port: 9300
_CONF_discovery.zen.ping.unicast.hosts: '[127.0.3.1,127.0.3.2,127.0.3.3]'
_CONF_discovery.zen.minimum_master_nodes: 2
_CONF_gateway.recover_after_nodes: 2
network_mode: host
volumes:
- type: bind
source: ./es1/config
target: /opt/es/config
- type: bind
source: ./es1/data
target: /opt/es/data
- type: bind
source: ./es1/logs
target: /opt/es/logs
- type: bind
source: ./es1/plugins
target: /opt/es/plugins
- type: bind
source: ./es1/offline-plugins
target: /opt/es/offline-plugins
es2:
image: harbor.colben.cn/general/elasticsearch:6
container_name: es2
restart: "on-failure"
stop_grace_period: 5m
privileged: true
environment:
ES_JAVA_OPTS: "-Xms8g -Xmx8g"
_CONF_cluster.name: myes
_CONF_node.name: es2
_CONF_network.bind_host: '[127.0.1.2,127.0.2.2]'
_CONF_network.publish_host: 127.0.3.2
_CONF_http.port: 9200
_CONF_transport.port: 9300
_CONF_discovery.zen.ping.unicast.hosts: '[127.0.3.1,127.0.3.2,127.0.3.3]'
_CONF_discovery.zen.minimum_master_nodes: 2
_CONF_gateway.recover_after_nodes: 2
network_mode: host
volumes:
- type: bind
source: ./es2/config
target: /opt/es/config
- type: bind
source: ./es2/data
target: /opt/es/data
- type: bind
source: ./es2/logs
target: /opt/es/logs
- type: bind
source: ./es2/plugins
target: /opt/es/plugins
- type: bind
source: ./es2/offline-plugins
target: /opt/es/offline-plugins
es3:
image: harbor.colben.cn/general/elasticsearch:6
container_name: es3
restart: "on-failure"
stop_grace_period: 5m
privileged: true
environment:
ES_JAVA_OPTS: "-Xms8g -Xmx8g"
_CONF_cluster.name: myes
_CONF_node.name: es3
_CONF_network.bind_host: '[127.0.1.3,127.0.2.3]'
_CONF_network.publish_host: 127.0.3.3
_CONF_http.port: 9200
_CONF_transport.port: 9300
_CONF_discovery.zen.ping.unicast.hosts: '[127.0.3.1,127.0.3.2,127.0.3.3]'
_CONF_discovery.zen.minimum_master_nodes: 2
_CONF_gateway.recover_after_nodes: 2
network_mode: host
volumes:
- type: bind
source: ./es3/config
target: /opt/es/config
- type: bind
source: ./es3/data
target: /opt/es/data
- type: bind
source: ./es3/logs
target: /opt/es/logs
- type: bind
source: ./es3/plugins
target: /opt/es/plugins
- type: bind
source: ./es3/offline-plugins
target: /opt/es/offline-plugins

View File

@@ -0,0 +1,8 @@
ARG ARCH
FROM harbor.colben.cn/general/jdk$ARCH:8
MAINTAINER Colben colbenlee@gmail.com
RUN useradd -s /bin/bash -Um -u 1011 es \
&& sed -i '23a permission java.net.SocketPermission "*:*","accept,connect,resolve";' /opt/jdk/jre/lib/security/java.policy
ADD --chown=es:es /ADD/ /opt/
CMD ["/opt/ccmd"]

26
elasticsearch6/README.md Normal file
View File

@@ -0,0 +1,26 @@
# 构建 elasticsearch6 镜像
## 导入文件
- [下载 elasticsearch-$VERSION.tar.gz](https://www.elastic.co/cn/downloads/elasticsearch)
## 定制
- 创建日志目录和插件目录
- 修改 jdk 安全策略
- 在启动参数中指定数据目录和日志目录,覆盖配置文件
- docker 参数: --privileged
## 外挂目录和文件
- /opt/es/config: es 配置目录
- /opt/es/data: es 数据目录
- /opt/es/logs: es 日志目录
- /opt/es/plugins: es 插件目录
- /opt/es/offline-plugins: es 离线插件目录,把离线插件文件(xxxx.zip)放在该目录下,重启容器后可以自动安装
## 引入环境变量
- ES_JAVA_OPTS: jdk 配置
- \_CONF\_\*: es 配置
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 部署单节点
- [Demo/ThreeNodes/](Demo/ThreeNodes/): 部署三节点集群

81
elasticsearch6/elasticsearch.sh Executable file
View File

@@ -0,0 +1,81 @@
#!/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 es $VERSION ...
cd $ROOT_DIR/ADD
rm -rf $(ls | grep -v ccmd || true)
tar zxf /release/RUNTIME/elasticsearch-$VERSION.tar.gz -C .
mv elasticsearch-$VERSION es
cd es
mkdir data offline-plugins
echo '#
#
# ---------------------------------- Custom ------------------------------------
#
' >> config/elasticsearch.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