Add elastic elasticsearch and kibana

This commit is contained in:
2024-02-01 11:02:16 +08:00
parent 08a3e63d46
commit b57394e360
5 changed files with 479 additions and 439 deletions
@@ -1,281 +1,282 @@
networks: networks:
elastic-net: elastic-net:
external: true external: true
services: services:
elastic: elastic:
container_name: kibana-${CONTAINER_NAME} container_name: kibana-${CONTAINER_NAME}
depends_on: depends_on:
es01: es01:
condition: service_healthy condition: service_healthy
es02: es02:
condition: service_healthy condition: service_healthy
es03: es03:
condition: service_healthy condition: service_healthy
deploy: deploy:
resources: resources:
limits: limits:
cpus: ${CPUS} cpus: ${CPUS}
memory: ${MEMORY_LIMIT} memory: ${MEMORY_LIMIT}
environment: environment:
- SERVERNAME=kibana - SERVERNAME=kibana
- ELASTICSEARCH_HOSTS=https://es01:9200 - ELASTICSEARCH_HOSTS=https://es01:9200
- ELASTICSEARCH_USERNAME=kibana_system - ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD} - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt - ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found' - curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'
timeout: 10s timeout: 10s
image: docker.elastic.co/kibana/kibana:8.12.0 image: docker.elastic.co/kibana/kibana:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- ${CLUSTER_NETWORK} - ${CLUSTER_NETWORK}
ports: ports:
- ${HOST_IP}:${PANEL_APP_PORT_HTTP}:5601 - ${HOST_IP}:${PANEL_APP_PORT_HTTP}:5601
restart: always restart: always
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/kibana/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/kibana/config/certs
- ${ES_ROOT_PATH}/kibana/data:/usr/share/kibana/data - ${ES_ROOT_PATH}/kibana/data:/usr/share/kibana/data
- ${ES_ROOT_PATH}/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml - ${ES_ROOT_PATH}/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
elastic-init: elastic-init:
command: | command: |
bash -c ' bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file"; echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1; exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file"; echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1; exit 1;
fi; fi;
if [ ! -f config/certs/ca.zip ]; then if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA"; echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip; bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs; unzip config/certs/ca.zip -d config/certs;
fi; fi;
if [ ! -f config/certs/certs.zip ]; then if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs"; echo "Creating certs";
echo -ne \ echo -ne \
"instances:\n"\ "instances:\n"\
" - name: es01\n"\ " - name: es01\n"\
" dns:\n"\ " dns:\n"\
" - es01\n"\ " - es01\n"\
" - localhost\n"\ " - localhost\n"\
" ip:\n"\ " ip:\n"\
" - 127.0.0.1\n"\ " - 127.0.0.1\n"\
" - name: es02\n"\ " - name: es02\n"\
" dns:\n"\ " dns:\n"\
" - es02\n"\ " - es02\n"\
" - localhost\n"\ " - localhost\n"\
" ip:\n"\ " ip:\n"\
" - 127.0.0.1\n"\ " - 127.0.0.1\n"\
" - name: es03\n"\ " - name: es03\n"\
" dns:\n"\ " dns:\n"\
" - es03\n"\ " - es03\n"\
" - localhost\n"\ " - localhost\n"\
" ip:\n"\ " ip:\n"\
" - 127.0.0.1\n"\ " - 127.0.0.1\n"\
> config/certs/instances.yml; > config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key; bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs; unzip config/certs/certs.zip -d config/certs;
fi; fi;
echo "Setting file permissions" echo "Setting file permissions"
chown -R root:root config/certs; chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;; find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;; find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability"; echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done; until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password"; echo "Setting kibana_system password";
until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done; until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
echo "All done!"; echo "All done!";
' '
container_name: elastic-init container_name: elastic-init
healthcheck: healthcheck:
interval: 1s interval: 1s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- '[ -f config/certs/es01/es01.crt ]' - '[ -f config/certs/es01/es01.crt ]'
timeout: 5s timeout: 5s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
networks: networks:
- ${CLUSTER_NETWORK} - ${CLUSTER_NETWORK}
user: "0" user: "0"
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
es01: es01:
container_name: es01 container_name: es01
depends_on: depends_on:
elastic-init: elastic-init:
condition: service_healthy condition: service_healthy
environment: environment:
- node.name=es01 - node.name=es01
- cluster.name=${CLUSTER_NAME} - cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03 - cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es02,es03 - discovery.seed_hosts=es02,es03
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD} - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true - bootstrap.memory_lock=true
- xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.key=certs/es01/es01.key - xpack.security.http.ssl.key=certs/es01/es01.key
- xpack.security.http.ssl.certificate=certs/es01/es01.crt - xpack.security.http.ssl.certificate=certs/es01/es01.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.transport.ssl.key=certs/es01/es01.key - xpack.security.transport.ssl.key=certs/es01/es01.key
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt - xpack.security.transport.ssl.certificate=certs/es01/es01.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=basic - xpack.license.self_generated.type=basic
- ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX} - ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX}
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials' - curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'
timeout: 10s timeout: 10s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- ${CLUSTER_NETWORK} - ${CLUSTER_NETWORK}
ports: ports:
- ${PANEL_APP_PORT_HTTPS}:9200 - ${PANEL_APP_PORT_HTTPS}:9200
- ${ES_COMMUNICATION_PORT}:9300 - ${ES_COMMUNICATION_PORT}:9300
restart: always restart: always
ulimits: ulimits:
memlock: memlock:
hard: -1 hard: -1
soft: -1 soft: -1
nofile: nofile:
hard: 65536 hard: 65536
soft: 65536 soft: 65536
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
- ${ES_ROOT_PATH}/es01/data:/usr/share/elasticsearch/data - ${ES_ROOT_PATH}/es01/data:/usr/share/elasticsearch/data
- ${ES_ROOT_PATH}/es01/logs:/usr/share/elasticsearch/logs - ${ES_ROOT_PATH}/es01/logs:/usr/share/elasticsearch/logs
- ${ES_ROOT_PATH}/es01/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ${ES_ROOT_PATH}/es01/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ${ES_ROOT_PATH}/es01/plugins:/usr/share/elasticsearch/plugins - ${ES_ROOT_PATH}/es01/plugins:/usr/share/elasticsearch/plugins
es02: es02:
container_name: es02 container_name: es02
depends_on: depends_on:
- es01 - es01
environment: environment:
- node.name=es02 - node.name=es02
- cluster.name=${CLUSTER_NAME} - cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03 - cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es03 - discovery.seed_hosts=es01,es03
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD} - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true - bootstrap.memory_lock=true
- xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.key=certs/es02/es02.key - xpack.security.http.ssl.key=certs/es02/es02.key
- xpack.security.http.ssl.certificate=certs/es02/es02.crt - xpack.security.http.ssl.certificate=certs/es02/es02.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.transport.ssl.key=certs/es02/es02.key - xpack.security.transport.ssl.key=certs/es02/es02.key
- xpack.security.transport.ssl.certificate=certs/es02/es02.crt - xpack.security.transport.ssl.certificate=certs/es02/es02.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=basic - xpack.license.self_generated.type=basic
- ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX} - ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX}
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials' - curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'
timeout: 10s timeout: 10s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- ${CLUSTER_NETWORK} - ${CLUSTER_NETWORK}
restart: always restart: always
ulimits: ulimits:
memlock: memlock:
hard: -1 hard: -1
soft: -1 soft: -1
nofile: nofile:
hard: 65536 hard: 65536
soft: 65536 soft: 65536
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
- ${ES_ROOT_PATH}/es02/data:/usr/share/elasticsearch/data - ${ES_ROOT_PATH}/es02/data:/usr/share/elasticsearch/data
- ${ES_ROOT_PATH}/es02/logs:/usr/share/elasticsearch/logs - ${ES_ROOT_PATH}/es02/logs:/usr/share/elasticsearch/logs
- ${ES_ROOT_PATH}/es02/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ${ES_ROOT_PATH}/es02/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ${ES_ROOT_PATH}/es02/plugins:/usr/share/elasticsearch/plugins - ${ES_ROOT_PATH}/es02/plugins:/usr/share/elasticsearch/plugins
es03: es03:
container_name: es03 container_name: es03
depends_on: depends_on:
- es02 - es02
environment: environment:
- node.name=es03 - node.name=es03
- cluster.name=${CLUSTER_NAME} - cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03 - cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es02 - discovery.seed_hosts=es01,es02
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD} - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true - bootstrap.memory_lock=true
- xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.key=certs/es03/es03.key - xpack.security.http.ssl.key=certs/es03/es03.key
- xpack.security.http.ssl.certificate=certs/es03/es03.crt - xpack.security.http.ssl.certificate=certs/es03/es03.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.transport.ssl.key=certs/es03/es03.key - xpack.security.transport.ssl.key=certs/es03/es03.key
- xpack.security.transport.ssl.certificate=certs/es03/es03.crt - xpack.security.transport.ssl.certificate=certs/es03/es03.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=basic - xpack.license.self_generated.type=basic
- ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX} - ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX}
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials' - curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'
timeout: 10s timeout: 10s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- ${CLUSTER_NETWORK} - ${CLUSTER_NETWORK}
restart: always restart: always
ulimits: ulimits:
memlock: memlock:
hard: -1 hard: -1
soft: -1 soft: -1
nofile: nofile:
hard: 65536 hard: 65536
soft: 65536 soft: 65536
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
- ${ES_ROOT_PATH}/es03/data:/usr/share/elasticsearch/data - ${ES_ROOT_PATH}/es03/data:/usr/share/elasticsearch/data
- ${ES_ROOT_PATH}/es03/logs:/usr/share/elasticsearch/logs - ${ES_ROOT_PATH}/es03/logs:/usr/share/elasticsearch/logs
- ${ES_ROOT_PATH}/es03/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ${ES_ROOT_PATH}/es03/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ${ES_ROOT_PATH}/es03/plugins:/usr/share/elasticsearch/plugins - ${ES_ROOT_PATH}/es03/plugins:/usr/share/elasticsearch/plugins
version: "2.2" version: "2.2"
# Template Ms 20240201
+15 -7
View File
@@ -5,14 +5,22 @@ if [ -f .env ]; then
# 导入 .env 文件中的变量 # 导入 .env 文件中的变量
source .env source .env
# 模板文件 MS_TEMPLATE_ENABLED 为 true 时 使用正确的模板文件 # 检查模板是否启用
MS_TEMPLATE_ENABLED=$(grep -E '^MS_TEMPLATE_ENABLED=' .env | cut -d= -f2)
# 检查MS_TEMPLATE_ENABLED是否为真
if [ "$MS_TEMPLATE_ENABLED" = "true" ]; then if [ "$MS_TEMPLATE_ENABLED" = "true" ]; then
# 复制docker-compose-template.yml为docker-compose.yml,覆盖已存在的文件 # 检查模板文件是否存在
cp -f docker-compose-template.yml docker-compose.yml if [ -e "docker-compose-template.yml" ]; then
echo "docker-compose.yml updated successfully." # 读取模板文件的内容
template_content=$(<docker-compose-template.yml)
# 清空目标文件
> docker-compose.yml
# 将模板内容写入目标文件
echo "$template_content" > docker-compose.yml
echo "docker-compose.yml updated successfully."
else
echo "Error: docker-compose-template.yml not found."
exit 1
fi
fi fi
# 替换 docker-compose.yml 中的网络变量 # 替换 docker-compose.yml 中的网络变量
+12
View File
@@ -85,3 +85,15 @@ additionalProperties:
value: "true" value: "true"
- label: False - label: False
value: "false" value: "false"
- default: "false"
edit: true
envKey: MS_TEMPLATE_ENABLED
labelEn: Use template installation (can be used if installation fails multiple times)
labelZh: 使用模板安装(多次安装失败可使用此方法)
required: true
type: select
values:
- label: True
value: "true"
- label: False
value: "false"
@@ -1,157 +1,158 @@
networks: networks:
1panel-network: 1panel-network:
external: true external: true
services: services:
elastic: elastic:
container_name: kibana-${CONTAINER_NAME} container_name: kibana-${CONTAINER_NAME}
depends_on: depends_on:
es-single-es01: es-single-es01:
condition: service_healthy condition: service_healthy
deploy: deploy:
resources: resources:
limits: limits:
cpus: ${CPUS} cpus: ${CPUS}
memory: ${MEMORY_LIMIT} memory: ${MEMORY_LIMIT}
environment: environment:
- SERVERNAME=kibana - SERVERNAME=kibana
- ELASTICSEARCH_HOSTS=https://es-single-es01:9200 - ELASTICSEARCH_HOSTS=https://es-single-es01:9200
- ELASTICSEARCH_USERNAME=kibana_system - ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD} - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt - ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found' - curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'
timeout: 10s timeout: 10s
image: docker.elastic.co/kibana/kibana:8.12.0 image: docker.elastic.co/kibana/kibana:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- 1panel-network - 1panel-network
ports: ports:
- ${HOST_IP}:${PANEL_APP_PORT_HTTP}:5601 - ${HOST_IP}:${PANEL_APP_PORT_HTTP}:5601
restart: always restart: always
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/kibana/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/kibana/config/certs
- ${ES_ROOT_PATH}/kibana/data:/usr/share/kibana/data - ${ES_ROOT_PATH}/kibana/data:/usr/share/kibana/data
- ${ES_ROOT_PATH}/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml - ${ES_ROOT_PATH}/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
es-single-es01: es-single-es01:
container_name: es-single-es01 container_name: es-single-es01
depends_on: depends_on:
es-single-init: es-single-init:
condition: service_healthy condition: service_healthy
environment: environment:
- discovery.type=single-node - discovery.type=single-node
- node.name=es-single-es01 - node.name=es-single-es01
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD} - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true - bootstrap.memory_lock=true
- xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.http.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.http.ssl.key=certs/es-single-es01/es-single-es01.key - xpack.security.http.ssl.key=certs/es-single-es01/es-single-es01.key
- xpack.security.http.ssl.certificate=certs/es-single-es01/es-single-es01.crt - xpack.security.http.ssl.certificate=certs/es-single-es01/es-single-es01.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED} - xpack.security.transport.ssl.enabled=${ES_XPACK_SECURITY_ENABLED}
- xpack.security.transport.ssl.key=certs/es-single-es01/es-single-es01.key - xpack.security.transport.ssl.key=certs/es-single-es01/es-single-es01.key
- xpack.security.transport.ssl.certificate=certs/es-single-es01/es-single-es01.crt - xpack.security.transport.ssl.certificate=certs/es-single-es01/es-single-es01.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=basic - xpack.license.self_generated.type=basic
- ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX} - ES_JAVA_OPTS=-Xms${ES_JAVA_OPTS_XMS} -Xmx${ES_JAVA_OPTS_XMX}
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials' - curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'
timeout: 10s timeout: 10s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
mem_limit: ${MEM_LIMIT} mem_limit: ${MEM_LIMIT}
networks: networks:
- 1panel-network - 1panel-network
ports: ports:
- ${PANEL_APP_PORT_HTTPS}:9200 - ${PANEL_APP_PORT_HTTPS}:9200
- ${ES_COMMUNICATION_PORT}:9300 - ${ES_COMMUNICATION_PORT}:9300
restart: always restart: always
ulimits: ulimits:
memlock: memlock:
hard: -1 hard: -1
soft: -1 soft: -1
nofile: nofile:
hard: 65536 hard: 65536
soft: 65536 soft: 65536
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
- ${ES_ROOT_PATH}/es01/data:/usr/share/elasticsearch/data - ${ES_ROOT_PATH}/es01/data:/usr/share/elasticsearch/data
- ${ES_ROOT_PATH}/es01/logs:/usr/share/elasticsearch/logs - ${ES_ROOT_PATH}/es01/logs:/usr/share/elasticsearch/logs
- ${ES_ROOT_PATH}/es01/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ${ES_ROOT_PATH}/es01/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ${ES_ROOT_PATH}/es01/plugins:/usr/share/elasticsearch/plugins - ${ES_ROOT_PATH}/es01/plugins:/usr/share/elasticsearch/plugins
es-single-init: es-single-init:
command: | command: |
bash -c ' bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file"; echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1; exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file"; echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1; exit 1;
fi; fi;
if [ ! -f config/certs/ca.zip ]; then if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA"; echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip; bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs; unzip config/certs/ca.zip -d config/certs;
fi; fi;
if [ ! -f config/certs/certs.zip ]; then if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs"; echo "Creating certs";
echo -ne \ echo -ne \
"instances:\n"\ "instances:\n"\
" - name: es-single-es01\n"\ " - name: es-single-es01\n"\
" dns:\n"\ " dns:\n"\
" - es-single-es01\n"\ " - es-single-es01\n"\
" - localhost\n"\ " - localhost\n"\
" ip:\n"\ " ip:\n"\
" - 127.0.0.1\n"\ " - 127.0.0.1\n"\
> config/certs/instances.yml; > config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key; bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs; unzip config/certs/certs.zip -d config/certs;
fi; fi;
echo "Setting file permissions" echo "Setting file permissions"
chown -R root:root config/certs; chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;; find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;; find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability"; echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://es-single-es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done; until curl -s --cacert config/certs/ca/ca.crt https://es-single-es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password"; echo "Setting kibana_system password";
until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es-single-es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done; until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es-single-es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
echo "All done!"; echo "All done!";
' '
container_name: elastic-init container_name: elastic-init
healthcheck: healthcheck:
interval: 1s interval: 1s
retries: 120 retries: 120
test: test:
- CMD-SHELL - CMD-SHELL
- '[ -f config/certs/es-single-es01/es-single-es01.crt ]' - '[ -f config/certs/es-single-es01/es-single-es01.crt ]'
timeout: 5s timeout: 5s
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
logging: logging:
driver: json-file driver: json-file
options: options:
max-file: "3" max-file: "3"
max-size: 10m max-size: 10m
networks: networks:
- 1panel-network - 1panel-network
user: "0" user: "0"
volumes: volumes:
- ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs - ${ES_ROOT_PATH}/certs:/usr/share/elasticsearch/config/certs
version: "2.2" version: "2.2"
# Template Ms 20240201
@@ -5,6 +5,24 @@ if [ -f .env ]; then
# 导入 .env 文件中的变量 # 导入 .env 文件中的变量
source .env source .env
# 检查模板是否启用
if [ "$MS_TEMPLATE_ENABLED" = "true" ]; then
# 检查模板文件是否存在
if [ -e "docker-compose-template.yml" ]; then
# 读取模板文件的内容
template_content=$(<docker-compose-template.yml)
# 清空目标文件
> docker-compose.yml
# 将模板内容写入目标文件
echo "$template_content" > docker-compose.yml
echo "docker-compose.yml updated successfully."
else
echo "Error: docker-compose-template.yml not found."
exit 1
fi
fi
# 创建目录 # 创建目录
mkdir -p "$ES_ROOT_PATH" mkdir -p "$ES_ROOT_PATH"