Docker 安装 ElasticSearch 和 Kibana

8 篇文章 0 订阅
2 篇文章 0 订阅
该博客详细记录了如何在Docker环境下安装和配置Elasticsearch和Kibana,包括下载镜像、启动容器、修改配置以允许局域网访问,以及安装IK分词器的过程。博主通过Docker命令演示了从下载Elasticsearch 8.6.1到安装ik分词插件的步骤,并且同样为Kibana配置了相应的网络和设置。
摘要由CSDN通过智能技术生成

1 下载 ElasticSearch

PS C:\Users\Administrator\Desktop> docker pull elasticsearch:8.6.1
8.6.1: Pulling from library/elasticsearch
7a0437f04f83: Pull complete 
2b674c951ca3: Pull complete 
06baeb69f25f: Pull complete 
eeff01d19ce5: Pull complete 
a994306398ca: Pull complete 
2c002d76c1f6: Pull complete 
6286f2196f9b: Pull complete 
Digest: sha256:383e9fb572f3ca2fdef5ba2edb0dae2c467736af96aba2c193722aa0c08ca7ec
Status: Downloaded newer image for elasticsearch:8.6.1
docker.io/library/elasticsearch:8.6.1

2 安装 ElasticSearch

PS C:\Users\Administrator\Desktop>
PS C:\Users\Administrator\Desktop> docker images
REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
bitnami/kafka          latest    97b3440e5598   4 weeks ago     551MB
bitnami/zookeeper      latest    714253cd23db   4 weeks ago     509MB
elasticsearch          8.6.1     704e34a98f9a   7 weeks ago     1.29GB
kibana                 8.6.1     2ee129133d3e   7 weeks ago     717MB
redis                  latest    9da089657551   5 months ago    117MB
mysql                  latest    43fcfca0776d   6 months ago    449MB
dushixiang/kafka-map   <none>    b711e1fb5c60   16 months ago   295MB
PS C:\Users\Administrator\Desktop>
PS C:\Users\Administrator\Desktop> docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
cbc3915d85d4   bridge    bridge    local
4dc61add9c09   es        bridge    local
a8ba08ed5ab0   host      host      local
142a549e3e3f   kafka     bridge    local
89705b19e5d1   none      null      local
a7a251d312e1   union     bridge    local
PS C:\Users\Administrator\Desktop>
PS C:\Users\Administrator\Desktop> docker run -d --network es --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.6.1
48bc98672d66e9bf6b18bb44e846c1a4d51de9391919891f42ae1df725151c61
PS C:\Users\Administrator\Desktop>
PS C:\Users\Administrator\Desktop> docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
faeb92f06340   kibana:8.6.1               "/bin/tini -- /usr/l…"   55 minutes ago   Up 54 minutes   0.0.0.0:5601->5601/tcp                                 kibana
afacbed0a5f1   elasticsearch:8.6.1        "/bin/tini -- /usr/l…"   4 hours ago      Up 4 hours      0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp         elasticsearch
649316566ffc   b711e1fb5c60               "java -Djava.securit…"   4 weeks ago      Up 6 hours      0.0.0.0:9001->8080/tcp                                 kafka-map
a271677bc9d1   bitnami/kafka:latest       "/opt/bitnami/script…"   4 weeks ago      Up 6 hours      0.0.0.0:9092->9092/tcp                                 kafka
c3293bb650f7   bitnami/zookeeper:latest   "/opt/bitnami/script…"   4 weeks ago      Up 6 hours      2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   zookeeper
PS C:\Users\Administrator\Desktop>

3 修改 ElasticSearch 配置(局域网可访问)

3.1 修改 elasticsearch.yml 配置文件

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 14-03-2023 08:21:52
#
# --------------------------------------------------------------------------------

# Enable security features
xpack.security.enabled: false

xpack.security.enrollment.enabled: false

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: false
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
PS C:\Users\Administrator\Desktop> docker exec -it elasticsearch /bin/bash
[root@486bf4758d2d elasticsearch]# cd /usr/share/elasticsearch/config/
[root@486bf4758d2d config]# vi elasticsearch.yml
[root@486bf4758d2d config]# exit
exit

3.1 重启 ElasticSearch

PS C:\Users\Administrator\Desktop> docker restart elasticsearch 

4 修改 ElasticSearch 安装ik分词器

4.1 elasticsearch-plugin 安装ik分词器

4.1.1 在线安装

elasticsearch 的版本和 ik 分词器的版本需要保持一致,不然在重启的时候会失败

elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.6.1/elasticsearch-analysis-ik-8.6.1.zip
PS C:\Users\Administrator\Desktop> docker exec -it elasticsearch /bin/bash
[root@48bc98672d66 elasticsearch]# cd /usr/share/elasticsearch/plugins/
[root@48bc98672d66 plugins]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.6.1/elasticsearch-analysis-ik-8.6.1.zip
-> Installing https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.6.1/elasticsearch-analysis-ik-8.6.1.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.6.1/elasticsearch-analysis-ik-8.6.1.zip

4.1.2 安装包安装

4.1.2.1 下载安装包

下载合适的版本的 elasticsearch-analysis-ik

root@ubuntu:/home/hyacinth/Desktop# ll
total 4408
drwxr-xr-x  2 hyacinth hyacinth    4096 Apr 28 06:00 ./
drwxr-xr-x 15 hyacinth hyacinth    4096 Apr 28 05:16 ../
-r--------  1 root     root     4504461 Apr 28 05:58 elasticsearch-analysis-ik-8.6.1.zip
4.1.2.2 将文件复制到 Docker 容器

