Elasticsearch 安装(Linux)

news2024/9/28 1:19:14

ElasticSearch

    • 概念
    • 安装
      • 安装es
    • 后台启动 & 停止
      • 启动
        • nohup 记录pid
      • 停止
    • 其他启动错误
      • max number of threads
      • 内存不足 Cannot allocate memory
      • failed to obtain node locks

概念

ES是一款分布式全文搜索引擎,基于Lucene,进行了二次封装,更容易上手。

安装

基于Java环境,最好提前安装好Java环境,有一个自带的jdk,但是版本可能不是其他组件需要的。
我们这里基于虚拟机来安装 es

安装es

  • 下载官网
    手动下载或者 curl 直接下载
    官网可能会比较慢,国内也有镜像站 华为
    这是ES历史版本
curl -O https://repo.huaweicloud.com/elasticsearch/7.14.0/elasticsearch-7.14.0-linux-x86_64.tar.gz
  • es放入 opt 目录下(个人习惯)
  • 解压
tar zxvf /opt/elasticsearch-7.14.0-linux-x86_64.tar.gz 
  • 启动

    • 启动

      ./bin/elasticsearch
      

      报错,新版本的es不允许以 root 启动,

      		[ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [origin.centos] uncaught exception in thread [main]
      org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
              at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.14.0.jar:7.14.0]
              at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.14.0.jar:7.14.0]
      Caused by: java.lang.RuntimeException: can not run elasticsearch as root
              at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399) ~[elasticsearch-7.14.0.jar:7.14.0]
              at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.14.0.jar:7.14.0]
              ... 6 more
      uncaught exception in thread [main]
      java.lang.RuntimeException: can not run elasticsearch as root
              at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103)
              at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
              at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399)
              at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
              at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
              at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
              at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
              at org.elasticsearch.cli.Command.main(Command.java:79)
              at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
              at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
      For complete error details, refer to the log at /opt/elasticsearch-7.14.0/logs/elasticsearch.log
      
    • 这里为其创建一个用户 elastic

      useradd elastic
      
    • 设置密码

      passwd elastic
      

      根据提示设置完密码

    • 目录授权

      chown -R elastic /opt/elasticsearch-7.14.0
      
    • 创建es 存储日志及数据的目录

      mkdir -p /data/es
      chown -R elastic /data/es
      mkdir -p /var/log/es
      chown -R elastic /var/log/es
      
    • 修改 elasticsearch.yml 配置日志及数据目录,位于 Paths 节点下

      # ----------------------------------- Paths ------------------------------------
      #
      # Path to directory where to store the data (separate multiple locations by comma):
      #
      path.data: /data/es
      #
      # Path to log files:
      #
      path.logs: /var/log/es
      #
      
    • 切换用户

      su elastic 
      
    • 再启动

      ./bin/elasticsearch
      

      启动成功,但是有警告信息 在这里插入图片描述
      这个放到后面再说

  • 访问ES
    我们先在虚拟机本地访问,可以看到成功访问到

    curl localhost:9200
    {
     "name" : "origin.centos",
     "cluster_name" : "elasticsearch",
     "cluster_uuid" : "XVgPBZ78RdWRssPtuSeJTg",
     "version" : {
       "number" : "7.14.0",
       "build_flavor" : "default",
       "build_type" : "tar",
       "build_hash" : "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
       "build_date" : "2021-07-29T20:49:32.864135063Z",
       "build_snapshot" : false,
       "lucene_version" : "8.9.0",
       "minimum_wire_compatibility_version" : "6.8.0",
       "minimum_index_compatibility_version" : "6.0.0-beta1"
     },
     "tagline" : "You Know, for Search"
    }
    

    然后我们在宿主机访问 虚拟机ip:9200 发现访问不了;
    其实在虚拟机 通过ip也访问不了

    [root@origin ~]# curl 192.168.0.101:9200
    curl: (7) Failed connect to 192.168.0.101:9200; Connection refused
    

    这是因为,ES默认,只能通过本地回环地址访问

  • 修改ES网络配置

    vim /opt/elasticsearch-7.14.0/config/elasticsearch.yml
    
    network.host: 0.0.0.0
    

    保存退出

  • 再启动ES

    ./bin/elasticsearch
    

    会发现,报错咯,大概意思是要解决以下这三个问题才能启动
    在这里插入图片描述

    • 第一个
      max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
      则需要配置 elasticsearch 进程,里面以是用户的角度去配置的 可打开的最大文件数
      vim /etc/security/limits.conf
      
      # 用户名 elastic ,不限制用户 用 * 替代
      elastic soft nofile 65536
      elastic hard nofile 65536
      
    • 第二个
      max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
      这个值是系统层面的,和用户进程没啥关系
      vim /etc/sysctl.conf
      
      vm.max_map_count = 262144
      
      保存退出。
      刷新配置
      sysctl -p
      
    • 第三个
      the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
      大概意思是,默认集群节点发现(这就是由于上面开启其他主机访问的缘故)配置不适用于生产环境,至少配置以下一项。
      修改配置文件,这里设置 discovery.seed_hosts 这个属性
      vim /opt/elasticsearch-7.14.0/config/elasticsearch.yml
      
      # 本机ip
      discovery.seed_hosts: ["192.168.0.101"]
      
  • 再次启动ES

    ./bin/elasticsearch
    

    到这里,我已经能够在其他主机上通过ip访问 ES了
    在这里插入图片描述

