1. 下载安装包并解压
- 或直接在虚拟机中输入:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
- 解压
tar -zxvf elasticsearch-7.0.0-linux-x86_64.tar.gz
2. 配置
- 在文件末尾添加如下配置
[root@ywq5 ~]# vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
- 修改/etc/security/limits.d/20-nproc.conf
[root@ywq5 ~]# $sudo vim /etc/security/limits.d/90-nproc.conf
* soft nproc 4096
#将该条目修改成4096
- 在/etc/sysctl.conf文件末尾添加
vm.max_map_count=655360
- 然后
[root@ywq5 ~]# sysctl -p
- 进入Elasticsearch安装目录
[root@ywq5 ywq]# cd elasticsearch-5.6.2/
- 创建Elasticsearch数据文件夹data
[root@ywq5 ywq]# mkdir data
- 创建Elasticsearch日志文件夹log
[root@ywq5 ywq]# mkdir log
- 修改Elasticsearch配置文件
[root@ywq5 ywq]# vim /config/elasticsearch
cluster.name: es-cluster
#设置集群的名称
node.name: es-node
#修改当前节点的名称
path.data: /usr/ywq/elasticsearch-7.0.0/data
#修改数据路径
path.logs: /usr/ywq/elasticsearch-7.0.0/logs
#修改日志路径
bootstrap.memory_lock: false
#设置ES节点允许内存交换
bootstrap.system_call_filter: false
#禁用系统调用过滤器
network.host: 192.168.xx.xx
#设置当前主机名称
discovery.zen.ping.unicast.hosts: ["192.168.xx.xx"]
#设置集群的主机列表
3. 启动Elasticsearch
[[email protected]]#bin/elasticsearch
-
发现报错: java.lang.RuntimeException:can not run elasticsearch as root
-
报错原因:elasticsearch不允许使用root用户启动
-
解决方法一:
在执行elasticsearch时加上参数-Des.insecure.allow.root=true
bin/elasticsearch -Des.insecure.allow.root=true
- 解决方法二:
在elasticsearch执行文件中添加ES_JAVA_OPTS="-Des.insecure.allow.root=true"
这样以后就不用添加参数也可以以root身份运行了
- 解决方法三:
添加一个用户
adduser *** //添加用户
passwd *** //给用户赋值
添加完用户之后:
用root用户执行 : chown -R 文件夹名 用户名
将所在的文件夹及解压完的文件夹权限给你新建的用户。之后再使用新用户启动就OK了。
然后使用bin/elasticsearch 就可以启动elasticsearch了,或者使用bin/elasticsearch -d命令在后端启动
4. 其他常见错误
- 1.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
这个是因为/etc/sysctl.conf文件中修改不成功导致的
- 切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
- 2.max number of threads [40] for user [ywq] is too low, increase to at least [2048]
设置/etc/security/limits.conf
# 结尾部分
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
然后重启服务器生效