将文件复制到docker容器/usr/share/elasticsearch/plugins/的上一层文件夹

 docker cp elasticsearch-analysis-ik-8.6.1.zip elasticsearch:/usr/share/elasticsearch/

查看插件文件

[root@d0bbceab711e elasticsearch]# ls -l
total 4984
-rw-r--r--  1 elasticsearch root    3860 Mar 18 06:15 LICENSE.txt
-rw-r--r--  1 elasticsearch root  545323 Mar 18 06:19 NOTICE.txt
-rw-r--r--  1 elasticsearch root    7263 Mar 18 06:14 README.asciidoc
drwxr-xr-x  2 elasticsearch root    4096 Mar 18 06:23 bin
drwxrwxr-x  1 elasticsearch root    4096 Apr 28 13:08 config
drwxrwxr-x  1 elasticsearch root    4096 Apr 28 12:51 data
-r--------  1 root          root 4504461 Apr 28 12:58 elasticsearch-analysis-ik-8.6.1.zip
drwxr-xr-x  1 elasticsearch root    4096 Mar 18 06:21 jdk
drwxr-xr-x  3 elasticsearch root    4096 Mar 18 06:21 lib
drwxrwxr-x  1 elasticsearch root    4096 Apr 28 12:52 logs
drwxr-xr-x 60 elasticsearch root    4096 Mar 18 06:22 modules
drwxrwxr-x  1 elasticsearch root    4096 Apr 28 13:08 plugins
[root@d0bbceab711e elasticsearch]# 
4.1.2.3 安装插件

切换到 /usr/share/elasticsearch/plugins/ 目录

[root@d0bbceab711e plugins]# elasticsearch-plugin install file:/usr/share/elasticsearch/elasticsearch-analysis-ik-8.6.1.zip
-> Installing file:/usr/share/elasticsearch/elasticsearch-analysis-ik-8.6.1.zip
-> Downloading file:/usr/share/elasticsearch/elasticsearch-analysis-ik-8.6.1.zip
[=================================================] 100%?? 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed analysis-ik
-> Please restart Elasticsearch to activate any plugins installed
[root@d0bbceab711e plugins]# 

4.2 查看 ik分词器 插件

[root@d0bbceab711e plugins]#  elasticsearch-plugin list
analysis-ik
[root@d0bbceab711e plugins]# 

4.3 重启 ElasticSearch

PS C:\Users\Administrator\Desktop> docker restart elasticsearch 
elasticsearch

5 查看 ElasticSearch 运行

{
  "name" : "48bc98672d66",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "FADMviDcTNCcacHfsixY5g",
  "version" : {
    "number" : "8.6.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a",
    "build_date" : "2021-03-18T06:17:15.410153305Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

查看ElasticSearch

在这里插入图片描述

6 下载 Kibana

PS C:\Users\Administrator\Desktop> docker pull kibana:8.6.1
8.6.1: Pulling from library/kibana
7a0437f04f83: Already exists 
8e192d417ab5: Pull complete 
ea359635feda: Pull complete 
24196e891c4b: Pull complete 
a86dac446d83: Pull complete 
fbdf36f6254a: Pull complete 
338901cee22e: Pull complete 
b2873ac63865: Pull complete 
16f763c7e0f2: Pull complete 
f4faf58f1eb2: Pull complete 
7b27a2cc5c2e: Pull complete 
100568e56b46: Pull complete 
9fbbbdc3755f: Pull complete 
Digest: sha256:767581addfa1f3c0520774a30c5d872bbc8f833e172d93685baf89c579a1808a
Status: Downloaded newer image for kibana:8.6.1
docker.io/library/kibana:8.6.1

7 安装 Kibana

使用–link连接到elasticsearch容器

PS C:\Users\Administrator\Desktop> docker run --network es --name kibana --link=elasticsearch:test  -p 5601:5601 -d kibana:8.6.1
e379a1ac3a6c74e0b74c6967138132bbc006134bbdd0065210a9657114b0f14d

PS C:\Users\Administrator\Desktop> docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS         PORTS                                                                                  NAMES
e379a1ac3a6c   kibana:8.6.1          "/bin/tini -- /usr/l…"   4 seconds ago    Up 3 seconds   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp                                              kibana
48bc98672d66   elasticsearch:8.6.1   "/bin/tini -- /usr/l…"   15 minutes ago   Up 8 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch

PS C:\Users\Administrator\Desktop> docker container ls -a
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                                                                                  NAMES
e379a1ac3a6c   kibana:8.6.1          "/bin/tini -- /usr/l…"   12 seconds ago   Up 11 seconds   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp                                              kibana
48bc98672d66   elasticsearch:8.6.1   "/bin/tini -- /usr/l…"   15 minutes ago   Up 8 minutes    0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch

8 修改 Kibana 配置

8.1 复制 Kibana 配置文件到宿主机

root@ubuntu:/home/hyacinth/Desktop# docker cp kibana:/usr/share/kibana/config/kibana.yml .

8.2 修改 Kibana 配置文件

root@ubuntu:/home/hyacinth/Desktop# vim kibana.yml 
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
csp.strict: false

8.3 复制 Kibana 配置文件到容器

root@ubuntu:/home/hyacinth/Desktop# docker cp kibana.yml kibana:/usr/share/kibana/config/

8.4 重启 Kibana 容器

PS C:\Users\Administrator\Desktop> docker restart kibana 
kibana

9 查看 Kibana

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值