ElasticSearch(以下简称es) 是一款基于lucene的分布式全文搜索引擎服务器,它提供实时搜索,稳定,快速可靠等优势。下面基于centos7环境下安装部署es。
- 查看linux环境下是否安装jdk(es启动必须java8以上环境),如果出现如下表示未安装jdk请先安装
[root@Eden666 ~]# java -version
-bash: java: command not found
- 若wget 下载下来解压不了出现以下错误,是因为我们下载jdk时有Accept License Agreement选项需要勾选,解决办法先下载下来再通过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环境:在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL这行下加入jdk环境配置,
[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
- 启动es,若出现以下不能分配内存情况,则需修改es的config,重新启动
[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堆最大和初始化内存改成 512m
-Xmx1g
- 启动之后若出现如下情况,是因为开启es服务器不能使用root用户,需要新建用户,并且赋予用户执行权限
[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
- 查看启动日志看是否报错,若没有报错,curl get请求返回正常说明启动成功
[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"
}