elasticsearch安装与使用(1)-使用docker安装Elasticsearch

1、Elasticsearch安装

docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.3.3
docker run --name es-node01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.3.3
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.

->  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  N-sf6R*O0Ur344otTfzc

->  HTTP CA certificate SHA-256 fingerprint:
  bfd8e24f5c41dcd170aadb0f8dbae3fe27d99633738f2d9c99dd456955523a5d

->  Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjMuMyIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiYmZkOGUyNGY1YzQxZGNkMTcwYWFkYjBmOGRiYWUzZmUyN2Q5OTYzMzczOGYyZDljOTlkZDQ1Njk1NTUyM2E1ZCIsImtleSI6InQxQUQ1SThCaWVkSFVsc3hFT3dlOnNoc1ZLVkl0UzB1R090S3EzUFotLXcifQ==

-> Configure other nodes to join this cluster:
* Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjMuMyIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiYmZkOGUyNGY1YzQxZGNkMTcwYWFkYjBmOGRiYWUzZmUyN2Q5OTYzMzczOGYyZDljOTlkZDQ1Njk1NTUyM2E1ZCIsImtleSI6InRWQUQ1SThCaWVkSFVsc3hELXp4OkJJSGx2YjQtU2pDWVBOVi11Y0VPVWcifQ==

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.3.3`
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

在这里插入图片描述

2、Kibana安装及运行

通过Kibana可以可视化的管理es数据库里的数据。

docker pull docker.elastic.co/kibana/kibana:8.3.3
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.3.3

在这里插入图片描述
在这里插入图片描述
用户名:elastic
密码:N-sf6R*O0Ur344otTfzc
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
http://0.0.0.0:5601/app/home#/
http://localhost:5601

3、curl操作

注意证书,证书从容器中复制出来后,我存放在/Users/sunwenjun/data/elastic8/http_ca.crt
注意用户名密码最好加上双引号。
The issue with zsh: no matches found: elastic:N-sf6R*O0Ur344otTfzc in your curl command is due to the * character being interpreted as a wildcard. To resolve this, you need to ensure the password is treated as a literal string. You can achieve this by quoting the password.

docker cp es-node01:/usr/share/elasticsearch/config/certs/http_ca.crt .
curl --cacert /Users/sunwenjun/data/elastic8/http_ca.crt -u "elastic:N-sf6R*O0Ur344otTfzc" https://localhost:9200/

在这里插入图片描述

4、Dev Tools可视化界面操作

在这里插入图片描述

5、python操作

pip install elasticsearch
from datetime import datetime
from elasticsearch import Elasticsearch

client =  Elasticsearch(
    hosts=['https://localhost:9200'],  # 服务地址与端口
    basic_auth=("elastic", "N-sf6R*O0Ur344otTfzc"),  # 用户名,密码
    ca_certs="/Users/sunwenjun/data/elastic8/http_ca.crt"  # 证书
)

doc = {
    'author': 'author_name',
    'text': 'Interesting content...',
    'timestamp': datetime.now(),
}
resp = client.index(index="test-index", id=1, document=doc)
print(resp['result']) # created

在这里插入图片描述

6、关闭与启动容器

docker start 容器id          # 启动容器
docker stop 容器id           # 停止当前运行的容器

参考

相关推荐

  1. Elasticsearch:(二)1.安装Elasticsearch

    2024-06-06 05:26:06       15 阅读
  2. Windows系统下使用docker安装elasticsearch和kibana

    2024-06-06 05:26:06       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 05:26:06       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 05:26:06       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 05:26:06       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 05:26:06       20 阅读

热门阅读

  1. Linux中挂载Windows Samba共享的指南

    2024-06-06 05:26:06       9 阅读
  2. python基于百度,哈工大等停用表进行的中文分词

    2024-06-06 05:26:06       8 阅读
  3. 个人关于ChatGPT的用法及建议

    2024-06-06 05:26:06       9 阅读
  4. HCIA-HarmonyOS Device Developer 课程大纲

    2024-06-06 05:26:06       10 阅读
  5. Homebrew、RVM、ruby、cocoapods

    2024-06-06 05:26:06       10 阅读
  6. actuator/env;.js 漏洞修复

    2024-06-06 05:26:06       9 阅读
  7. springcloud项目部署Nginx+Gateway+其他服务

    2024-06-06 05:26:06       9 阅读
  8. 利用LinearList类定义Stack

    2024-06-06 05:26:06       11 阅读