欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

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

程序员文章站 2023-11-16 11:01:40
centos7虚拟机安装elasticsearch5.0.x-安装篇 请预先安装jdk详细步骤请参考: 创建新用户(非root用户) elasticsearch只...

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

请预先安装jdk详细步骤请参考:

创建新用户(非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"
}

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