ElasticSearch简介

什么是ElasticSearch:
 

  • ElasticSearch是基于Apache Lucene构建的开源搜索引擎
  • 采用Java编写,提供了简单易用的RESTFul API
  • 轻松的横向扩展,可支持PB级的结构化或非结构化的数据处理



应用场景:
 

  • 海量数据分析引擎
  • 站内搜索引擎
  • 作为数据仓库


文档地址:https://www.elastic.co/guide/en/ ... etting-started.html

部署环境:

centos 7 x64位、elasticsearch 6.5.2版本、jdk 1.8.0.191

1:安装jdk 1.8.0

ElasticSearch对JRE的版本是敏感的,错误的版本,会导致ElasticSearch无法运行。
 

【实战】Centos 7 安装Java JDK教程
https://www.itsvse.com/thread-6169-1-1.html
(出处: 架构师_程序员)


2:下载并运行ElasticSearch 6.5.2

下载地址页面:https://www.elastic.co/downloads/elasticsearch
 

  1. --下载
  2. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.2.tar.gz
  3. --解压到/usr/local/目录下面
  4. tar -zxvf elasticsearch-6.5.2.tar.gz -C /usr/local/
  5. --进入到/usr/local/目录
  6. cd /usr/local/elasticsearch-6.5.2/

复制代码

  1. --运行,如果想后台运行后面加 -d
  2. ./bin/elasticsearch

复制代码

[root@VM_0_9_centos elasticsearch-6.5.2]# ./bin/elasticsearch
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
[2018-12-11T15:24:27,847][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.2.jar:6.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.2.jar:6.5.2]
        ... 6 more




Elasticsearch 要求不能使用超级用户root运行,所以我们随便建立一个账号,我这里就得用户为es
 

  1. --创建es账户
  2. adduser es
  3.  
  4. --修改密码
  5. passwd es
  6.  
  7. --给es用户elasticsearch目录的授权。
  8. chown -R es /usr/local/elasticsearch-6.5.2/
  9.  
  10. 或则
  11.  
  12. --将 /usr/local/elasticsearch-6.5.2/ 的拥有者设置为 es
  13. chown -R es:es /usr/local/elasticsearch-6.5.2/
  14.  
  15. --切换到 es 用户,启动elasticsearch
  16. su es
  17. --启动elasticsearch
  18. ./bin/elasticsearch

复制代码



如果没有没有error,就运行成功啦

新开一个终端,用curl访问


在确定服务器端口(9200)开启,elasticsearch启动的情况下(ps -ef | grep elasticsearch)可以在浏览器中访问
 

[root@VM_0_9_centos local]# curl 'http://localhost:9200/?pretty'
{
  "name" : "iUSRV4T",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "WCbka65VTd2TnM8gQvztqg",
  "version" : {
    "number" : "6.5.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "9434bed",
    "build_date" : "2018-11-29T23:58:20.891072Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}




3:通过外网访问elasticsearch

编辑elasticsearch的配置文件
 

  1. vim ./config/elasticsearch.yml

复制代码



找到network.host: 一行,去除#号,修改为:

  1. network.host: 0.0.0.0

复制代码



(network.host: [_local_, 172.30.6.1]   172.30.6.1为指定的ip地址,可以是多个。未测试)

重新启动elasticsearch即可,然后就可以外网访问http://ip:9200 界面了。



可能遇到的错误:

错误一
 

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]


max_map_count 的值是指一个进程最多可用于的内存映射区(memory map areas),在调用malloc会用到,由mmap/mprotect生成。

解决方法 提高vm.max_map_count 的大小:
 

  1. # 切换到root用户
  2. vim /etc/sysctl.conf
  3. # 在最后面追加下面内容
  4. vm.max_map_count = 655360
  5. # 使用 sysctl -p 使其生效,并查看修改后的结果
  6. sysctl -p

复制代码





错误二
 

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]


解决办法
 

  1. #切换到root用户修改
  2. vim /etc/security/limits.conf
  3.  
  4. # 在最后面追加下面内容
  5. es hard nofile 65536
  6. es soft nofile 65536

复制代码

修改后重新登录 es 用户,使用如下命令查看是否修改成功

  1. ulimit -Hn
  2. 65536

复制代码


错误三
 

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)


解决办法
 

  1. # 由于elasticsearch5.0默认分配jvm空间大小为2g,修改jvm空间分配
  2. # 如果使用虚拟机安装,内存最好不小于2G
  3. # vim config/jvm.options  
  4. -Xms512m
  5. -Xmx512m

复制代码

阿里云上可能出现的问题:

system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk


解决方法:在elasticsearch配置中加入下面命令即可
 

  1. bootstrap.system_call_filter: false

复制代码

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