Elasticsearch 与 JDK 版本对应关系

在安装 Elasticsearch 时,要注意 JDK 对应的版本,另外 Elasticsearch 7.x 以上已经内置 JDK 环境配置,不需要本地 JDK 环境支持。

  1. Elasticsearch 5.x 安装需要 JDK8 及以上
  2. Elasticsearch 6.5 安装需要 JDK11 及以上
  3. Elasticsearch 7.2.x 内置了JDK12

这里有一张非常详尽的 ElasticsearchJDK 版对应关系表格。

手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_elasticsearch

Elasticsearch 7.6 安装

下载

cd /home/software
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz

解压

tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz

笔者的 Elasticsearch 最终安装路径为:/home/software/data/elasticsearch-7.6.2

注意 Elasticsearch7.6 已经内置了JDK,所以机器不需要本地 JDK 环境支持,如果服务器有本地 JDK ,尽量保持和 Elasticsearch 版本匹配的 JDK 版本。

启动

启动时,官方禁止使用 root 用户启动 Elasticsearch,否则会报错!

java.lang.RuntimeException: can not run elasticsearch as root
手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_elastic_02

如果非得使用 root 用户启动,当然也是可以的,但是只能针对 Elasticsearch5 之前的版本。

./elasticsearch -Des.insecure.allow.root=true

Elasticsearch5 之后,Elasticsearch 官方明确禁止用 root 用户启动 Elasticsearch 了,所以我们需要单独为 Elasticsearch 建立系统用户。

#创建用户
adduser espuxin
passwd 123456

#切换 Elasticsearch 用户 espuxin
su espuxin

#启动 Elasticsearch
./elastcsearch

错误汇总

1、 java.nio.file.AccessDeniedException: /home/software/data/elasticsearch-7.6.2/config/jvm.options 错误

手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_linux_03

报这个错就是因为启动 Elasticsearch 的账户权限不足,所以在启动 ElasticSearch 之前,需要给 espuxin 用户赋予对应的执行权限。

具体做法是把用户切换到 root 用户,把 ElasticSearch 的安装目录执行权限赋予给 espuxin 用户。

例如:

chown -R esadmin:esadmin /home/software/data/elasticsearch-7.6.2

再次启动 Elasticsearch,启动正常。

2、 Linux下启动 Elasticsearch 报错 BindTransportException [Failed to bind to [9300-9400]

这个错误需要配置外网可访问,用 vi 打开 /home/esadmin/es/elasticsearch-7.6.2/config/elasticsearch.yml 文件,把 network.host 参数配置成 0.0.0.0

# Set the bind address to a specific IP (IPv4 or IPv6):
network.host: 0.0.0.0

3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 错误

ERROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /home/esadmin/es/elasticsearch-7.6.2/logs/elasticsearch.log

切换到 root用户,在 /etc/sysctl.conf 文件添加 vm.max_map_count 参数值为 262144

su root
echo "vm.max_map_count=262144" > /etc/sysctl.conf

sysctl -p 查看是否生效。

手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_ide_04

4、bootstrap checks failed 错误

ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /home/esadmin/es/elasticsearch-7.6.2/logs/elasticsearch.log

打开 /home/software/data/elasticsearch-7.6.2/config/elasticsearch.yml 文件, 把 cluster.namenode.nameinitial_master_nodes 参数设置默认值。

cluster.name: wooola-es
node.name: node-1
cluster.initial_master_nodes: ["node-1"]

再次启动后,在浏览器中输入:http://192.144.254.238:9200/手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_ide_05

至此,Elasticsearch 成功安装完毕。

Elasticsearch 后台访问

需要使用在启动命令 ./elasticsearch 后加上 -d 参数,这时执行的时候会出现没有权限,

./elasticsearch: Permission denied

需要授权执行命令:

chmod +x bin/elasticsearch

最后为了数据安全访问,需要对 Elasticsearch 进行密码设置,账号为 elastic。

手把手教你在CentOS 7上 安装 Elasticsearch 7.6,必须收藏!!!_elastic_06