用docker将Elasticsearch部署并可使用

– 目标

为了跟上Elasticsearch的步伐,我希望能有一个可以实践的环境。
因此,这次我使用了Docker来配置Elastic Stack环境。

结尾

一旦浏览了docker-elk,您就可以立即完成。

现在开始制作

克隆

我将从docker-elk进行克隆。

git clone https://github.com/deviantony/docker-elk

为了分析日本语,我要安装插件。

请在elasticsearch/Dockerfile中添加下面的内容

ARG ELASTIC_VERSION

# https://www.docker.elastic.co/
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}

# Add your elasticsearch plugins setup here
# Example: RUN elasticsearch-plugin install analysis-icu
RUN curl -L -k -O https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-kuromoji/analysis-kuromoji-8.7.0.zip
RUN curl -L -k -O https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-8.7.0.zip 

RUN cp analysis-* /tmp

RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///tmp/analysis-kuromoji-8.7.0.zip
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///tmp/analysis-icu-8.7.0.zip

根据评论中所写的,按照正常情况来说,可以使用RUN elasticsearch-plugin install analysis-kuromoji来进行安装。但由于特殊情况,我们这次选择了上述的写法。

建筑,启动

我们将进行构建和启动。

docker compose build
~
docker compose up

访问Kibana

访问 http://localhost:5601
认证信息默认如下所示:
用户:elastic
密码:changeme
如果成功认证并显示主页,则表示成功。

更改密码

为了安全起见,我们将更改默认使用的密码。请按照以下顺序执行操作。请在”New value”处备份新密码。

docker compose exec elasticsearch bin/elasticsearch-reset-password --batch --user elastic
Password for the [elastic] user successfully reset.
New value: new_password
docker compose exec elasticsearch bin/elasticsearch-reset-password --batch --user logstash_internal
Password for the [logstash_internal] user successfully reset.
New value: new_password
docker compose exec elasticsearch bin/elasticsearch-reset-password --batch --user kibana_system
Password for the [kibana_system] user successfully reset.
New value: new_password

更新环境

将env文件中以下部分替换为刚刚生成的密码。

ELASTIC_VERSION=8.7.0

## Passwords for stack users
#

# User 'elastic' (built-in)
#
# Superuser role, full access to cluster management and data indices.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
ELASTIC_PASSWORD='new_password' # ここを更新

# User 'logstash_internal' (custom)
#
# The user Logstash uses to connect and send data to Elasticsearch.
# https://www.elastic.co/guide/en/logstash/current/ls-security.html
LOGSTASH_INTERNAL_PASSWORD='new_password' # ここを更新

# User 'kibana_system' (built-in)
#
# The user Kibana uses to connect and communicate with Elasticsearch.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
KIBANA_SYSTEM_PASSWORD='new_password' # ここを更新
~

运行以下命令,进行重启。

docker-compose up -d logstash kibana

重新访问Kibana

请使用以下默认的认证信息访问 http://localhost:5601:
用户名:elastic
密码:new_password

试着去GET一下

在Dev Tools中执行以下操作。

GET _security/role

只要能确认默认角色,比如观察者用户等等就可以了。

bannerAds