Centos7安装ElasticSearch6.5.4

因为ElasticSearch是基于Lucene的分布式搜索引擎,Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,所以需要先在你的环境中安装jre环境。具体可以参考这篇文章Centos7 安装和配置jre1.8

第一步,下载ElasticSearch

https://www.elastic.co/downloads/elasticsearch

第二步,上传到/home/data目录下

cd /home
mkdir data
cd data
rz

第三步,解压文件并移动到elasticsearch目录下

tar -zxvf elasticsearch-6.5.4.tar.gz 
cd ..
mkdir elasticsearch
mv /home/data/elasticsearch-6.5.4/ /home/elasticsearch/

第四步,启动elasticsearch

cd /home/elasticsearch/elasticsearch-6.5.4/bin
./elasticsearch

发现报错

表示不能使用root用户启动elasticsearch。我们需要创建一个用户来启动elasticsearch

groupadd esgroup
useradd esuser -g esgroup-p esuser

给elasticsearch目录授予esuser权限

 chown esuser:esgroup -R /home/elasticsearch/

现在切换esuser用户再次启动

su esuser
./elasticsearch

如果出现如下标志表示启动成功了

测试一下,9200是elasticsearch的默认端口

curl http://localhost:9200

现在配置远程访问

修改elasticsearch配置文件

 /home/elasticsearch/elasticsearch-6.5.4/config/elasticsearch.yml

network.host就是你的服务器的ip地址

在末尾添加

http.cors.enabled: true
http.cors.allow-origin: "*"

防火墙开放9200端口

firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

或者关闭防火墙

systemctl stop firewalld.service

systemctl disable firewalld.service   禁止防火墙开机启动

再次重启elasticsearch。

在Windows电脑的浏览器访问http://192.168.0.117:9200/

这就已经配置好了。

可能遇见的问题

max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

解决办法:

vi /etc/security/limits.conf 

在末尾添加,* 表示全部用户

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096

max number of threads [2048] for user [lishang] likely too low, increase to at least [4096]

解决办法:

vi /etc/security/limits.d/20-nproc.conf 

将如下内容

* soft nproc 2048

修改为

* soft nproc 4096

max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

解决办法:

vi /etc/sysctl.conf 

文件末尾添加

vm.max_map_count=655360

执行命令

sysctl -p

重启服务器

再次启动elasticsearch,发现可以正常启动了。

猜你喜欢

转载自blog.csdn.net/WYA1993/article/details/86227094
今日推荐