【docker】使用docker安装部署elasticsearch+Kibana(上)

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
应用实时监控服务-应用监控,每月50GB免费额度
应用实时监控服务-用户体验监控,每月100OCU免费额度
简介: 【docker】使用docker安装部署elasticsearch+Kibana

实验示例图

736ea77fed92d0e53bab016453f2e68b.png

💥注意事项

  • elasticsearch安装之后,十分消耗内存资源,需要手动配置限制内存大小。
  • elasticsearch和Kibana安装时,版本号需要一致。
  • 本实验采用的Linux系统是CentOS Linux release 7.9.2009 (Core),docker版本是20.10.14
  • elasticsearch和kibana版本都是8.2.0


一、什么是elasticsearch

Elasticsearch 是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。


二、什么是Kibana

Kibana 是一个开源分析和可视化平台,旨在与 Elasticsearch 配合使用。您可以使用 Kibana 搜索、查看存储在 Elasticsearch 索引中的数据并与之交互。您可以轻松执行高级数据分析,并在各种图表、表格和地图中可视化数据。


三、使用docker安装部署elasticsearch

创建专属网络

docker network create xybnet
docker network ls
docker inspect xybnet

执行命令结果

[root@docker ~]# docker network create xybnet
b4562c006813576d161c84f729c1a6aebf0eecb1ced954159ba02f32cd6ee656
[root@docker ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
b2ac7dc0d1c0   bridge    bridge    local
9fd62dbfb07f   host      host      local
27700772b8f7   none      null      local
b4562c006813   xybnet    bridge    local
[root@docker ~]# docker inspect xybnet
[
    {
        "Name": "xybnet",
        "Id": "b4562c006813576d161c84f729c1a6aebf0eecb1ced954159ba02f32cd6ee656",
        "Created": "2022-05-13T23:03:55.546299236+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
[root@docker ~]#


下载elasticsearch镜像

docker search elasticsearch
docker pull elasticsearch:8.2.0
docker images

执行命令结果

[root@docker ~]# docker search elasticsearch
[root@docker ~]# docker pull elasticsearch:8.2.0
8.2.0: Pulling from library/elasticsearch
e0b25ef51634: Already exists
860caabdf263: Already exists
9fbe6bc43ac5: Already exists
9d4f6737f430: Already exists
10f01841fd3e: Already exists
dae1e3bba098: Already exists
0a3767e40ef9: Already exists
7d786dfd085d: Already exists
7ce904f28ed3: Already exists
Digest: sha256:6bd33a35f529d349d8d385856b138d73241555abf2851287c055665494680b8d
Status: Downloaded newer image for elasticsearch:8.2.0
docker.io/library/elasticsearch:8.2.0
[root@docker ~]# docker images
REPOSITORY      TAG            IMAGE ID       CREATED        SIZE
redis           6-alpine3.15   6d12d0de5a46   2 weeks ago    32.4MB
elasticsearch   8.2.0          f75ee9faf718   3 weeks ago    1.21GB
tomcat          latest         fb5657adc892   4 months ago   680MB
elasticsearch   latest         5acf0e8da90b   3 years ago    486MB
[root@docker ~]# docker inspect elasticsearch:8.2.0
[
    {
        "Id": "sha256:f75ee9faf7183b931afb70d416647824c9b344e83905bbe7f70062b5eab91e43",
        "RepoTags": [
            "elasticsearch:8.2.0"
        ],
        "RepoDigests": [
******以下输出内容省略******


创建并启动Elasticsearch容器服务

# 此命令限制运行内存大小以及挂载卷
docker run -d --name xybes --net xybnet -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms1024m -Xmx2048m" -p 5601:5601 -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data elasticsearch:8.2.0
# 此命令不设置自定义网络
docker run -d --name xybes -p 9200:9200 -p 9300:9300 -p 5601:5601 -e "discovery.type=single-node" elasticsearch:8.2.0
# 本实验执行此命令
docker run -d --name xybes --net xybnet -p 9200:9200 -p 9300:9300 -p 5601:5601 -e "discovery.type=single-node" elasticsearch:8.2.0
docker ps
# 参数解释说明
# -d 后台运行 
# --name xybes            指定容器唯一的名称,方便管理
# --net xybnet            指定网络
# -p 9200:9200 -p 9300:9300     映射容器端口到宿主机上
# -e "discovery.type=single-node"   环境变量配置为单机模式
# -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data 持久化数据存储
# -e ES_JAVA_OPTS="-Xms1024m -Xmx2048m" 设置内存大小
# elasticsearch:8.2.0           镜像名称和版本号

执行命令结果

[root@docker ~]# docker run -d --name xybes --net xybnet -p 9200:9200 -p 9300:9300 -p 5601:5601 -e "discovery.type=single-node" elasticsearch:8.2.0
900c8e4dbe11c4460543859b8c887d1fbb21b33071474e079de430e087fdb92f
[root@docker ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS
                NAMES
900c8e4dbe11   elasticsearch:8.2.0   "/bin/tini -- /usr/l…"   17 seconds ago   Up 16 seconds   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp, 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   xybes
[root@docker ~]# docker inspect 900c8e4dbe11
[
    {
        "Id": "900c8e4dbe11c4460543859b8c887d1fbb21b33071474e079de430e087fdb92f",
        "Created": "2022-05-14T12:56:51.502325109Z",
        "Path": "/bin/tini",
        "Args": [
            "--",
            "/usr/local/bin/docker-entrypoint.sh",
            "eswrapper"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 7605,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-05-14T12:56:52.189429009Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
******以下输出内容省略******
# 进入xybes容器
[root@docker ~]# docker exec -it xybes /bin/bash
cluster.name: "docker-cluster"
# 查看配置目录
elasticsearch@900c8e4dbe11:~$ ls
LICENSE.txt  NOTICE.txt  README.asciidoc  bin  config  data  jdk  lib  logs  modules  plugins
# 查看设置es用户密码帮助命令
elasticsearch@900c8e4dbe11:~$ ./bin/elasticsearch-setup-passwords -h
Sets the passwords for reserved users
Commands
--------
auto - Uses randomly generated passwords
interactive - Uses passwords entered by a user
Non-option arguments:
command
Option             Description
------             -----------
-E <KeyValuePair>  Configure a setting
-h, --help         Show help
-s, --silent       Show minimal output
-v, --verbose      Show verbose output
# 以自定义的方式设置密码
elasticsearch@900c8e4dbe11:~$ ./bin/elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This       command will be removed in a future release.
******************************************************************************
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
elasticsearch@900c8e4dbe11:~$ ls
LICENSE.txt  NOTICE.txt  README.asciidoc  bin  config  data  jdk  lib  logs  modules  plugins
# 进入elasticsearch.yml配置文件,关闭SSL(即修改此命令xpack.security.enabled: false)
elasticsearch@900c8e4dbe11:~$ vi config/elasticsearch.yml
elasticsearch@900c8e4dbe11:~$ cat config/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-05-2022 12:56:54
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
# 退出容器
elasticsearch@900c8e4dbe11:~$ exit
exit
# 系统重新加载
[root@docker ~]# systemctl daemon-reload
# 重启xybes容器
[root@docker ~]# docker restart xybes
xybes
# 测试访问
[root@docker ~]# curl http://localhost:9200
curl: (56) Recv failure: Connection reset by peer
# 使用IP:9200访问成功
[root@docker ~]# curl http://192.168.200.66:9200
{
  "name" : "900c8e4dbe11",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "wDwmop88TiO1Rkf1fecHvg",
  "version" : {
    "number" : "8.2.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "b174af62e8dd9f4ac4d25875e9381ffe2b9282c5",
    "build_date" : "2022-04-20T10:35:10.180408517Z",
    "build_snapshot" : false,
    "lucene_version" : "9.1.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
[root@docker ~]#

1817605ee48e188eca4c9636ca236f0a.png

# 以SSL安全模式访问。
[root@docker ~]# docker cp xybes:/usr/share/elasticsearch/config/certs/http_ca.crt ./
# 访问成功
[root@docker ~]# curl --cacert http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
{
  "name" : "900c8e4dbe11",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "wDwmop88TiO1Rkf1fecHvg",
  "version" : {
    "number" : "8.2.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "b174af62e8dd9f4ac4d25875e9381ffe2b9282c5",
    "build_date" : "2022-04-20T10:35:10.180408517Z",
    "build_snapshot" : false,
    "lucene_version" : "9.1.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
[root@docker ~]#


四、使用docker安装部署Kibana

下载kibana镜像(注意对应版本)

docker search kibana
docker pull kibana:8.2.0
docker images

执行命令结果

[root@docker ~]# docker pull kibana:8.2.0
8.2.0:  Pulling from library/kibana
e0b25ef51634: Already exists
16168a059524: Pull complete
a7c5b97fb1b3: Pull complete
b4997d90f2a3: Pull complete
08edfcb77367: Pull complete
162b89073472: Pull complete
c27ed485e628: Pull complete
c8ec5118d07e: Pull complete
3098c58d1611: Pull complete
f0cd89b25439: Pull complete
90247f6ea1db: Pull complete
3bdda07522a2: Pull complete
36a9ec86c178: Pull complete
Digest: sha256:0ba5d3d3ddab3212eadd15bcc701c24a2baafe2f8bd7ced9d2a750cf227b8a06
Status: Downloaded newer image for kibana:8.2.0
docker.io/library/kibana:8.2.0
[root@docker ~]# docker images
REPOSITORY      TAG            IMAGE ID       CREATED        SIZE
redis           6-alpine3.15   6d12d0de5a46   2 weeks ago    32.4MB
kibana          8.2.0          58a692253df4   3 weeks ago    752MB
elasticsearch   8.2.0          f75ee9faf718   3 weeks ago    1.21GB
tomcat          latest         fb5657adc892   4 months ago   680MB
elasticsearch   7.7.0          7ec4f35ab452   2 years ago    757MB
elasticsearch   latest         5acf0e8da90b   3 years ago    486MB
[root@docker ~]#


创建并启动kibana容器

# 本实验执行此命令
docker run -it -d --name kibana --network=container:xybes kibana:8.2.0
docker run -it -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 --name kibana --network=container:xybes -v /data/kibana/config:/usr/share/kibana/config kibana:8.2.0

执行命令结果

[root@docker ~]# docker run -it -d --name kibana --network=container:xybes kibana:8.2.0
88969a52ec18c84fa7950a80f0211fc645c8de2df49b2b70ee8847e8903e026c
[root@docker ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS
                NAMES
88969a52ec18   kibana:8.2.0          "/bin/tini -- /usr/l…"   50 seconds ago   Up 49 seconds
                kibana
900c8e4dbe11   elasticsearch:8.2.0   "/bin/tini -- /usr/l…"   4 hours ago      Up 3 hours      0.0.0.0:5601->5601/tcp, :::5601->5601/tcp, 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   xybes
[root@docker ~]#
[root@docker ~]# docker inspect 88969a52ec18
[
    {
        "Id": "88969a52ec18c84fa7950a80f0211fc645c8de2df49b2b70ee8847e8903e026c",
        "Created": "2022-05-14T17:08:38.738984864Z",
        "Path": "/bin/tini",
        "Args": [
            "--",
            "/usr/local/bin/kibana-docker"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 27371,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-05-14T17:08:38.908540948Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
******以下输出内容省略******
相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
3月前
|
数据可视化 Java Windows
Elasticsearch入门-环境安装ES和Kibana以及ES-Head可视化插件和浏览器插件es-client
本文介绍了如何在Windows环境下安装Elasticsearch(ES)、Elasticsearch Head可视化插件和Kibana,以及如何配置ES的跨域问题,确保Kibana能够连接到ES集群,并提供了安装过程中可能遇到的问题及其解决方案。
Elasticsearch入门-环境安装ES和Kibana以及ES-Head可视化插件和浏览器插件es-client
|
29天前
|
存储 JSON Java
ELK 圣经:Elasticsearch、Logstash、Kibana 从入门到精通
ELK是一套强大的日志管理和分析工具,广泛应用于日志监控、故障排查、业务分析等场景。本文档将详细介绍ELK的各个组件及其配置方法,帮助读者从零开始掌握ELK的使用。
|
1月前
|
存储 监控 安全
|
2月前
|
自然语言处理 搜索推荐 关系型数据库
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
这篇文章是关于Elasticsearch全文搜索引擎的学习指南,涵盖了基本概念、命令风格、索引操作、分词器使用,以及数据的增加、修改、删除和查询等操作。
35 0
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
|
2月前
|
存储 JSON Java
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
这篇文章是关于Elasticsearch的学习指南,包括了解Elasticsearch、版本对应、安装运行Elasticsearch和Kibana、安装head插件和elasticsearch-ik分词器的步骤。
214 0
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
|
2月前
|
运维 监控 数据可视化
大数据-171 Elasticsearch ES-Head 与 Kibana 配置 使用 测试
大数据-171 Elasticsearch ES-Head 与 Kibana 配置 使用 测试
80 1
|
3月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
3月前
|
JSON 自然语言处理 数据库
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
概念、ik分词器、倒排索引、索引和文档的增删改查、RestClient对索引和文档的增删改查
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
|
4月前
|
数据可视化 Docker 容器
一文教会你如何通过Docker安装elasticsearch和kibana 【详细过程+图解】
这篇文章提供了通过Docker安装Elasticsearch和Kibana的详细过程和图解,包括下载镜像、创建和启动容器、处理可能遇到的启动失败情况(如权限不足和配置文件错误)、测试Elasticsearch和Kibana的连接,以及解决空间不足的问题。文章还特别指出了配置文件中空格的重要性以及环境变量中字母大小写的问题。
一文教会你如何通过Docker安装elasticsearch和kibana 【详细过程+图解】
|
4月前
|
Ubuntu jenkins 持续交付
Docker:docker安装部署jenkins
Docker:docker安装部署jenkins
51 0