后台启动 & 停止

启动

  • nohup ./bin/elasticsearch > /dev/null 2>&1 &
  • nohup /opt/elasticsearch-7.14.0/bin/elasticsearch > /dev/null 2>&1 &
  • ./bin/elasticsearch -d -p pid(记录pid的一个文件,可以用于脚本管理启停) #相对路径
  • /opt/elasticsearch-7.14.0/bin/elasticsearch -d #绝对路径

nohup 记录pid

路径既可以是相对路径也可以是绝对路径

nohup /opt/elasticsearch-7.14.0/bin/elasticsearch >/dev/null 2>&1 & echo $! > pid

nohup /opt/elasticsearch-7.14.0/bin/elasticsearch >/dev/null 2>&1 & echo $! > /opt/elasticsearch-7.14.0/pid

停止

kill [-9] pid
kill cat pid(启动时记录pid的文件)
cat pid(启动时记录pid的文件) | xargs kill [-9]

其他启动错误

max number of threads

max number of threads [3818] for user [elastic] is too low, increase to at least [4096] 类似问题,则需要配置 当前用户启动的进程允许开启多少个线程

vim /etc/security/limits.conf
# 用户名 elastic ,不限制用户 用 * 替代
elastic soft nproc 4096
elastic hard nproc 4096

内存不足 Cannot allocate memory

将ES所需内存调小后,再启动ES。

vim ./config/jvm.options

-Xms2g
-Xmx2g

failed to obtain node locks

这是由于当前节点上已经有ES实例绑定了数据目录。
此时要看是否确实需要在节点上运行多个实例。
如果需要

  • 则修改配置文件 elasticsearch.yml
    配置当前节点可以运行的es实例数
node.max_local_storage_nodes: 2

否则,需停止当前正在运行的ES进程,再启动。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/656860.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ElasticSearch笔记02-ElasticSearch入门

ElasticSearch安装 下载软件 ElasticSearch的官网,视频教程里用的Version是7.8.0,所以,我们也是用7.8.0版本的ElasticSearch。 下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch,然后搜索…

车载诊断协议 —— 诊断服务Service 11

我是穿拖鞋的汉子,魔都中坚持长期主义的工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 在最艰难的时候,自己就别去幻想太远的将来,只要鼓励自己过好今天就行了! 这世间有太多的猝不及防,有些东西根本不配占有自己的情绪,人生就是一场体验,…

一种栅格数据的空间聚类方法(ACA-Cluster)

本文结合实例详细讲解了如何使用Python对栅格数据进行空间聚类,关注公众号GeodataAnalysis,回复20230616获取示例数据和代码,包含整体的写作思路,上手运行一下代码更容易弄懂。 带有非空间属性的空间数据聚类分析是空间聚类研究的…

English Learning - L3 作业打卡 Lesson6 Day43 2023.6.16 周五

English Learning - L3 作业打卡 Lesson6 Day43 2023.6.16 周五 引言🍉句1: Thousands of lanterns slowly drift out to sea guiding the dead on their return journey to the other world.成分划分弱读连读爆破语调 🍉句2: This is a moving spectacl…

炎炎夏日!东南亚LazadaShopee泳衣品类热销榜单来袭

6月商机无限,趁热打铁!3大节庆即将来袭。小编特为卖家整理了6月最强爆单选品指南,揭秘东南亚泳衣市场。赶紧一睹为快吧! 炎炎夏日,马上即将迎来暑假,海边游玩肯定成了小朋友即家长们的首选之地&#xff0c…

js将json字符串转换为json对象的方法解析

