详解centos7虚拟机安装elasticsearch5.0.x-安装篇

centos7虚拟机安装elasticsearch5.0.x-安装篇

请预先安装jdk详细步骤请参考:http://www.jb51.net/softjc/193398.html

创建新用户(非root用户)

elasticsearch只能用非root启动,这里我创建了一个叫seven的用户

[root@localhost ~]# useradd seven
[root@localhost ~]# passwd seven

下载elasticsearch

[root@localhost ~]# su seven
[seven@localhost root]$ cd /home/seven
[seven@localhost ~]$ mkdir download
[seven@localhost ~]$ cd download
[seven@localhost download]$ wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha3/elasticsearch-5.0.0-alpha3.tar.gz

解压并运行elasticsearch

解压

[seven@localhost download]$ tar -zxvf elasticsearch-5.0.0-alpha3.tar.gz

移动到指定文件夹并重命名(方便管理)

[seven@localhost download]$ mv elasticsearch-5.0.0-alpha3 /usr/java/elasticsearch

修改访问elasticsearch的IP及端口

[seven@localhost config]$ vim /usr/java/elasticsearch/config/elasticsearch.yml

找到如下代码段,并取消network.host及http.port所在行的注释,修改IP及端口

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.0.155
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>

直接运行bin/elasticsearch文件启动elasticsearch

[seven@localhost bin]$ cd /usr/java/elasticsearch/bin/
[seven@localhost bin]$ ./elasticsearch

启动时发现报错了。。。

[seven@localhost bin]$ ./elasticsearch
[2016-06-28 13:49:27,899][INFO ][node      ] [Mondo] version[5.0.0-alpha3], pid[3671], build[cad959b/2016-05-26T08:25:57.564Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1 .0_91/25.91-b14]
▽2016-06-28 13:49:27,900][INFO ][node      ] [Mondo] initializing ...
[2016-06-28 13:49:28,941][INFO ][plugins     ] [Mondo] modules [percolator, lang-mustache, lang-painless, ingest-grok, reindex, lang-expression, lang-groovy], plugins []
[2016-06-28 13:49:28,963][INFO ][env      ] [Mondo] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [15.7gb], net total_space [17.4gb], spins? [unknown], types [rootfs]
[2016-06-28 13:49:28,963][INFO ][env      ] [Mondo] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-06-28 13:49:31,980][INFO ][node      ] [Mondo] initialized
[2016-06-28 13:49:31,980][INFO ][node      ] [Mondo] starting ...
[2016-06-28 13:49:32,115][INFO ][transport    ] [Mondo] publish_address {192.168.0.155:9300}, bound_addresses {192.168.0.155:9300}
Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed
initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)
  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)
  at org.elasticsearch.node.Node.start(Node.java:337)
  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)
  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)
  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)
  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)
  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)
  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)
  at org.elasticsearch.cli.Command.main(Command.java:53)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)
Refer to the log for complete error details.
[2016-06-28 13:49:32,144][INFO ][node      ] [Mondo] stopping ...
[2016-06-28 13:49:32,198][INFO ][node      ] [Mondo] stopped
[2016-06-28 13:49:32,198][INFO ][node      ] [Mondo] closing ...
[2016-06-28 13:49:32,210][INFO ][node      ] [Mondo] closed

于是我临时提高了vm.max_map_count的大小

*此操作需要root权限

[root@localhost ~]# sysctl -w vm.max_map_count=262144

查看修改结果

[root@localhost ~]# sysctl -a|grep vm.max_map_count
vm.max_map_count = 262144

或者永久性修改

[root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf
[root@localhost ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf
[root@localhost ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf
mv:是否覆盖"/etc/sysctl.conf"? y
[root@localhost ~]# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
vm.max_map_count = 262144

上面还有一个错误是关于jvm内存分配的问题heap size [268435456] not equal to maximum heap size [2147483648],需要修改的jvm配置

[seven@localhost bin]$ vim /usr/java/elasticsearch/config/jvm.options

将-Xmx2g改成-Xmx256m,也就是heap size [268435456] /1024/1024的值

又有新的错误。。。

Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed
initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
memory locking requested for elasticsearch process but memory is not locked
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)
  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)
  at org.elasticsearch.node.Node.start(Node.java:337)
  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)
  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)
  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)
  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)
  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)
  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)
  at org.elasticsearch.cli.Command.main(Command.java:53)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)
Refer to the log for complete error details.
[2016-06-28 14:55:49,770][INFO ][node      ] [Goldbug] stopping ...
[2016-06-28 14:55:49,875][INFO ][node      ] [Goldbug] stopped
[2016-06-28 14:55:49,875][INFO ][node      ] [Goldbug] closing ...
[2016-06-28 14:55:49,887][INFO ][node      ] [Goldbug] closed

这个问题折腾了我一下午,最后还是找到了解决方案,同样回到config/elasticsearch.yml文件,找到如下配置,开放discovery.zen.ping.unicast.hosts及discovery.zen.minimum_master_nodes

# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.0.155"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>

然后修改max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]这个错误(切换到root操作)

