docker部署elasticsearch+kibana

linux部署
复制文件到kdata
cd kdata
解压:
tar -zxvf elasticsearch-7.9.0-linux-x86_64.tar.gz
目录重命名:
mv elasticsearch-7.9.0 elasticsearch
修改配置:
cd elasticsearch/config
vi jvm.options
修改默认配置:-Xms1g    -Xmx1g 为 -Xms512m   -Xmx512m
编辑elasticsearch.yml修改数据和日志目录
vi elasticsearch.yml

docker部署
----1
docker pull elasticsearch:7.9.0
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" elasticsearch:7.9.0
docker pull kibana:7.9.0
docker run -d --name kibana --link elasticsearch:elasticsearch -e "I18N_LOCALE=zh-CN" -p 5601:5601 kibana:7.9.0

systemctl restart docker
----2
docker network create somenetwork
docker run -d --name elasticsearch --net someonework -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms256m -Xmx512m" elasticsearch:7.9.0

----3
--配置验证
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

mkdir -p /kdata/elasticsearch/config
mkdir -p /kdata/elasticsearch/data
echo "http.host: 0.0.0.0">>/kdata/elasticsearch/config/elasticsearch.yml
注意:http.host: 0.0.0.0 冒号后有一空格。
chmod -R 777 /kdata/elasticsearch/

--启动
docker run --name elasticsearch -p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /kdata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /kdata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /kdata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.9.0

--说明
--name elasticsearch:将容器命名为 elasticsearch
-p 9200:9200:将容器的9200端口映射到宿主机9200端口
-p 9300:9300:将容器的9300端口映射到宿主机9300端口,目的是集群互相通信
-e "discovery.type=single-node":单例模式
-e ES_JAVA_OPTS="-Xms64m -Xmx128m":配置内存大小
-v /kdata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:将配置文件挂载到宿主kdata机
-v /kdata/elasticsearch/data:/usr/share/elasticsearch/data:将数据文件夹挂载到宿主机
-v /kdata/elasticsearch/plugins:/usr/share/elasticsearch/plugins:将插件目录挂载到宿主机(需重启)
-d elasticsearch:7.9.0:后台运行容器,并返回容器ID

--重启后自动启动
docker update elasticsearch --restart=always