Linux中安装Elasticsearch(elasticsearch-7.7.0-linux-x86_64.tar.gz)并开启远程访问

一、首先简单说一下Elasticsearch是什么?
Open Source, Distributed, RESTful Search Engine;Elasticsearch是一个开源的、分布式、RESTful搜索引擎;
二、搜索技术都有哪些呢?mysql关系型数据用的这么广泛为什么还用ES呢?
1、基于数据库搜索
like %关键词%,有诸多不足与局限;
2、搜索引擎框架
解决基于数据库搜索的不足与局限,实现分布式、高可用、高性能搜索;
三、ElasticSearch VS Solr?
在近几年大数据发展时代,Elastic由于其分布式特性,满足了很多PB级大数据的处理需求,特别是后面ELK三大组合的流行,Solr使用量逐渐下跌
ElasticSearch和Solr均起源于Lucene,Lucene是基于Java语言开发的搜索引擎库类;
Lucene具有高性能、但易扩展有局限性,只能单机环境,而且只能基于Java语言开发,其他php、python等不能使用;
类库的接口学习曲线陡峭,原生并不支持水平扩展;
四、倒排索引(反向索引)
全文检索:底层是倒排索引(图片引自网络);
image.png
下面整理一下Elasticsearch 安装和运行,我是在VMware中安装的centos7,es使用的是官方压缩包来安装,也可以使用其他方式安装;

es下载地址:https://elasticsearch.cn/download/
环境依赖:Es是由java开发的,在安装时需要依赖jdk环境,一般解压即可使用,并不需要make install那些C语言软件的操作,而且在es7之后的版本里面已经内置了jdk环境。
推荐使用es内置的那个版本的jdk(记得将es中的jdk加入到环境变量里面)。

将es安装包上传至Linux中(比如/usr/local/src/elasticsearch-7.7.0-linux-x86_64.tar.gz)
将elasticsearch-7.7.0-linux-x86_64.tar.gz进行解压,并在bin目录中运行命令如下

./elasticsearch

如果不配置JAVA_HOME环境变量则会有相应的提示信息
image.png
如果jdk与elasticsearch的版本不匹配的话也不能正常启动elasticsearch,比如我配置的是jdk8作为环境变量,则会出现错误提示:至少需要jdk11以上的版本,如下
image.png
为了适配jdk与elasticsearch的兼容性,干脆就使用es中解压出来的那个jdk就可以了
image.png
在Linux中是不可以使用root用户来运行elasticsearch的,如下提示切换为普通进行启动elasticsearch命令
image.png
但是运行之后发现只能在linux本机中访问,通过win远程方式是失败的,如下
image.png
如何开始ES的远程访问?

需要修改绑定的ip:
network.host: 0.0.0.0 # 绑定到0.0.0.0,允许任何ip来访问
但是当修改配置文件之后再次运行,发现出现错误信息
ERROR: [4] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3799] for user [ts] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]: 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
image.png
针对问题[1][2]解决方式:
切换到root用户,编辑limits.conf 添加类似如下内容
vim /etc/security/limits.conf
添加如下内容:

  • soft nofile 65536
  • hard nofile 131072
  • soft nproc 2048
  • hard nproc 4096

然后重启linux
针对问题[3]
elasticsearch用户拥有的内存权限太小,至少需要262144;
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
针对问题[4]
把elasticsearch.yml中 discovery.seed_hosts 注释打开,写上当前主节点的IP;
image.png
现在能够成功运行还是不能访问,需要确认把防火墙9200端口打开试一下
image.png

————————————————
版权声明:本文为CSDN博主「天天都在Debug的程序员liuqian」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liuhePPPP/article/details/106985861
https://blog.csdn.net/liuhePPPP/article/details/106985861