首页 > 其他分享 >Elasticsearch环境搭建

Elasticsearch环境搭建

时间:2023-09-06 13:56:43浏览次数:43  
标签:bin elastic -- 环境 kibana Elasticsearch elasticsearch docker 搭建

一、安装 elasticsearch

-- 拉取镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.9.1  
-- 创建 docker 网络
docker network create elastic    
-- 启动容器,-m 设置内存大小
docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.9.1
-- 将证书从容器复制到本地计算机
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .  

首次启动后,控制台会输出用户名密码和注册令牌

✅ 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`):
  j1QUuCeQbcawuLkvJ*=u

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  82e5fd26d657c97027721a4e47f464063e40cb67a104ef847b5cff3887f2f52e

ℹ️  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):
  eyJ2ZXIiOiI4LjkuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiODJlNWZkMjZkNjU3Yzk3MDI3NzIxYTRlNDdmNDY0MDYzZTQwY2I2N2ExMDRlZjg0N2I1Y2ZmMzg4N2YyZjUyZSIsImtleSI6ImtSSWlYb29CbEdlcWJ4aEFodTVCOnlaTUIxX2NMVFc2enB6RVhKVm9IVkEifQ==

ℹ️ 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):
  eyJ2ZXIiOiI4LjkuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiODJlNWZkMjZkNjU3Yzk3MDI3NzIxYTRlNDdmNDY0MDYzZTQwY2I2N2ExMDRlZjg0N2I1Y2ZmMzg4N2YyZjUyZSIsImtleSI6Imt4SWlYb29CbEdlcWJ4aEFodTVCOnA5NlFONVdFUkdDdi1rNy1RYkx3ZncifQ==

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

打开浏览器访问 https://localhost:9200 输入用户名 elastic 密码 j1QUuCeQbcawuLkvJ*=u ,页面返回:

{
    name: "c0766560ee1a",
    cluster_name: "docker-cluster",
    cluster_uuid: "pQ8iWzM5TQGPY0W8vQOlVQ",
    version: {
    number: "8.9.1",
    build_flavor: "default",
    build_type: "docker",
    build_hash: "a813d015ef1826148d9d389bd1c0d781c6e349f0",
    build_date: "2023-08-10T05:02:32.517455352Z",
    build_snapshot: false,
    lucene_version: "9.7.0",
    minimum_wire_compatibility_version: "7.17.0",
    minimum_index_compatibility_version: "7.0.0"
    },
    tagline: "You Know, for Search"
}

elasticsearch 令牌过期

-- 刷新令牌
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana --url "https://127.0.0.1:9200"

密码错误

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

输出结果:

xadyo97zTpBfLl56j38C  

二、安装 kibana

-- 拉取镜像
docker pull docker.elastic.co/kibana/kibana:8.9.1  
-- 运行容器
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.9.1  
-- 创建本地目录
sudo mkdir -p /opt/docker/kibana/config  
-- 修改目录权限
sudo chmod -R 777 /opt/docker/kibana
-- 拷贝配置文件到本地
sudo docker cp kib-01:/usr/share/kibana/config /opt/docker/kibana/  
-- 删除容器
docker stop kib-01 
docker rm kib-01  
-- 运行容器,指定名称、端口、挂载外部配置文件
docker run --name kib-01 --net elastic -p 5601:5601 -v /opt/docker/kibana/config:/usr/share/kibana/config docker.elastic.co/kibana/kibana:8.9.1   

访问 http://localhost:5601 页面会弹出配置窗口,输入 elasticsearch 初次启动输出的令牌进行关联

eyJ2ZXIiOiI4LjkuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiODJlNWZkMjZkNjU3Yzk3MDI3NzIxYTRlNDdmNDY0MDYzZTQwY2I2N2ExMDRlZjg0N2I1Y2ZmMzg4N2YyZjUyZSIsImtleSI6Imt4SWlYb29CbEdlcWJ4aEFodTVCOnA5NlFONVdFUkdDdi1rNy1RYkx3ZncifQ==

输入后 在 kibana 控制台获取到验证码输入即可

配置完成后会弹出 elastic 登录页面,输入 elasticsearch 的用户名和密码即可

如果令牌过期,可执行如下命令:

-- 刷新令牌
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana --url "https://127.0.0.1:9200"

三、安装Logstash

官网下载
注:Logstash 直接采用本地安装包解压方式执行

导入数据

下载 movies.csv 文件,存放到bin目录下
在bin目录下创建 logstash.conf 文件:

input {
  file {
    path => "/{自己的文件目录}/elasticsearch/logstash-8.9.1/bin/movies.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
    separator => ","
    columns => ["id","content","genre"]
  }

  mutate {
    split => { "genre" => "|" }
    remove_field => ["path", "host","@timestamp","message"]
  }

  mutate {

    split => ["content", "("]
    add_field => { "title" => "%{[content][0]}"}
    add_field => { "year" => "%{[content][1]}"}
  }

  mutate {
    convert => {
      "year" => "integer"
    }
    strip => ["title"]
    remove_field => ["path", "host","@timestamp","message","content"]
  }

}
output {
   elasticsearch {
     hosts => "https://localhost:9200"
     index => "movies"
     document_id => "%{id}"
     ssl_certificate_verification => "true"
     cacert => "/Users/zhulizhong/Software/elasticsearch/logstash-8.9.1/bin/http_ca.crt"
     user => "elastic"
     password => "xadyo97zTpBfLl56j38C"
   }
  stdout {}
}

然后执行导入命令

./logstash -f /Users/zhulizhong/Software/elasticsearch/logstash-8.9.1/bin/logstash.conf

failed to obtain node locks 错误

删除 /data/.lock 文件

unable to find valid certification path to requested target 错误

配置elasticsearch证书文件
配置elasticsearch用户名密码  

标签:bin,elastic,--,环境,kibana,Elasticsearch,elasticsearch,docker,搭建
From: https://www.cnblogs.com/emptyironbox/p/17682119.html

相关文章

  • Elasticsearch7.8集群实践记录之下线节点
    1.背景:由于机房迁移需要将elasticsearch集群进行跨机房搬迁,采取先扩容再收缩的方式进行,已有效减小对业务环境的影响。当前需要将老的节点有序下线。2.操作步骤:  1.检查集群配置,保证主节点的可用性;   #设置minimum_master_nodes为2curl-XPUT'http://hostname:9......
  • Python 设置环境变量方法
    Python中的os模块Python中的os模块提供了很多与操作系统相关的功能。其中就包括设置环境变量的方法,即setenv()方法。使用os.setenv()方法设置环境变量importosos.setenv('VAR_NAME','VAR_VALUE')其中,VAR_NAME是环境变量的名称,VAR_VALUE是环境变量的值。这样我们就可以使用......
  • Elasticsearch7.8集群实践记录
    1.背景:当需要开发团队搭建自有elasticsearch集群时候,需要先明确具体的应用场景,进而对可用性,性能以及容量进行评估。当前实践记录主要应用场景在于业务日志记录短暂保存以便提供近期数据查询,并选择elasticsearch版本7.8.0,可用性要求三个9,每日数据量月1.5T,数据保存大约1周;2.配置项......
  • Elasticsearch
    ES(分布式、开源、查询)传统数据一般会分三个方向:结构化数据、非结构化数据、半结构化数据结构化数据:一般每个字段之间都是有关系的,例如mysql的主键唯一id代表了该条数据的唯一定位(mysql、mongodb)非结构化数据:无法用二维表结构来设计,文章、日志、视频、图片等等(mongodb、redis)......
  • 海外代购系统/代购网站怎么搭建
    搭建海外代购系统/代购网站的详细步骤涉及到的内容非常多,本文将分为以下几个部分进行详细介绍:前端开发、后端管理系统的开发、数据库设计和代购流程的设计与实现。一、前端开发前端开发是整个代购网站的门面,它直接面向用户,因此对于用户体验和网站形象至关重要。在进行前端开发时......
  • 《动手学深度学习 Pytorch版》 4.9 环境和分布偏移
    4.9.1分布偏移的类型整节理论,详见书本。4.9.2分布偏移示例整节理论,详见书本。4.9.3分布偏移纠正整节理论,详见书本。4.9.4学习问题的分类法整节理论,详见书本。4.9.5机器学习中的公平、责任和透明度整节理论,详见书本。练习(1)当我们改变搜索引擎的行为时会发生什么?用......
  • 007-SpringBoot+Mybatis+Sqlite框架搭建
    1,配置文件(application.yaml)server:port:6695spring:datasource:url:jdbc:sqlite:D:/examtolearn.dbusername:password:driver-class-name:org.sqlite.JDBCmybatis:mapper-locations:classpath:mapper/*.xmlconfiguration:log-......
  • Elasticsearch系列
    Elasticsearch介绍Elasticsearch系列之-linux.docker安装和基础操作Elasticsearch系列之-windows安装和基础操作Elasticsearch系列之-查询......
  • DevOps |研发效能之环境、程序、配置、SQL变更管理
    本文主要是讲如何建立有效的环境、程序、配置、SQL变更和管理平台。几天前和一个朋友聊到环境、程序的配置变更,SQL变更和整个上线流程。之前我们在这块也做了很多,有做的好的也有做的一般的,借机都总结下来,希望对你有用。通常情况下,我们最关注的也是最重要的部分是应用的变更,就是程序......
  • 配置后端环境变量
    安装后端所需基本依赖项目的接口文档https://apifox.com/apidoc/shared-5a53a935-41de-43d0-9bd7-272baf4f7fc6下面是安装后端基本环境一、安装nodehttps://nodejs.cn/download/点击下载对应的版本安装完后在控制台输入node-v可查看是否安装成功二、下载hbuilderX编辑器https......