這裏採起調小ES佔用的內存: 默認配置以下圖,初始化和最大內存大小爲2Gjava
調節爲1gnode
以後再運行bin/elasticsearch.bat文件就能夠正常啓動了.linux
以前一直是在Linux上使用的ES的1.4版本,在Linux上解壓就能用,今天嘗試使用ES的5.0.0版本.bootstrap
若是使用Linux的root用戶 對ES5.0 解壓運行 會報以下錯誤:java.lang.RuntimeException: can not run elasticsearch as root 錯誤是說運行ES不能以root用戶的身份vim
ES5以後就不容許用root用戶啓動了,若是是ES5.0如下的版本能夠參考此解決方式:http://blog.csdn.net/u010317005/article/details/52205825安全
[2017-11-16T23:06:39,263][ERROR][o.e.b.Bootstrap ] Exception java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:96) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:155) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:112) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.Command.main(Command.java:62) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73) [elasticsearch-5.0.0.jar:5.0.0] [2017-11-16T23:06:39,328][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:116) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) ~[elasticsearch-5.0.0.jar:5.0.0]
這是出於系統安全考慮設置的條件。因爲ElasticSearch能夠接收用戶輸入的腳本而且執行,爲了系統安全考慮,建議建立一個單獨的用戶用來運行ElasticSearch.less
建立elsearch用戶組及elsearch用戶jvm
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
更改elasticsearch文件夾及內部文件的所屬用戶及組爲elsearch:elsearchelasticsearch
chown -R elsearch:elsearch elasticsearch-5.0.0
切換到elsearch用戶再啓動(有可能仍是會報錯,可能的報錯以及解決方式見下文)ui
su elsearch #切換帳戶 cd elasticsearch/bin #進入你的elasticsearch目錄下的bin目錄 ./elasticsearch
[2017-11-16T23:17:07,043][WARN ][o.e.b.JNANatives ] unable to install syscall filter: java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.JNANatives.trySeccomp(JNANatives.java:215) [elasticsearch-5.0.0.jar:5.0.0]
報了一大串錯誤,其實就是一個警告信息. 使用新的Linux版本就不會出現此問題了. 不用理會....
[2017-11-16T23:20:30,812][ERROR][o.e.b.Bootstrap ] [m2M7ykG] node validation exception bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] max number of threads [1024] for user [elsearch] likely too low, increase to at least [2048] max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] [2017-11-16T23:20:30,815][INFO ][o.e.n.Node ] [m2M7ykG] stopping ... [2017-11-16T23:20:30,852][INFO ][o.e.n.Node ] [m2M7ykG] stopped [2017-11-16T23:20:30,852][INFO ][o.e.n.Node ] [m2M7ykG] closing ... [2017-11-16T23:20:30,886][INFO ][o.e.n.Node ] [m2M7ykG] closed
添加以下內容: (soft nproc和hard nproc也能夠設置成65536)
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
以上幾個參數的解釋
① soft nproc:可打開的文件描述符的最大數(軟限制)
② hard nproc:可打開的文件描述符的最大數(硬限制)
③ soft nofile:單個用戶可用的最大進程數量(軟限制)
④ hard nofile:單個用戶可用的最大進程數量(硬限制)
這個命令也必須使用root用戶,
使用非root用戶報錯:
咱們須要編輯其中的 elasticsearch.yml 這一文件,使用命令 vim elasticsearch.yml
修改network.host和discovery.zen.ping.unicast.hosts的IP,改爲當前ip地址(經過 ifconfig 命令查看)。若是不修改,則只能本地訪問(localhost或127.0.0.1)
以上修改就能夠遠程訪問該ES的Web服務.
ElasticSearch後臺啓動命令
./elasticsearch -d
查看後臺命令是否啓動成功
ps aux|grep elasticsearch elsearch 3119 4.6 3.2 3535488 250876 pts/1 Sl 16:50 0:09 /opt/java/jdk1.7.0_75/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/home/py-project/elasticsearc-2.4.0 -cp /home/py-project/elasticsearch-2.4.0/lib/elasticsearch-2.4.0.jar:/home/py-project/elasticsearch-2.4.0/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d elsearch 3254 0.0 0.0 110224 916 pts/1 S+ 16:54 0:00 grep --color=auto elasticsearch