软件下载地址:https://pan.baidu.com/s/13gX0ParcOMO_XYcdfSPlzg 提取码:9y0e
安装的时候注意jdk和elasticsearch版本问题,本次测试版本:java 14,elasticsearch 7.6.0
elasticsearch安装需要依赖java环境,所以首先配置java环境变量: http://www.jiajiajia.club/blog/artical/yjw520/21
将elasticsearch的安装包上传到linux系统,我放在了 /usr/local 文件夹下。解压
进入elasticsearch的安装目录:/usr/local/elasticsearch-7.6.0/
执行运行命令:
./bin/elasticsearch
如果报错如下:
error:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000600000000, 8589934592, 0) failed; error='Not enough space' (errno=12)
说明你服务器的内存不够,修改配置文件:
注意(下面所有的修改配置文件均在root用户下进行)
vim ./config/jvm.options
将相应的配置修改为如下(根据自己的服务器大小来):
-Xms512m
-Xmx512m
修改完成后再次启动报错:
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)
这是权限问题,elasticsearch不能再root用户下启动,所以需要添加es用户,赋予相应的权限,再es用户下启动。
添加es用户,用es用户启动
useradd es
passwd es
chown -R es:es /usr/local/elasticsearch-7.6.0
su es
./bin/elasticsearch
如果没问题的话,启动成功,在另一个连接终端下执行:curl -X GET http://localhost:9200,会出现如下代码:
{
"name" : "192.168.202.128",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "B-eVRGgOQFe7QgKgqHpQHA",
"version" : {
"number" : "7.6.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
"build_date" : "2020-02-06T00:09:00.449973Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
解决外网不可访问问题:
前提是防火墙将 9200端口放开
修改配置文件:
vim ./config/elasticsearch.yml
末尾添加:
network.host: 0.0.0.0
修改上述配置文件后启动报错:
错误1
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
修改
vim /etc/security/limits.conf
#添加:
* soft nofile 65536
* hard nofile 65536
#此文件修改后需要重新登录
错误2
ERROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改:
vim /etc/sysctl.conf
#末尾添加:
vm.max_map_count=655360
#保存执行如下命令:
sysctl -p
错误3
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
修改:
vim ./config/elasticsearch.yml
追加:
cluster.initial_master_nodes: ["node-1"]
开放端口后外网访问:http://192.168.202.128:9200/
{
"name" : "192.168.202.128",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "B-eVRGgOQFe7QgKgqHpQHA",
"version" : {
"number" : "7.6.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
"build_date" : "2020-02-06T00:09:00.449973Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}