1.服务器创建es用户
useradd es
passwd es
2.elasticsearch部署环境JDK
3.安装包
可以去elastic官网下载相应版本文件。我这里安装版本的是7.12.0。
Linux版本:
//centos下若没有安装curl
yum install curl
//进入es用户目录执行下载
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz
解压下载的压缩文件
tar -xzvf elasticsearch-7.12.0-linux-x86_64.tar.gz
启动elasticsearch
cd elasticsearch-7.12.0/bin/
./elasticsearch &
访问elasticsearch
curl http://127.0.0.1:9200
//返回信息
{
"name" : "izwz9ja3exxb7by25st5gbz",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "hD8cxBoIRvW6tZUEIFMTUQ",
"version" : {
"number" : "7.12.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a",
"build_date" : "2021-03-18T06:17:15.410153305Z",
"build_snapshot" : false,
"lucene_version" : "8.8.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
集群启动:
修改配置文件
vim elasticsearch.yml
//配置集群名称
cluster.name: elasticsearch
//配置节点名称
node.name: node-1
//配置数据存放路径
path.data: /path/to/data
//配置日志存放路径
path.logs: /path/to/logs
//配置访问地址 所有机器可访问 则配置为0.0.0.0
network.host: 0.0.0.0
//配置访问端口
http.port: 9200
//配置集群扫描地址
discovery.seed_hosts: ["172.18.88.96", "127.0.0.1"]
//配置集群节点主节点竞选的节点
cluster.initial_master_nodes: ["node-1", "node-2"]
启动集群节点
./elasticsearch -Epath.data=data1 -Epath.logs=log1 -Enode.name=node-1 -d
./elasticsearch -Epath.data=data2 -Epath.logs=log2 -Enode.name=node-2 -d
./elasticsearch -Epath.data=data3 -Epath.logs=log3 -Enode.name=node-3 -d
查看集群健康信息:
curl http://localhost:9200/_cluster/health
curl http://localhost:9200/_cat/health?v=true
查看节点列表
curl http://localhost:9200/_cat/nodes
查看节点信息
curl http://localhost:9200/_nodes/transport?pretty
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
warning: ignoring JAVA_OPTS= -Djava.security.egd=file:/dev/./urandom; pass JVM parameters via ES_JAVA_OPTS
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_171/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
warning: ignoring JAVA_OPTS= -Djava.security.egd=file:/dev/./urandom; pass JVM parameters via ES_JAVA_OPTS
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_171/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
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_pid27324.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.JvmOption.flagsFinal(JvmOption.java:119)
at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
解决方法:
修改config目录下的配置文件jvm.options
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# 按自己机器内存情况配置
-Xms128m
-Xmx128m
[2021-04-09T10:26:01,627][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [izwz9ja3exxb7by25st5gbz] 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.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.12.0.jar:7.12.0]
at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.12.0.jar:7.12.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397) ~[elasticsearch-7.12.0.jar:7.12.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.12.0.jar:7.12.0]
... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
at org.elasticsearch.cli.Command.main(Command.java:79)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
For complete error details, refer to the log at /root/elasticsearch-7.12.0/logs/elasticsearch.log
解决方法:
创建es用户
创建es 用户
useradd es
创建es用户密码 changeme
passwd es
分配es用户 安装文件夹权限
chown -R es elasticsearch-7.12.0
切换到es 用户
su es
启动报错“Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker”
解决方法:因为elasticsearch目录在root下面,将elasticsearch安装文件拷贝到es用户目录下
启动报错“AccessDeniedException[/home/es/elasticsearch-7.12.0/config/elasticsearch.yml]”
解决方法:因为elasticsearch目录没有权限,读取不到配置文件,授权操作一下
chown -R es elasticsearch-7.12.0
解决方法:
修改配置文件
vim /etc/sysctl.conf
在文件最后加上
vm.max_map_count=262144
保存文件后 刷新文件生效
sysctl -p