linux环境安装以及配置elasticsearch-7.3.2
注:es自带了jdk。如果在linux服务器上安装了jdk,es就会使用自己安装的jdk
1.linux ES的安装(elasticsearch-7.3.2)
1.下载elasticsearch-7.3.2 tar包 下载地址:https://www.elastic.co/cn/downloads/elasticsearch
2.上传到linux,解压 tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
3.进入解压后的 elasticsearch-7.3.2文件夹的bin目录下 执行./elasticsearch
执行结果如下:
这个错误,是因为使用root用户启动elasticsearch,elasticsearch是不允许使用root用户启动的
在6.xx之前,可以通过root用户启动。但是发现黑客可以透过elasticsearch获取root用户密码,所以为了安全性,在6版本之后就不能通过root启动elasticsearch
解决方案如下:
#创建用户组
1.groupadd hcy
#添加用户到用户组
2.useradd hcy -g hcy
3.cd [elasticsearch-7.3.2所在路径]
#把es文件拥有者修改为创建的用户
4.chown -R hcy:hcy elasticsearch-7.3.2
#切换到创建的用户然后云行
5.su hcy
这时候可以启动,但是使用浏览器访问,访问不了,解决方法如下:
修改配置 在elasticsearch目录下:
1、调整jvm内存大小(机器内存够也可不调整)
vim config/jvm.options
-Xms512m
-Xmx512m2、修改network配置,支持通过ip访问
vim config/elasticsearch.yml
network.host:服务器地址
http.port: 9200
修改完之后再启动又会报4个如下错误:
max file descriptors [4096] for elasticsearch process is too low,
increase to at least [65535]
最大文件描述符[4096]对于elasticsearch进程可能太低,至少增加到[65535] max number of threads
[3802] for user [hcy] is too low, increase to at least [4096]
用户的最大线程数[3802]过低,增加到至少[4096]
方法:
vim /etc/security/limits.conf
soft nofile 65536
hard nofile 131072
soft nproc 2048
hard nproc 4096
所有用户 nofile - 打开文件的最大数目
noproc - 进程的最大数目
soft 指的是当前系统生效的设置值
hard 表明系统中所能设定的最大值
max virtual memory areas vm.max_map_count [65530] is too low, increase
to at least [262144] vm最大虚拟内存,max_map_count[65530]太低,至少增加到[262144]
方法:
vim /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p 使配置生效
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 discovery.seed_hosts,
discovery.seed_providers, cluster.initial_master_nodes这三个配置,必须配置
方法:
vim config/elasticsearch.yml
#集群名称 配置集群时候使用 名称必须一致
cluster.name=hcy
#节点名称
node.name=node-1
#集群初始化master节点
cluster.initial_master_nodes: [“node-1”]
启动:
#切换到创建用户
su hcy
cd /elasticsearch-7.3.2/bin
./elasticsearch 或 ./elasticsearch -d (以后台方式运行)
注意:注意开放端口或者关闭防火墙(centos7)
查询防火墙状态:firewall-cmd --state
关闭防火墙:systemctl stop firewalld.service
开启防火墙: systemctl start firewalld.service
禁止firewall开机启动:systemctl disable firewalld.service
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/opt/elasticsearch-7.3.2/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
简单理解为:绑定节点失败!!!
百度后,好多人同样遇到了这个问题,导致的原因可能是因为之前运行的es还没有正常关闭。
方法: ps -ef |grep ‘elastic’
kill -9 进程号