Windows 环境使用 Docker 安装 ES & Kibana 8.12.2 及analysis-ik插件

在我们本地开发或测试的过程中,往往需要搭建自己的开发环境,最方便的方式就是使用docker来完成。快捷,方便,随用随启。

本篇使用docker搭建 ElasticSearch8.12.2 的单机过程,仅作为测试练习使用,(elasticsearch 8.12.2+kibana 8.12.2 )

注意:kibana与Elasticsearch的版本必须一致,不然会匹配不成功

1. 前提条件

安装Docker Desktop for Windows:请确保您的Windows系统已安装Docker Desktop。可以从Docker官网下载并安装。

2. 部署ES

创建网络
shell 复制代码
docker network create elasticsearch
加载镜像

首先,打开命令提示符或PowerShell,运行以下命令以拉取最新版本的Elasticsearch和Kibana镜像:

shell 复制代码
docker pull elasticsearch:8.12.2
容器启动

接下来,运行以下命令以启动Elasticsearch容器:

shell 复制代码
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.12.2

这个命令将:

  • -d:在后台运行容器。
  • --name elasticsearch:为容器命名。
  • -p 9200:9200-p 9300:9300:将容器的端口映射到宿主机的端口。
  • -e "discovery.type=single-node":设置Elasticsearch为单节点模式。
创建es账号

为了安全起见,我们将为Elasticsearch设置用户名和密码。运行以下命令进入Elasticsearch容器并设置密码:

shell 复制代码
# 使用root用户进入容器
docker exec --user root -it elasticsearch /bin/bash

# 添加用户
/usr/share/elasticsearch/bin/elasticsearch-users useradd jingyu
/usr/share/elasticsearch/bin/elasticsearch-users roles -a superuser jingyu
/usr/share/elasticsearch/bin/elasticsearch-users roles -a kibana_system jingyu
修改ES配置
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 07-08-2024 16:01:31
#
# --------------------------------------------------------------------------------

# 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 -------------------------
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
重启ES
shell 复制代码
docker restart elasticsearch

3. 部署Kibana

加载镜像
shell 复制代码
docker pull kibana:8.12.2
容器启动

现在,我们启动Kibana容器,并连接到Elasticsearch容器:

shell 复制代码
 docker run -d --name kibana -p 5601:5601 --link elasticsearch:elasticsearch kibana:8.12.2

这个命令将:

  • -d:在后台运行容器。
  • --name kibana:为容器命名。
  • -p 5601:5601:将容器的端口映射到宿主机的端口。
  • --link elasticsearch:elasticsearch:链接到Elasticsearch容器。
修改Kibana配置

我们需要编辑Kibana的配置文件,使其能够使用Elasticsearch的用户名和密码。首先,找到Kibana配置文件的路径,通常是在容器内的/usr/share/kibana/config/kibana.yml

运行以下命令编辑配置文件:

yml 复制代码
# 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
elasticsearch.username: "jingyu"
elasticsearch.password: "jingyu"

kibana.yml文件中,添加以下内容(使用你在步骤3中生成的用户名和密码)。

重启Kibana
shell 复制代码
docker restart kibana

现在,您可以在浏览器中访问http://localhost:5601来打开Kibana的Web界面。您可能需要使用在步骤3中设置的用户名和密码进行登录。

4. 安装插件

安装指令
shell 复制代码
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.12.2/elasticsearch-analysis-ik-8.12.2.zip
安装过程
shell 复制代码
sh-5.0$ pwd
/usr/share/elasticsearch
sh-5.0$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.12.2/elasticsearch-analysis-ik-8.12.2.zip
-> Installing https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.12.2/elasticsearch-analysis-ik-8.12.2.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.12.2/elasticsearch-analysis-ik-8.12.2.zip
[=================================================] 100%?? 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See https://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
sh-5.0$

5. 注意事项

在生产环境中,应该使用docker-compose来管理服务,并确保所有的敏感信息(如用户名和密码)都通过环境变量或加密的方式进行管理。

考虑到安全性和数据持久性,可能还需要设置卷(volume)来持久化Elasticsearch和Kibana的数据。

按照以上步骤操作后,应该能够顺利在Windows系统中使用Docker成功部署Elasticsearch、Kibana和插件,并设置用户名和密码。祝您使用愉快!

相关推荐
不要数手指啦8 分钟前
Apifox使用方法
windows
上天_去_做颗惺星 EVE_BLUE1 小时前
Docker入门教程:常用命令与基础概念
linux·运维·macos·docker·容器·bash
alden_ygq2 小时前
Kubernetes容器运行时:Containerd vs Docker
docker·容器·kubernetes
努力搬砖 ing2 小时前
Docker疑难杂症解决指南
docker·容器·eureka
林九生2 小时前
【Docker】Docker环境下快速部署Ollama与Open-WebUI:详细指南
java·docker·eureka
Grassto2 小时前
dockerfile: PaddleOCR hubserving api 服务
docker·ocr·paddleocr
Aric_Jones3 小时前
lua入门语法,包含安装,注释,变量,循环等
java·开发语言·git·elasticsearch·junit·lua
ZHOU_WUYI3 小时前
Flask Docker Demo 项目指南
python·docker·flask
撸码到无法自拔9 小时前
docker常见命令
java·spring cloud·docker·容器·eureka
IT专业服务商10 小时前
联想 SR550 服务器,配置 RAID 5教程!
运维·服务器·windows·microsoft·硬件架构