一、Elasticsearch 簡介
下面摘自官網(wǎng)
Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data so you can discover the expected and uncover the unexpected.
(Elasticsearch是一種分布式,REST風(fēng)格的搜索和分析引擎唯咬,能夠解決越來越多的用例喊括。 作為彈性堆棧的核心漩蟆,它集中存儲您的數(shù)據(jù)声滥,以便您可以發(fā)現(xiàn)預(yù)期并發(fā)現(xiàn)意外卧蜓。)
二帐要、Elasticsearch 安裝
安裝前準(zhǔn)備
- 安裝最新版 JDK ,本人測試環(huán)境是JDK 1.8.0_112弥奸,官方說 JDK 1.7 + 即可
- 下載 Elasticsearch 最新安裝包榨惠。
安裝Elasticsearch
-
解壓安裝包
$ cd /opt/es $ tar zxvf elasticsearch-5.5.0.tar.gz
-
修改 Elasticsearch 相關(guān)參數(shù)
vi /opt/es/elasticsearch-5.5.0/config/elasticsearch.yml
修改如下內(nèi)容:
# 集群的名字
cluster.name: elasticsearch# 節(jié)點(diǎn)名字
node.name: node-1# 索引分片個(gè)數(shù),默認(rèn)為5片
index.number_of_shards: 5# 索引副本個(gè)數(shù)盛霎,默認(rèn)為1個(gè)副本
index.number_of_replicas: 1# 數(shù)據(jù)存儲目錄(多個(gè)路徑用逗號分隔)
path.data: /home/ntc/es/data# 日志目錄
path.logs: /home/ntc/es/logs# 修改一下ES的監(jiān)聽地址赠橙,這樣別的機(jī)器才可以訪問
network.host: 172.16.X.X# 設(shè)置節(jié)點(diǎn)間交互的tcp端口(集群),默認(rèn)是9300
transport.tcp.port: 9300# 監(jiān)聽端口(默認(rèn)的就好)
http.port: 9200# 增加新的參數(shù),這樣head插件才可以訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"
-
啟動Elasticsearch
$ cd elasticsearch-5.5.0 $ ./bin/elasticsearch
此時(shí)由于是用root用戶啟動的愤炸,所以會報(bào)如下錯(cuò)誤期揪。
[2017-07-11T12:10:33,262][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:127) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.0.jar:5.5.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.0.jar:5.5.0]
... 6 more
解決方案有兩種:
-
直接修改Elasticsearch配置,支持用root啟動摇幻。
因?yàn)槲打?yàn)證横侦,后續(xù)補(bǔ)充
-
出于系統(tǒng)安全考慮,建議新建單獨(dú)的用戶運(yùn)行 Elasticsearch绰姻。
(1) 創(chuàng)建用戶組和用戶
$ groupadd esgroup $ useradd es -g esgroup
(2) 修改 Elasticsearch 文件夾及內(nèi)部所有文件的所屬用戶組和用戶(注意用戶和用戶組的順序)枉侧。
$ chown -R es:esgroup /opt/es/elasticsearch-5.5.0
(3) 切換到es用戶,并啟動Elasticsearch
$ su - es [es@localhost ~]$ cd /opt/es/elasticsearch-5.5.0 [es@localhost elasticsearch-5.5.0]$ ./bin/elasticsearch
(4) 啟動后狂芋,輸出如下信息榨馁,啟動成功
[2017-07-11T12:48:13,611][INFO ][o.e.n.Node ] initialized [2017-07-11T12:48:13,611][INFO ][o.e.n.Node ] [zzZc25X] starting ... [2017-07-11T12:48:13,878][INFO ][o.e.t.TransportService ] [zzZc25X] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} [2017-07-11T12:48:13,898][WARN ][o.e.b.BootstrapChecks ] [zzZc25X] max number of threads [1024] for user [es] is too low, increase to at least [2048] [2017-07-11T12:48:13,899][WARN ][o.e.b.BootstrapChecks ] [zzZc25X] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [2017-07-11T12:48:13,899][WARN ][o.e.b.BootstrapChecks ] [zzZc25X] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk [2017-07-11T12:48:17,005][INFO ][o.e.c.s.ClusterService ] [zzZc25X] new_master {zzZc25X}{zzZc25XOTdacyXbQyrqhMw}{ajlhWEWxTZyitnVUy-OFHQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2017-07-11T12:48:17,056][INFO ][o.e.h.n.Netty4HttpServerTransport] [zzZc25X] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} [2017-07-11T12:48:17,058][INFO ][o.e.n.Node ] [zzZc25X] started [2017-07-11T12:48:17,321][INFO ][o.e.g.GatewayService ] [zzZc25X] recovered [0] indices into cluster_state
三、驗(yàn)證 Elasticsearch 啟動狀態(tài)
-
瀏覽器直接訪問地址查看狀態(tài)
輸入地址:
http://172.16.X.X:9200/
輸出結(jié)果:
{ "name" : "zzZc25X", "cluster_name" : "elasticsearch", "cluster_uuid" : "m52p74pBSIeX-Le50BM_qQ", "version" : { "number" : "5.5.0", "build_hash" : "260387d", "build_date" : "2017-06-30T23:16:05.735Z", "build_snapshot" : false, "lucene_version" : "6.6.0" }, "tagline" : "You Know, for Search" }
-
命令查看狀態(tài)
輸入命令:
[es@localhost elasticsearch-5.5.0]$ ps -ef | grep elastic
輸出結(jié)果:
es 26430 26272 16 12:59 pts/1 00:00:22 /opt/jdk1.8.0_112/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/opt/es/elasticsearch-5.5.0 -cp /opt/es/elasticsearch-5.5.0/lib/* org.elasticsearch.bootstrap.Elasticsearch
四帜矾、Elasticsearch 后臺啟動及關(guān)閉
-
Elasticsearch后臺啟動
通過./bin/elasticsearch 啟動服務(wù)翼虫,按 ctrl+c 的時(shí)候程序就會stop掉比較尷尬,所以需要后臺啟動程序屡萤。 首先授權(quán)執(zhí)行命令: chmod +x ./bin/elasticsearch 再次執(zhí)行后臺啟動命令: ./bin/elasticsearch -d
-
通過上一步查看到的 Elasticsearch 狀態(tài)中的端口珍剑,執(zhí)行下面命令殺死 Elasticsearch 進(jìn)程
[es@localhost elasticsearch-5.5.0]$ kill -9 26430
五、安裝過程中的一些其他問題
- 啟動時(shí)會有這么一個(gè)警告死陆,不影響使用招拙,網(wǎng)上查詢說使用最新linux版本就可以了。
[2017-07-11T13:13:08,465][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.SystemCallFilter.linuxImpl(SystemCallFilter.java:350) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:638) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:215) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:99) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.5.0.jar:5.5.0]
-
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解決方案:切換到root用戶措译,編輯 limits.conf 添加下面內(nèi)容
vi /etc/security/limits.conf
添加如下內(nèi)容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
-
max number of threads [1024] for user [es] is too low, increase to at least [2048]
解決方案:切換到root用戶别凤,進(jìn)入limits.d目錄下修改配置文件。
修改如下內(nèi)容:
* soft nproc 1024
#修改為
* soft nproc 2048
-
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方案:切換到root用戶修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并執(zhí)行命令:
sysctl -p
-
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因: CentOS6.X 不支持SecComp领虹,而ES5.2.0默認(rèn)bootstrap.system_call_filter為true進(jìn)行檢測规哪,所以導(dǎo)致檢測失敗,失敗后直接導(dǎo)致ES不能啟動塌衰。
解決方案:修改/opt/es/elasticsearch-5.5.0/config/elasticsearch.yml中配置
vi /opt/es/elasticsearch-5.5.0/config/elasticsearch.yml
修改如下配置
#bootstrap.memory_lock: true
#修改為
bootstrap.memory_lock: false
bootstrap.system_call_filter: false