将json字符串转换为json对象的方法。在数据传输过程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键。 例如: JSON字符串: var str1 ‘{ “n…

MIT 6.S081 Lab Three

MIT 6.S081 Lab Three 引言page tablesPrint a page table (easy)代码解析 A kernel page table per process (hard)代码解析 Simplify copyin/copyinstr(hard)代码解析 可选的挑战练习 引言 本文为 MIT 6.S081 2020 操作系统 实验三解析。 MIT 6.S081…

shardingsphere第一课-前置课程-Mysql的集群搭建以及多数据源管理

一.Mysql的集群搭建(使用docker搭建省事) 1、关闭防火墙,重启docker** #关闭docker systemctl stop docker #关闭防火墙 systemctl stop firewalld #启动docker systemctl start docker2.1、准备主服务器 解释: 端口号是3306, 指定宿主机配…

FPGA基础知识-时序和延迟

目录 学习目标: 学习内容: 1.延迟模型的类型 2.路径延迟建模 3.时序检查 4.延迟反标注 学习时间: 学习总结 学习目标: 提示:这里可以添加学习目标 鉴别Verilog 仿真中用到的延迟模型的类型,分布延…

YOLOv5改进系列(10)——替换主干网络之GhostNet

【YOLOv5改进系列】前期回顾: YOLOv5改进系列(0)——重要性能指标与训练结果评价及分析 YOLOv5改进系列(1)——添加SE注意力机制

项目中还不会用SpringSecurity,看这篇文章就够了

安全管理是Java应用开发中无法避免的问题,随着Spring Boot和微服务的流行,Spring Security受到越来越多Java开发者的重视,究其原因,还是沾了微服务的光。作为Spring家族中的一员,其在和Spring家族中的其他产品如SpringBoot、Spring Cloud等进…

client-go的Indexer三部曲之而:性能测试

欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是《client-go的Indexer》系列的第二篇,在前文咱们通过实例掌握了client-go的Indexer的基本功能,本篇咱们尝试对下面这…

6.pixi.js编写的塔防游戏(类似保卫萝卜)-游戏资源打包逻辑

游戏说明 一个用pixi.js编写的h5塔防游戏,可以用electron打包为exe,支持移动端,也可以用webview控件打包为app在移动端使用 环境说明 cnpm6.2.0 npm6.14.13 node12.22.7 npminstall3.28.0 yarn1.22.10 npm config list electron_mirr…

配置legacyUnhandledExceptionPolicy属性防止处理异常后程序崩溃退出(C#)

这是这篇文章后面遗留的问题: winform中的全局异常信息_winform全局异常捕获_zxy2847225301的博客-CSDN博客 就是线程抛出异常后,被AppDomain.CurrentDomain.UnhandledException注册的事件捕获后,程序依旧崩溃退出。 解决方案:在…

架构-嵌入式模块

章节架构 约三分,主要为选择题 #mermaid-svg-z6RGCDSEQT5AhE1p {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-z6RGCDSEQT5AhE1p .error-icon{fill:#552222;}#mermaid-svg-z6RGCDSEQT5AhE1p .error-text…

【产品经理】从用户体验五要素出发,谈如何设计与体验一款产品

用户体验五要素是产品人必备的知识技能,由于网络碎片化的了解,往往容易造成其高深莫测,晦涩难懂的形象,进而对其束之高阁。但实质不过是一种产品分析与设计的方法论,正确姿势去了解它能帮助我们更好地理解一款产品和从…

移动端小于12px的字体处理方法

今天在按设计稿坐页面时&#xff0c;遇到了下图的情况 ​​​​​ 由于浏览器对字体最小为12px的限制&#xff0c;所以我查阅资料后尝试使用transform:scale来处理 代码如下&#xff1a; <div class"icon"><span class"iconfont icon-a-xuexi3 icon-…

ZYNQ——PL端流水灯的实现

文章目录 一、介绍二、代码编写三、引脚分配四、仿真分析五、添加 ILA IP六、板上验证 一、介绍 本文介绍的是在ZYNQ 7020黑金开发板上实现PL端流水灯的例子&#xff0c;开发板上PL端的LED灯总共有4个&#xff0c;在原理图中找到 PL LED 如下图所示&#xff0c;通过看图可知&a…

【MarkDown】CSDN Markdown之四象限图quadrantChart详解

四象限图 四象限图是一种将数据分为四个象限的可视化方法。它用于在二维网格上绘制数据点&#xff0c;其中一个变量表示x轴&#xff0c;另一个变量表示y轴。根据针对正在分析的数据集的一组标准&#xff0c;将图表分成四个相等的部分来确定四个象限。经常使用四象限图来识别数…

父亲节|祝天下所有父亲节日快乐,长寿安康!

父亲节&#xff0c;是一个感谢父亲的节日。普遍认为的日期是每年6月的第三个星期日&#xff0c;在这一天世界上有52个国家和地区在过父亲节。同时注重孝道也是我们中华民族的传统文化。 在这个感恩的节日里 把最真诚美好的祝福 送给天下所有的父亲们 祝福他们 节日快乐&…