Elasticsearch安装

目录

  • 下载安装包
  • 问题1内存太小
    • 解决办法
  • 问题2java版本
    • 解决办法
  • 问题3 回收资源限制
    • 解决办法
  • 问题4不能以root启动
    • 解决办法
  • 获取信息,表示安装成功
  • 查看与安装插件
  • 在命令行中查看
  • 本机多实例ElasticSearch 运行
  • 删除进程

下载安装包

进入下载页面,https://www.elastic.co/downloads/elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-linux-x86_64.tar.gz
tar xf elasticsearch-7.3.1-linux-x86_64.tar.gz
mv elasticsearch-7.3.1 elasticsearch
cd elasticsearch/

问题1内存太小

[root@centos7-zk1 elasticsearch]# bin/elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/soft/jdk1.8.0_201/jre] does not meet this requirement
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# 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_pid7878.log
error:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
    at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:111)
    at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:79)
    at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:57)
    at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:89)

解决办法

加内存

问题2java版本

[root@centos7-zk1 elasticsearch]# bin/elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/soft/jdk1.8.0_201/jre] does not meet this requirement
[2019-09-08T11:11:20,849][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [centos7-zk1] 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:163) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.3.1.jar:7.3.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.3.1.jar:7.3.1]
    ... 6 more

解决办法

wget https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz
tar xf openjdk-11.0.1_linux-x64_bin.tar.gz /opt
cd /opt
mv jdk-11.0.1/ jdk

修改/opt/elasticsearch/bin/elasticsearch-env

export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH

问题3 回收资源限制

[root@centos7-zk1 elasticsearch]# bin/elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-09-08T11:24:39,384][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [centos7-zk1] 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:163) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.3.1.jar:7.3.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.3.1.jar:7.3.1]
    ... 6 more

解决办法

修改/opt/elasticsearch/config/jvm.options


##GC configuration
##原有的注释了,添加了G1回收器
##-XX:+UseConcMarkSweepGC
-XX:+UseG1GC

问题4不能以root启动

[root@centos7-zk1 elasticsearch]# bin/elasticsearch
[2019-09-08T11:49:19,758][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [centos7-zk1] 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:163) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.3.1.jar:7.3.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.3.1.jar:7.3.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.3.1.jar:7.3.1]
    ... 6 more

解决办法

处于对root用户的安全保护,需要使用其他用户组进行授权启动

useradd es 
chown -R es:es  /opt/elasticsearch

备注: 添加用户组 elsearch
添加用户 elsearch 密码为 elasticsearch 到用户组 elsearch
将elsearch安装目录授权给 用户组:用户 即 elsearch:elsearch

su es
/opt/elasticsearch/bin/elasticsearch

获取信息,表示安装成功

[root@centos7-zk1 config]# curl localhost:9200
{
  "name" : "centos7-zk1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "kci1lWhQSYODdYPtJdOJ3A",
  "version" : {
    "number" : "7.3.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "4749ba6",
    "build_date" : "2019-08-19T20:19:25.651794Z",
    "build_snapshot" : false,
    "lucene_version" : "8.1.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

查看与安装插件

/opt/elasticsearch/bin/elasticsearch-plugin list
[root@centos7-zk1 ~]# /opt/elasticsearch/bin/elasticsearch-plugin install analysis-icu
-> Downloading analysis-icu from elastic
[=================================================] 100%   
-> Installed analysis-icu先重新启动es
bin/elasticsearch 

在命令行中查看

[root@centos7-zk1 ~]# curl localhost:9200/_cat/plugins
centos7-zk1 analysis-icu 7.3.1

本机多实例ElasticSearch 运行

bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data -d 
bin/elasticsearch -E node.name=node1 -E cluster.name=geektime -E path.data=node1_data -d 
bin/elasticsearch -E node.name=node2 -E cluster.name=geektime -E path.data=node2_data -d 
bin/elasticsearch -E node.name=node3 -E cluster.name=geektime -E path.data=node3_data -d 

删除进程

ps -ef | grep elasticsearch 
kill pid

你可能感兴趣的:(Elasticsearch安装)