@
目录写在前面
mysql
version: '3'
services:
mysql:
image: mysql:8.0.18
restart: always
container_name: mysql
command:
--default_authentication_plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
ports:
- "3306:3306"
volumes:
- /etc/localtime:/etc/localtime:ro
- $PWD/var/lib/mysql:/var/lib/mysql
- $PWD/mysqlBackup:/data/mysqlBackup
environment:
MYSQL_ROOT_PASSWORD: <root-pass> # mysql root 账户的密码
MYSQL_DATABASE: <database-name> # 新建 mysql 数据库名称
MYSQL_USER: <user> # 新建 mysql 用户
MYSQL_PASSWORD: <pass> # 新建 mysql 密码
redis
version: '3'
services:
redis:
image: redis # 镜像名称以及版本号
restart: always # 失败后总是重启
container_name: redis-6379 # 自定义容器名
# 文件夹以及文件映射
volumes:
- $PWD/data:/data
- $PWD/logs:/logs
# 自定义 redis configuration file
# - $PWD/redis.conf:/usr/local/etc/redis/redis.conf
#command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
command: redis-server --requirepass <pass> # redis 密码
# 端口号
ports:
- "6379:6379"
rabbit mq
version: '3'
services:
rabbit-mq:
hostname: rabbitmq
# 镜像名称以及版本号
image: rabbitmq:3-management
# 失败后总是重启
restart: always
# 自定义容器名
container_name: rabbitmq
# 文件夹以及文件映射
volumes:
- $PWD/etc:/etc/rabbitmq
# - $PWD/lib:/var/lib/rabbitmq
- $PWD/log:/var/log/rabbitmq
ports:
# 端口号
- "5672:5672"
- "15672:15672"
environment:
RABBITMQ_DEFAULT_USER: <user> # rabbit mq user
RABBITMQ_DEFAULT_PASS: <pass> # rabbit mq password
mongo
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: <user> # mongo root 用户名
MONGO_INITDB_ROOT_PASSWORD: <pass> # mongo root 密码
MONGO_INITDB_DATABASE: <database> # mongo database
ports:
- "27017:27017"
elasticsearch
单节点
version: '3'
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
container_name: es
environment:
- "discovery.type=single-node"
#- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "ELASTIC_PASSWORD=elastic"
#volumes:
# - ./plugins:/usr/share/elasticsearch/plugins #插件文件挂载
# - ./data:/usr/share/elasticsearch/data #数据文件挂载
# - ./log:/usr/share/elasticsearch/logs
ports:
- 9200:9200
多节点
- .ven
# Password for the 'elastic' user (at least 6 characters)
ELASTIC_PASSWORD=elastic
# Password for the 'kibana_system' user (at least 6 characters)
KIBANA_PASSWORD=elastic
# Version of Elastic products
STACK_VERSION=8.13.2
# Set the cluster name
CLUSTER_NAME=docker-cluster
# Set to 'basic' or 'trial' to automatically start the 30-day trial
LICENSE=basic
#LICENSE=trial
# Port to expose Elasticsearch HTTP API to the host
ES_PORT=9200
#ES_PORT=127.0.0.1:9200
# Port to expose Kibana to the host
KIBANA_PORT=5601
#KIBANA_PORT=80
# Project namespace (defaults to the current folder name if not set)
#COMPOSE_PROJECT_NAME=myproject
# Increase or decrease based on the available host memory (in bytes)
MEM_LIMIT=1073741824
- mem limit
设置为至少vm.max_map_count262144编辑
内核设置必须设置为至少用于生产用途。vm.max_map_count262144
[Linux]
1. 若要在实时系统上应用该设置,请运行:
sysctl -w vm.max_map_count=262144
2. 要永久更改设置的值,请更新 中的值。
vm.max_map_count/etc/sysctl.conf
vm.max_map_count=262144
[macOS with Docker]
1. 在命令行中,运行:
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
2. 按回车键并使用配置:sysctlvm.max_map_count
sysctl -w vm.max_map_count=262144
[docker desktop]
1. sudo sysctl -w vm.max_map_count=262144
带有 Docker 桌面 WSL 2 后端的 Windows编辑
该设置必须在“docker-desktop”WSL 实例中设置,然后 Elasticsearch 容器将正确启动。有几种方法可以做到这一点,这取决于 在你的 Windows 版本和 WSL 版本上。vm.max_map_count
1.1 如果你使用的是版本 22H2 之前的 Windows 10,或者如果你使用的是 Windows 10 版本 22H2,请使用 WSL 的内置版本,每次重新启动 Docker 时都必须手动设置它,然后才能启动 您的 Elasticsearch 容器,或者(如果您不希望在每次重新启动时都这样做)您必须全局设置 每个 WSL2 实例都已更改。这是因为这些版本的 WSL 不要正确处理 /etc/sysctl.conf 文件。vm.max_map_count
若要在每次重新启动时手动设置它,必须在命令提示符下运行以下命令 或每次重启 Docker 时的 PowerShell 窗口:
wsl -d docker-desktop -u root
sysctl -w vm.max_map_count=262144
1.2 如果你使用的是这些版本的 WSL,并且你不希望每次都运行这些命令 重新启动 Docker 时,可以使用此设置全局更改每个 WSL 分配 通过修改 %USERPROFILE%\.wslconfig,如下所示:
[wsl2]
1. kernelCommandLine = "sysctl.vm.max_map_count=262144"
这将导致所有 WSL2 VM 在启动时分配该设置。
2. 如果你使用的是 Windows 11 或 Windows 10 版本 22H2 并已安装 Microsoft Store WSL 版本,可以在“docker-desktop”WSL 中修改 /etc/sysctl.conf 分发,也许使用这样的命令:
wsl -d docker-desktop -u root
vi /etc/sysctl.conf
并附上一行内容如下:
vm.max_map_count = 262144
- docker-compose
version: "2.2"
services:
setup:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- ./certs:/usr/share/elasticsearch/config/certs
user: "0"
command: >
bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1;
fi;
if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs;
fi;
if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs";
echo -ne \
"instances:\n"\
" - name: es01\n"\
" dns:\n"\
" - es01\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
" - name: es02\n"\
" dns:\n"\
" - es02\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
" - name: es03\n"\
" dns:\n"\
" - es03\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
> 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;
unzip config/certs/certs.zip -d config/certs;
fi;
echo "Setting file permissions"
chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;;
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;
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;
echo "All done!";
'
healthcheck:
test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"]
interval: 1s
timeout: 5s
retries: 120
es01:
depends_on:
setup:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- ./certs:/usr/share/elasticsearch/config/certs
- ./esdata01:/usr/share/elasticsearch/data
ports:
- ${ES_PORT}:9200
environment:
- node.name=es01
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es02,es03
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es01/es01.key
- xpack.security.http.ssl.certificate=certs/es01/es01.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es01/es01.key
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
es02:
depends_on:
- es01
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- ./certs:/usr/share/elasticsearch/config/certs
- ./esdata02:/usr/share/elasticsearch/data
environment:
- node.name=es02
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es03
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es02/es02.key
- xpack.security.http.ssl.certificate=certs/es02/es02.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es02/es02.key
- xpack.security.transport.ssl.certificate=certs/es02/es02.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
es03:
depends_on:
- es02
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- ./certs:/usr/share/elasticsearch/config/certs
- ./esdata03:/usr/share/elasticsearch/data
environment:
- node.name=es03
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es02
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es03/es03.key
- xpack.security.http.ssl.certificate=certs/es03/es03.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es03/es03.key
- xpack.security.transport.ssl.certificate=certs/es03/es03.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
kibana:
depends_on:
es01:
condition: service_healthy
es02:
condition: service_healthy
es03:
condition: service_healthy
image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
volumes:
- ./certs:/usr/share/kibana/config/certs
- ./kibanadata:/usr/share/kibana/data
ports:
- ${KIBANA_PORT}:5601
environment:
- SERVERNAME=kibana
- ELASTICSEARCH_HOSTS=https://es01:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
mem_limit: ${MEM_LIMIT}
healthcheck:
test:
[
"CMD-SHELL",
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
retries: 120