ElasticSearch 单实例安装
- 一、安装到CentOS7
- 二、遇到的问题
- 1、`org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root`
- 2、`max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]`
- 3、`max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]`
- 4、启动成功后,局域网内不能访问
一、安装到CentOS7
1、安装JDK,至少1.8.0_73以上版本
安装jdk这里略过
2、下载Elasticsearch安装包
https://www.elastic.co/downloads
我这里下载的是 Version: 6.5.4 ,也可以通过Rmp方式安装
3、通过工具上传安装包
将下载好的压缩包 elasticsearch-6.5.4 .tar.gz 上传到自己规划的目录 。
我这里是上传到 usr/local/
4、在当前目录下解压安装包
tar -xvf elasticsearch-6.5.4 .tar.gz
得到elasticsearch-6.5.4目录
5、启动Elasticsearch
es本身特点之一就是开箱即用,如果是中小型应用,数据量少,操作不是很复杂,直接启动就可以使用。
进到到bin目录
cd /usr/local/elasticsearch-6.5.4/bin
当前启动
./elasticsearch
6、检查ES是否启动成功
访问服务器ip:9200 ,得到如下结果,表示启动成功了
二、遇到的问题
1、org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
解决方案:
elasticsearch 为了安全是不允许root账号启动的,因此切换到其他用户启动
命令:
su xxxx
回车 xxxx是用户名,然后输入登录用户的密码
2、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
问题翻译过来就是:elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536;
解决办法:
-
切换到root用户修改
vim /etc/security/limits.conf
-
在最后面追加下面内容
xxx hard nofile 65536
xxx soft nofile 65536
xxx 是启动ES的用户
3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;
解决方法:
-
切换到root用户
-
执行命令:
sysctl -w vm.max_map_count=262144 -
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144 -
上述方法修改之后,如果重启虚拟机将失效,所以: 解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
4、启动成功后,局域网内不能访问
1.启动成功后,在虚拟机内部使用 curl 命令 curl ip:port 发现端口是通的
但在局域网内其他电脑上访问此端口不通。
解决方案:
-
开放防火墙9200 端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload -
修改es配置文件 elasticsearch.yml
进入到es安装目录
vim config/elasticsearch.yml
增加:network.host: 0.0.0.0
保存重启elasticsearch