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

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
应用实时监控服务-用户体验监控,每月100OCU免费额度
应用实时监控服务-应用监控,每月50GB免费额度
简介: 【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可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
4天前
|
人工智能 API 数据安全/隐私保护
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
NextChat 是一个可以在 GitHub 上一键免费部署的私人 ChatGPT 网页应用,支持 GPT3、GPT4 和 Gemini Pro 模型。该项目在 GitHub 上获得了 63.8k 的 star 数。部署简单,只需拉取 Docker 镜像并运行容器,设置 API Key 后即可使用。此外,NextChat 还提供了预设角色的面具功能,方便用户快速创建对话。
49 22
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
|
10天前
|
Java 应用服务中间件 Linux
【Docker容器化技术】docker安装与部署、常用命令、容器数据卷、应用部署实战、Dockerfile、服务编排docker-compose、私有仓库
本文主要讲解了Docker的安装与部署、常用命令、容器数据卷、应用部署实战、Dockerfile、服务编排docker-compose、私有仓库以及Docker容器虚拟化与传统虚拟机比较。
186 7
【Docker容器化技术】docker安装与部署、常用命令、容器数据卷、应用部署实战、Dockerfile、服务编排docker-compose、私有仓库
|
15天前
|
SQL 关系型数据库 数据库
国产数据实战之docker部署MyWebSQL数据库管理工具
【10月更文挑战第23天】国产数据实战之docker部署MyWebSQL数据库管理工具
53 4
国产数据实战之docker部署MyWebSQL数据库管理工具
|
5天前
|
运维 开发者 Docker
Docker Compose:简化容器化应用的部署与管理
Docker Compose:简化容器化应用的部署与管理
|
5天前
|
Docker 微服务 容器
使用Docker Compose实现微服务架构的快速部署
使用Docker Compose实现微服务架构的快速部署
15 1
|
12天前
|
存储 监控 安全
|
30天前
|
Web App开发 前端开发 测试技术
【Docker项目实战】使用docker部署tabler后台模版
【10月更文挑战第10天】使用docker部署tabler后台模版
32 1
【Docker项目实战】使用docker部署tabler后台模版
|
1月前
|
JSON JavaScript 测试技术
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
【10月更文挑战第9天】使用Docker部署PPTist在线演示文稿应用
34 1
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
|
1月前
|
消息中间件 编解码 Docker
【Docker项目实战】Docker部署RabbitMQ消息中间件
【10月更文挑战第8天】Docker部署RabbitMQ消息中间件
81 1
【Docker项目实战】Docker部署RabbitMQ消息中间件
|
1月前
|
存储 前端开发 测试技术
【Docker项目实战】使用Docker部署Calcium网页计算器
【10月更文挑战第7天】使用Docker部署Calcium网页计算器
29 1
【Docker项目实战】使用Docker部署Calcium网页计算器