一、docker部署ElasticSearch
1、创建网桥
docker network create xybnet
2、下载镜像
docker pull elasticsearch:8.2.0
3、先运行容器
docker run -d \
--name es \
--net xybnet \
-p 9200:9200 \
-p 9300:9300 \
-p 5601:5601 \
-e "discovery.type=single-node" \
elasticsearch:8.2.0
4、复制容器文件到指定目录
docker cp es:/usr/share/elasticsearch/data /docker/es
docker cp es:/usr/share/elasticsearch/config /docker/es
/docker/es目录自己提前创建并且打开权限
5、销毁容器
docker stop es
docker rm es
6、挂载数据卷,限制内存
docker run -d \
--name es \
--net xybnet \
-p 9200:9200 \
-p 9300:9300 \
-e ES_JAVA_OPTS="-Xms1024m -Xmx2048m" \
-p 5601:5601 \
-e "discovery.type=single-node" \
-v /docker/es/data:/usr/share/elasticsearch/data \
-v /docker/es/config:/usr/share/elasticsearch/config \
elasticsearch:8.2.0
7、进入elasticsearch.yml配置文件,关闭SSL
文件在挂在的/docker/es/config目录下
即修改此命令xpack.security.enabled: false
以下是完整文件,已修改,可以直接复制
cluster.name: "docker-cluster"
network.host: 0.0.0.0#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 01-12-2023 06:13:23
#
# --------------------------------------------------------------------------------# Enable security features
xpack.security.enabled: falsexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:enabled: truekeystore.path: certs/http.p12# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/transport.p12truststore.path: certs/transport.p12
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
8、重启容器
docker restart es
9、访问成功
浏览器访问:
二、docker部署kibana
1、安装镜像
docker pull kibana:8.2.0
2、先创建容器
docker run -it -d \
--name kibana \
--network=container:es \
kibana:8.2.0
3、复制容器文件到指定目录
docker cp kibana:/usr/share/kibana/config /docker/kibana
4、销毁容器
docker stop kibana
docker rm kibana
5、运行容器,挂载数据卷
docker run -it -d \-e ELASTICSEARCH_URL=http://127.0.0.1:9200 \--name kibana \--network=container:es \-v /docker/kibana/config:/usr/share/kibana/config \kibana:8.2.0
6、配置elasticsearch和Kibana相连接
配置文件在挂在的/docker/kibana/config目录下
进入/docker/kibana/config目录中修改kibana.yml配置文件,修改访问的IP地址,为本地127.0.0.1访问
以下修改后的完整文件,可以直接复制
#
# ** THIS IS AN AUTO-GENERATED FILE **
## Default Kibana configuration for docker target
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://127.0.0.1:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
7、重启容器
docker restart kibana
8、访问
访问5601端口即可成功进入
参考文档:
Elasticsearch学习笔记_elasticsearch笔记-CSDN博客