Elasticsearch + Docker:实现容器化部署指南

Elasticsearch是一款强大的分布式搜索和分析引擎,广泛应用于日志分析、全文检索、实时数据分析等场景。而Docker作为一种轻量级的容器化技术,能够帮助开发者快速部署和管理应用。将Elasticsearch与Docker结合,不仅可以简化部署流程,还能提高资源利用率和系统可维护性。

1 环境准备

1.1 安装Docker

安装操作请参考:Docker入门指南:1分钟搞定安装 + 常用命令,轻松入门容器化!-CSDN博客

1.2 配置镜像地址

复制代码
vim /etc/docker/daemon.json 
# 编辑/etc/docker/daemon.json文件,添加如下内容
{
        "registry-mirrors": [
                "https://proxy.1panel.live",
                "https://docker.1panel.top",
                "https://docker.1ms.run",
                "https://docker.ketches.cn",
                "https://docker.hpcloud.cloud",
                "https://docker.1panel.live",
                "http://mirrors.ustc.edu.cn",
                "http://mirror.azure.cn",
                "https://nrbewqda.mirror.aliyuncs.com",
                "https://dmmxhzvq.mirror.aliyuncs.com"
        ]
}

# 重新加载配置并重启docker
systemctl daemon-reload
systemctl restart docker.service

# 验证镜像地址是否生效可用,能够看到Registry Mirrors:说明正常
[root@node3 ~]# docker info
Client:
 Version:    27.3.1
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 27.3.1
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c
 runc version: v1.1.14-0-g2c9f560
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 7.777GiB
 Name: node3
 ID: 11b2908d-4f1c-4d9f-9ea1-275e70e998f9
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://proxy.1panel.live/
  https://docker.1panel.top/
  https://docker.1ms.run/
  https://docker.ketches.cn/
  https://docker.hpcloud.cloud/
  https://docker.1panel.live/
  http://mirrors.ustc.edu.cn/
  http://mirror.azure.cn/
  https://nrbewqda.mirror.aliyuncs.com/
  https://dmmxhzvq.mirror.aliyuncs.com/
 Live Restore Enabled: false
 Product License: Community Engine

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@node3 ~]# 

2 Docker部署安装

2.1 拉取镜像

复制代码
# 配置镜像地无法拉取,我们直接使用如下命令从Docker Hub进行拉取
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0

[root@node3 ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0
7.10.0: Pulling from elasticsearch/elasticsearch
e320e40c33f8: Downloading [====>                                              ]  8.088MB/84.39MB
e320e40c33f8: Downloading [=======>                                           ]  12.95MB/84.39MB
e320e40c33f8: Downloading [=========>                                         ]  15.66MB/84.39MB
e320e40c33f8: Downloading [==============>                                    ]  23.77MB/84.39MB
e320e40c33f8: Downloading [======================>                            ]  37.28MB/84.39MB
e320e40c33f8: Downloading [=============================>                     ]  49.18MB/84.39MB
e320e40c33f8: Downloading [====================================>              ]  61.07MB/84.39MB
e320e40c33f8: Downloading [============================================>      ]  75.67MB/84.39MB
e320e40c33f8: Pull complete 
be0367056981: Pull complete 
67e849725737: Pull complete 
2689ab201ca3: Extracting [=====================>                             ]  148.7MB/345.7MB
2689ab201ca3: Pull complete 
054ab54cebfb: Pull complete 
4e6ca8ea18d1: Pull complete 
033f0d2daef0: Pull complete 
3e873ca10c18: Pull complete 
19c868cd4818: Pull complete 
Digest: sha256:3ad224719013a016ab4931d1891fcf873fdf6b8c38d0970e30fc1c8b0c07f436
Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:7.10.0
docker.elastic.co/elasticsearch/elasticsearch:7.10.0
[root@node3 ~]# 

2.2 查看镜像

复制代码
[root@node3 ~]# docker images |grep elasticsearch
docker.elastic.co/elasticsearch/elasticsearch   7.10.0    37190fe5beea   4 years ago     774MB
[root@node3 ~]# 

2.3 启动容器

复制代码
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.0

[root@node3 ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.0
075ec21030f78a17e28ce7901f7b89f836679a75f104ab6692ed04c5afba61db
[root@node3 ~]# docker ps |grep elasticsearch
075ec21030f7   docker.elastic.co/elasticsearch/elasticsearch:7.10.0   "/tini -- /usr/local..."   34 seconds ago   Up 31 seconds   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch
[root@node3 ~]# 

2.4 验证

复制代码
# curl访问
[root@node3 ~]# curl http://192.168.10.32:9200
{
  "name" : "075ec21030f7",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "kC0qvmg6RFu29F5gY-OWIg",
  "version" : {
    "number" : "7.10.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "51e9d6f22758d0374a0f3f5c6e8f3a7997850f96",
    "build_date" : "2020-11-09T21:30:33.964949Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root@node3 ~]# 

浏览器访问:http://192.168.10.32:9200/

3 总结

通过以上步骤,我们就完成了使用Docker快速部署Elasticsearch单节点操作。使用容器化部署不仅简化了环境配置,还提高了系统的可维护性和扩展性

相关推荐
阿俊仔(摸鱼版)38 分钟前
Ubuntu上安装Docker
linux·ubuntu·docker
惜棠1 小时前
ragflow安装es报错怎么办
大数据·elasticsearch·搜索引擎
帽儿山的枪手3 小时前
程序员必掌握docker六种网络模式
网络协议·docker·容器
青花锁4 小时前
Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow
linux·ubuntu·docker·deepseek
郭逍遥6 小时前
GZCTF平台搭建及题目上传
笔记·学习·ubuntu·docker·容器
小参宿6 小时前
告别流媒体会员!如何用Docker搭建可远程控制的家庭音乐服务器
服务器·docker·容器
{⌐■_■}6 小时前
【PostgreSQL】pg各版本选用取舍逻辑与docker安装postgres:15
数据库·docker·postgresql
Elastic 中国社区官方博客7 小时前
Elasticsearch:构建 AI 驱动的搜索体验
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
今天又在摸鱼8 小时前
docker入门
java·spring cloud·docker
wangchen01129 小时前
【docker】安装SQLServer
docker·容器·sqlserver·azuredatastudio