[root@localhost ~]# cp /etc/security/limits.conf /etc/security/limits.conf.bak
[root@localhost ~]# cat /etc/security/limits.conf | grep -v "seven" > /tmp/system_limits.conf
[root@localhost ~]# echo "seven hard nofile 65536" >> /tmp/system_limits.conf
[root@localhost ~]# echo "seven soft nofile 65536" >> /tmp/system_limits.conf
[root@localhost ~]# mv /tmp/system_limits.conf /etc/security/limits.conf

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

[seven@localhost ~]$ ulimit -Hn
65536

接下来就可以启动elasticsearch了,启动完成使用浏览器访问http://192.168.0.155:9200

{
 "name" : "Vampire by Night",
 "cluster_name" : "elasticsearch",
 "version" : {
 "number" : "5.0.0-alpha3",
 "build_hash" : "cad959b",
 "build_date" : "2016-05-26T08:25:57.564Z",
 "build_snapshot" : false,
 "lucene_version" : "6.0.0"
 },
 "tagline" : "You Know, for Search"
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • SpringBoot整合ElasticSearch实践

    本节我们基于一个发表文章的案例来说明SpringBoot如何elasticsearch集成.elasticsearch本身可以是一个独立的服务,也可以嵌入我们的web应用中,在本案例中,我们讲解如何将elasticsearch嵌入我们的应用中. 案例背景:每个文章(Article)都要属于一个教程(Tutorial),而且每个文章都要有一个作者(Author). 一.实体设计: Tutorial.java public class Tutorial implements Serializable

  • Elasticsearch.Net使用入门教程(1)

    本文实例为大家分享了Elasticsearch.Net使用教程,供大家参考,具体内容如下 首先去官网下载Elasticsearch 2.3.4安装包,解压后,在cmd命令行进入安装目录,再进入 bin目录,运行elasticsearch.bat命令. elasticsearch插件elasticsearch-head安装: bin目录下执行命令plugin -install mobz/elasticsearch-head 然后开始.net编程,构建控制台应用程序 Program.cs代码如下:

  • 安装ElasticSearch搜索工具并配置Python驱动的方法

    ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是第二流行的企业搜索引擎.设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便. 我们建立一个网站或应用程序,并要添加搜索功能,令我们受打击的是:搜索工作是很难的.我们希望我们的搜索解决方案要快,我们希望有一个零配置和一个完全免费的搜索模式,我们希望能够简单

  • centos下root运行Elasticsearch异常问题解决

     在CentOS 6.5 上运行Elasticsearch 2.3,异常如下: Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root. at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93) at org.elasticsearch.bootstrap.Bootstra

  • 详解spring-boot集成elasticsearch及其简单应用

    介绍 记录将elasticsearch集成到spring boot的过程,以及一些简单的应用和helper类使用. 接入方式 使用spring-boot中的spring-data-elasticsearch,可以使用两种内置客户端接入 1.节点客户端(node client): 配置文件中设置为local:false,节点客户端以无数据节点(node-master或node-client)身份加入集群,换言之,它自己不存储任何数据,但是它知道数据在集群中的具体位置,并且能够直接转发请求到对应的节

  • Elasticsearch.Net使用教程 MVC4图书管理系统(2)

    本文实例为大家分享了MVC4图书管理系统的制作教程,供大家参考,具体内容如下 首先项目结构图: Model层的相关代码如下: Book.cs代码如下: public class Book { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [MaxLength(500)] [Display(Name = "标题")] public string Title

  • 详解spring中使用Elasticsearch的代码实现

    在使用Elasticsearch之前,先给大家聊一点干货. 1.      ES和solr都是作为全文搜索引擎出现的.都是基于Lucene的搜索服务器. 2.   ES不是可靠的存储系统,不是数据库,它有丢数据的风险. 3.  ES不是实时系统,数据写入成功只是trans log成功(类似于MySQL的bin log),写入成功后立刻查询查不到是正常的.因为数据此刻可能还在内存里而不是进入存储引擎里.同理,删除一条数据后也不是马上消失.写入何时可查询?ES内部有一个后台线程,定时将内存中的一批数

  • elasticsearch插件开发教程

    检索引擎Elasticsearch支持插件模式.有些时候你可能须要安装一些插件.甚至自己开发插件,这里就提供一个開始ES插件开发演示样例,ES版本号为1.5.2. 一.插件类继承自org.elasticsearch.plugins.AbstractPlugin package org.elasticsearch.plugin.helloworld; import java.util.ArrayList; import java.util.Collection; import java.util.

  • 基于Lucene的Java搜索服务器Elasticsearch安装使用教程

    一.安装Elasticsearch Elasticsearch下载地址:http://www.elasticsearch.org/download/ ·下载后直接解压,进入目录下的bin,在cmd下运行elasticsearch.bat 即可启动Elasticsearch ·用浏览器访问: http://localhost:9200/   ,如果出现类似如下结果则说明安装成功: { "name" : "Benedict Kine", "cluster_na

  • spring 操作elasticsearch查询使用方法

    最近学习了一下elasticsearch使用,网上的资料又很少,真是一个头两个大.好歹最后终于了解了.留个笔记做日后查询. package com.gooddeep.dev.elasticsearch.commons.dao; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.elasticsearch.action.ActionFuture; import org.elasti

随机推荐