ElasticSearch(以下簡(jiǎn)稱es) 是一款基于lucene的分布式全文搜索引擎服務(wù)器惕稻,它提供實(shí)時(shí)搜索,穩(wěn)定蝙叛,快速可靠等優(yōu)勢(shì)俺祠。下面基于centos7環(huán)境下安裝部署es。
- 查看linux環(huán)境下是否安裝jdk(es啟動(dòng)必須java8以上環(huán)境),如果出現(xiàn)如下表示未安裝jdk請(qǐng)先安裝
[root@Eden666 ~]# java -version
-bash: java: command not found
- 若wget 下載下來解壓不了出現(xiàn)以下錯(cuò)誤借帘,是因?yàn)槲覀兿螺djdk時(shí)有Accept License Agreement選項(xiàng)需要勾選锻煌,解決辦法先下載下來再通過sftp上傳解壓,我這邊解壓放在/opt/soft文件夾下姻蚓。
[root@Eden666 ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz
[root@Eden666 ~]# tar -zxvf jdk-8u191-linux-x64.tar.gz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
- 配置jdk環(huán)境:在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL這行下加入jdk環(huán)境配置宋梧,
[root@Eden666 ~]# vi /etc/profile
export JAVA_HOME=/opt/soft/jdk1.8.0_191
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@Eden666 ~]# java -version
-bash: java: command not found
[root@Eden666 ~]# source /etc/profile //刷新配置
[root@Eden666 ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
[root@Eden666 soft]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.0.tar.gz
[root@Eden666 soft]# mv elasticsearch-6.5.0.tar.gz elasticsearch-6.5.0
[root@Eden666 soft]# ls
elasticsearch-6.5.0 jdk1.8.0_191
[root@Eden666 soft]# tar -zxvf elasticsearch-6.5.0
- 啟動(dòng)es,若出現(xiàn)以下不能分配內(nèi)存情況狰挡,則需修改es的config捂龄,重新啟動(dòng)
[root@Eden666 elasticsearch-6.5.0]# ./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid1307.log
[root@Eden666 elasticsearch-6.5.0]# vi config/jvm.options
-Xms1g //我這邊JVM堆最大和初始化內(nèi)存改成 512m
-Xmx1g
- 啟動(dòng)之后若出現(xiàn)如下情況释涛,是因?yàn)殚_啟es服務(wù)器不能使用root用戶,需要新建用戶,并且賦予用戶執(zhí)行權(quán)限
[root@Eden666 elasticsearch-6.5.0]# ./bin/elasticsearch
[2018-11-15T14:58:45,626][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.0.jar:6.5.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.0.jar:6.5.0]
... 6 more
[root@Eden666 elasticsearch-6.5.0]# useradd esuser
[root@Eden666 elasticsearch-6.5.0]# passwd esuser
Changing password for user esuser.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Eden666 elasticsearch-6.5.0]# chown -R esuser:esuser /opt/soft/
[root@Eden666 elasticsearch-6.5.0]# su esuser
[esuser@Eden666 elasticsearch-6.5.0]$ ./bin/elasticsearch
- 查看啟動(dòng)日志看是否報(bào)錯(cuò)倦沧,若沒有報(bào)錯(cuò)唇撬,curl get請(qǐng)求返回正常說明啟動(dòng)成功
[root@Eden666 ~]# curl localhost:9200
{
"name" : "5MLXu98",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "I4nrxsMLR-KNRcZZnhHpIQ",
"version" : {
"number" : "6.5.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "816e6f6",
"build_date" : "2018-11-09T18:58:36.352602Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}