详解centos7虚拟机安装elasticsearch5.0.x-安装篇
centos7虚拟机安装elasticsearch5.0.x-安装篇
请预先安装jdk详细步骤请参考:https://www.nhooo.com/softjc/193398.html
创建新用户(非root用户)
elasticsearch只能用非root启动,这里我创建了一个叫seven的用户
[root@localhost~]#useraddseven [root@localhost~]#passwdseven
下载elasticsearch
[root@localhost~]#suseven [seven@localhostroot]$cd/home/seven [seven@localhost~]$mkdirdownload [seven@localhost~]$cddownload [seven@localhostdownload]$wgethttps://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha3/elasticsearch-5.0.0-alpha3.tar.gz
解压并运行elasticsearch
解压
[seven@localhostdownload]$tar-zxvfelasticsearch-5.0.0-alpha3.tar.gz
移动到指定文件夹并重命名(方便管理)
[seven@localhostdownload]$mvelasticsearch-5.0.0-alpha3/usr/java/elasticsearch
修改访问elasticsearch的IP及端口
[seven@localhostconfig]$vim/usr/java/elasticsearch/config/elasticsearch.yml
找到如下代码段,并取消network.host及http.port所在行的注释,修改IP及端口
#----------------------------------Network----------------------------------- # #SetthebindaddresstoaspecificIP(IPv4orIPv6): # network.host:192.168.0.155 # #SetacustomportforHTTP: # http.port:9200 # #Formoreinformation,seethedocumentationat: #<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
直接运行bin/elasticsearch文件启动elasticsearch
[seven@localhostbin]$cd/usr/java/elasticsearch/bin/ [seven@localhostbin]$./elasticsearch
启动时发现报错了。。。
[seven@localhostbin]$./elasticsearch [2016-06-2813: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[OracleCorporation/JavaHotSpot(TM)64-BitServerVM/1.0_91/25.91-b14] ▽2016-06-2813:49:27,900][INFO][node][Mondo]initializing... [2016-06-2813:49:28,941][INFO][plugins][Mondo]modules[percolator,lang-mustache,lang-painless,ingest-grok,reindex,lang-expression,lang-groovy],plugins[] [2016-06-2813:49:28,963][INFO][env][Mondo]using[1]datapaths,mounts[[/(rootfs)]],netusable_space[15.7gb],nettotal_space[17.4gb],spins?[unknown],types[rootfs] [2016-06-2813:49:28,963][INFO][env][Mondo]heapsize[1.9gb],compressedordinaryobjectpointers[true] [2016-06-2813:49:31,980][INFO][node][Mondo]initialized [2016-06-2813:49:31,980][INFO][node][Mondo]starting... [2016-06-2813:49:32,115][INFO][transport][Mondo]publish_address{192.168.0.155:9300},bound_addresses{192.168.0.155:9300} Exceptioninthread"main"java.lang.RuntimeException:bootstrapchecksfailed initialheapsize[268435456]notequaltomaximumheapsize[2147483648];thiscancauseresizepausesandpreventsmlockallfromlockingtheentireheap maxfiledescriptors[4096]forelasticsearchprocesslikelytoolow,increasetoatleast[65536] pleaseset[discovery.zen.minimum_master_nodes]toamajorityofthenumberofmastereligiblenodesinyourcluster maxvirtualmemoryareasvm.max_map_count[65530]likelytoolow,increasetoatleast[262144] atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125) atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85) atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65) atorg.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183) atorg.elasticsearch.node.Node.start(Node.java:337) atorg.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198) atorg.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257) atorg.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96) atorg.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91) atorg.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) atorg.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91) atorg.elasticsearch.cli.Command.main(Command.java:53) atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70) atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63) Refertothelogforcompleteerrordetails. [2016-06-2813:49:32,144][INFO][node][Mondo]stopping... [2016-06-2813:49:32,198][INFO][node][Mondo]stopped [2016-06-2813:49:32,198][INFO][node][Mondo]closing... [2016-06-2813:49:32,210][INFO][node][Mondo]closed
于是我临时提高了vm.max_map_count的大小
*此操作需要root权限
[root@localhost~]#sysctl-wvm.max_map_count=262144
查看修改结果
[root@localhost~]#sysctl-a|grepvm.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 #Systemdefaultsettingslivein/usr/lib/sysctl.d/00-system.conf. #Tooverridethosesettings,enternewsettingshere,orinan/etc/sysctl.d/<name>.conffile # #Formoreinformation,seesysctl.conf(5)andsysctl.d(5). vm.max_map_count=262144 [root@localhost~]#sysctl-p vm.max_map_count=262144
上面还有一个错误是关于jvm内存分配的问题heapsize[268435456]notequaltomaximumheapsize[2147483648],需要修改的jvm配置
[seven@localhostbin]$vim/usr/java/elasticsearch/config/jvm.options
将-Xmx2g改成-Xmx256m,也就是heapsize[268435456]/1024/1024的值
又有新的错误。。。
Exceptioninthread"main"java.lang.RuntimeException:bootstrapchecksfailed initialheapsize[268435456]notequaltomaximumheapsize[2147483648];thiscancauseresizepausesandpreventsmlockallfromlockingtheentireheap maxfiledescriptors[4096]forelasticsearchprocesslikelytoolow,increasetoatleast[65536] memorylockingrequestedforelasticsearchprocessbutmemoryisnotlocked atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125) atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85) atorg.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65) atorg.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183) atorg.elasticsearch.node.Node.start(Node.java:337) atorg.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198) atorg.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257) atorg.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96) atorg.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91) atorg.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) atorg.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91) atorg.elasticsearch.cli.Command.main(Command.java:53) atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70) atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63) Refertothelogforcompleteerrordetails. [2016-06-2814:55:49,770][INFO][node][Goldbug]stopping... [2016-06-2814:55:49,875][INFO][node][Goldbug]stopped [2016-06-2814:55:49,875][INFO][node][Goldbug]closing... [2016-06-2814:55:49,887][INFO][node][Goldbug]closed
这个问题折腾了我一下午,最后还是找到了解决方案,同样回到config/elasticsearch.yml文件,找到如下配置,开放discovery.zen.ping.unicast.hosts及discovery.zen.minimum_master_nodes
#---------------------------------Discovery---------------------------------- # #Passaninitiallistofhoststoperformdiscoverywhennewnodeisstarted: #Thedefaultlistofhostsis["127.0.0.1","[::1]"] # discovery.zen.ping.unicast.hosts:["192.168.0.155"] # #Preventthe"splitbrain"byconfiguringthemajorityofnodes(totalnumberofnodes/2+1): # discovery.zen.minimum_master_nodes:3 # #Formoreinformation,seethedocumentationat: #<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
然后修改maxfiledescriptors[4096]forelasticsearchprocesslikelytoolow,increasetoatleast[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"sevenhardnofile65536">>/tmp/system_limits.conf [root@localhost~]#echo"sevensoftnofile65536">>/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":"VampirebyNight", "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":"YouKnow,forSearch" }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。