1、编写docker-compose.yml文件
version: '3.7'
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1
container_name: my.es
restart: always
environment:
- cluster.name=my.es
- "discovery.type=single-node"
volumes:
- ./data:/usr/share/elasticsearch/data
- ./config:/usr/share/elasticsearch/config
ports:
- 9200:9200
- 9300:9300
2、创建data、config宿主机映射目录,权限777。
3、config目录下新建配置文件
- jvm.options
-Xmx4g
- elasticsearch.yml
cluster.name: my.es
network.host: 0.0.0.0
node.name: es01
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/data
- log4j2.properties
######## Server JSON ############################
appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json
appender.rolling.layout.type = ESJsonLayout
appender.rolling.layout.type_name = server
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.json.gz
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size = 256MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-*
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB
################################################
rootLogger.level = info
rootLogger.appenderRef.rolling.ref = rolling
注:log4j2.properties文件中,“值”后面跟空格,启动时报错。
4、启动
docker-compose up -d
参考资料: