Docker安装Elasticsearch 8.x 、Kibana 8.x等

【自取】最近整理的,有需要可以领取学习:

这里我使用的是8.2.0版本。同时内容会介绍ik分词和elastic-head的安装,elasticsearch-java的配置。

1. 下载ik分词器插件

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.2.0/elasticsearch-analysis-ik-8.2.0.zip

下载后,为后续ES容器创建一个目录esplugins(名称定制),以将插件目录挂载到该目录。因为我的对接环境是在Windows计算机下。创建目录地址C:USERSQMDesktopESesplugins8。[en]After downloading, create a directory esplugins (name customization) for subsequent es containers to mount the plug-in directory to that directory. Because my docker environment is under the window computer. Create a directory address C: Users QM Desktop es esplugins8.
将下载的压缩包解压到该目录。目录结构如下:[en]Extract the downloaded zip package to the directory. The directory structure is as follows:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

; 2. 创建docker网络

docker network create es

3. 安装ElasticSearch 8.2.0


docker pull elasticsearch:8.2.0

docker run -d --name es8 --net es ^
-v C:\Users\QM\Desktop\es\esplugins8:/usr/share/elasticsearch/plugins ^
-p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.2.0

启动后查看容器中的日志。令牌、密码和其他信息将被打印出来,并需要保存以供日后使用。页面如下。[en]View the log in the container after startup. Token, password and other information will be printed out and need to be saved for later use. The page is as follows.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

启动成功后,访问https://127.0.0.1:9200/会出现如下界面:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

账号弹性,密码在控制台生成。登录后,可以看到下图,表示启动成功:[en]The account elastic, and the password is generated on the console. After logging in, you can see the following figure, which indicates that the startup is successful:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

我这边并没有发现密码和token哈,不过不急,可以自己生成。

; 3.1 生成elastic密码及enrollment-token


docker exec -it es8 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

docker exec -it es8 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana

3.2 修改配置文件

这时,需要修改es的配置文件。增加跨域及http的配置。可以直接进入容器修改,也可以copy出来修改在copy回去。由于进入容器还需要下载vim。我这边直接copy出来修改。


docker cp es8:/usr/share/elasticsearch/config/elasticsearch.yml C:\Users\QM\Desktop\elasticsearch.yml

http.cors.enabled: true

http.cors.allow-origin: "*"

xpack.security.http.ssl:
  enabled: false

docker cp C:\Users\QM\Desktop\elasticsearch.yml es8:/usr/share/elasticsearch/config/elasticsearch.yml

这里解释下, 为什么要修改http.ssl为false
答:如果不修改,访问elasticsearch默认是 https请求。也没问题。但是在java-api中操作,请求需要配置ca证书。我觉的很麻烦。关闭后直接使用基本认证账号密码就可以了。

修改后,重新启动ES。[en]After modification, restart es.

docker restart es8

4. 安装kibana 8.2.0


docker pull kibana:8.2.0

docker run -d --net es --name kb8 -p 5601:5601  -e "I18N_LOCALE=zh-CN" kibana:8.2.0

访问地址:http://localhost:5601/,如下:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

此时,我们可以粘贴在ElasticSearch启动时生成的令牌。然后单击配置弹性。[en]At this point, we can paste in the tokens generated when elasticsearch starts. Then click configure Elastic.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

弹出窗口,Kibana需要验证码。在Kibana容器控制台也可以看到这个验证码:[en]Pop-up window, kibana needs CAPTCHA. This verification code can also be seen in the kibana container console:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

如果您没有看到它,也可以使用以下命令生成它:[en]If you don’t see it, you can also generate it using the following command:

docker exec -it kb8 /usr/share/kibana/kibana-verification-code

然后就出现了如下(如果http.ssl没关,不会出现这种情况。但是后续步骤也是差不多的,继续看就好):

Docker安装Elasticsearch 8.x 、Kibana 8.x等

额,可能是我在elasticsearch配置文件中关闭了http.sll导致的。不慌,备选方案,点击手动配置。

Docker安装Elasticsearch 8.x 、Kibana 8.x等

该地址是Kibane访问ElasticSearch的地址。如果您选中上面的缺省值,它一定没有意义。Ping本地主机:9200肯定不能在kibana容器中工作。但他们是在一个码头网络上。让我们去docker查看一下ElasticSearch的IP地址。[en]This address is * the address where kibane accesses elasticsearch * . If you check the default value above, it must not make sense. Ping localhost:9200 will definitely not work in the kibana container. But they are on a * docker network *. Let’s go to docker to check the ip address of elasticsearch.


docker network inspect es

找到下面这段话。发现ES的IP为172.18.0.2[en]Find the following paragraph. It is found that the ip of es is 172.18.0.2

Docker安装Elasticsearch 8.x 、Kibana 8.x等

在kibana页面输入http://172.18.0.2:9200检查,进入如下页面:

Docker安装Elasticsearch 8.x 、Kibana 8.x等

这个页面的用户kibana_system的密码需要我们去生成。命令如下:

docker exec -it es8 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_system

生成后,输入密码并单击配置,以下内容即被视为成功。[en]After generation, enter the password and click on the configuration, and the following is considered a success.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

配置完成后,我们将被要求登录。那么这个帐号就是弹性超级管理员帐号。如果您忘记了密码,可以看到3.1管理员重新生成密码。[en]Once configured, we will be required to log in. Then this account is the account of elastic Super Admin. If you forget your password, you can see * 3.1 administrator * to regenerate it.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

落地后,就完了![en]After landing, it is done!

Docker安装Elasticsearch 8.x 、Kibana 8.x等

5. 安装elasticsearch-head

没有必要安装这个,比如一些视频、博客等等。还可以下载节点环境、下载项目等。谷歌浏览器,对吧?谷歌商店(你作为程序员是进不去的)可以进去搜索ElasticSearch-Head。只需下载浏览器插件即可。[en]There is no need to install this, like some videos, bloggers and so on. Also download the node environment, download projects and so on. Google browser, right? Google Store (which you can’t get in, reflect on as a programmer) can go in and search elasticsearch-head. Just download the browser plug-in.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

下载完成后,打开插件页面,配置ElasticSearch地址。只要证明一下就行了。帐户密码是弹性的。[en]After downloading, open the plug-in page and configure the elasticsearch address. Just certify it. The account password is elastic.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

在登录成功之后。[en]After the login is successful.

Docker安装Elasticsearch 8.x 、Kibana 8.x等

; 6. Java-api

其实elasticsearch8.x之后的java-api的命名空间(改为co.elastic.clients)与名字(改为elasticsearch-java)都改了。像什么RestHighLevelClient这些类也弃用了。取而代之的是ElasticsearchClient。
由于我们大多数人使用的是SpringBoot,所以我们将在这里按照SpringBoot进行集成。[en]Since most of us use springboot, we will integrate according to springboot here.

6.1 引入依赖

我这里的弹簧靴是2.7.0。请注意,该版本是兼容的,并尝试与ES服务版本相同。[en]My springboot here is 2.7.0. Note that the version is compatible and try to be the same as the es service version.

<dependency>
  <groupId>org.springframework.bootgroupId>
  <artifactId>spring-boot-starter-data-elasticsearchartifactId>
dependency>

<dependency>
  <groupId>jakarta.jsongroupId>
  <artifactId>jakarta.json-apiartifactId>
  <version>2.0.1version>
dependency>

6.2 配置yml

spring:
  elasticsearch:
    username: elastic
    password: Zwpf5villae8_S+ZizxR

6.3 配置bean

由于自动配置类,最高版本与Elasticearch Client不兼容。或注入RestHighLevelClient。因此,我们自己配置注入Elasticearch客户端。[en]Due to the automatic configuration class, the highest version is not compatible with ElasticsearchClient. Or injected RestHighLevelClient. So we configure the injection ElasticsearchClient on our own.


@Bean
ElasticsearchClient elasticsearchClient(RestClient restClient) {

    ElasticsearchTransport transport = new RestClientTransport(
        restClient,
        new JacksonJsonpMapper()
    );
    return new ElasticsearchClient(transport);
}

6.4 总结

我相信Java对于那些能够阅读这篇文章的人来说并不弱。具体接口请参考官网:[en]I believe that Java is not weak for those who can read this article. For specific API, please refer to the official website:
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html

Original: https://blog.csdn.net/weixin_45056780/article/details/125408524
Author: 世代农民
Title: Docker安装Elasticsearch 8.x 、Kibana 8.x等

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6089/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部