- 下载安装包,上传到虚拟机
【1】新建文件夹:mkdir es-home
mkdir es-data
cd es-data
mkdir data
mkdir logs
【2】将elasticsearch-7.6.2-linux-x86_64.tar.gz上传到es-home
【3】cd es-home
【4】解压文件:tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
【5】可有可无:mv elasticsearch-7.6.2 elasticsearch(目录重命名) - 修改配置文件(elasticsearch.yml和jvm.options)
【1】elasticsearch.yml:
vi elasticsearch.yml
cluster.name: es-name
node.name: es-1
path.data: /es-data/data
path.logs: /es-data/logs
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["es-1"]
根据需求设置配置文件,具体可以参考一下两个链接:
ElasticSearch7.x 之 elasticsearch.yml详细配置
elasticsearch-.yml(中文配置详解)
【2】jvm.options
Elasticsearch基于Lucene的,而Lucene底层是java实现,因此需要配置jvm参数。看各自的情况更改
vi jvm.options
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
# 根据实际情况 修改这里的配置
-Xms1g
-Xmx1g
- 切换到root用户修改配置(limits.conf和sysctl.conf)
vi etc/security/limits.conf
#在最后添加
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
vi etc/sysctl.conf
#在最后添加
vm.max_map_count = 262144
执行sysctl -p刷新一下
-
启动Es(不能使用root,需要新建用户)
【1】前台启动 :./elasticsearch
ctrl+c 停止服务
【2】后台启动 :./elasticsearch -d
ps -ef|grep elasticsearch
kill 进程号 -
启动报错:
【1】
Exception in thread "main" java.nio.file.AccessDeniedException: /root/home/searchengine/elasticsearch-6.2.4/config/jvm.options
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:58)
问题:
使用非root用户启动es,用户权限不够,
解决:
chown -R 用户名:用户名 es-home
chown -R 用户名:用户名 es-data
【2】
for elasticsearch process is too low, increase to at least [65536]
解决:
# 切换到root
vi /etc/security/limits.conf
# 在末尾添加
用户名 hard nofile 65536
用户名 soft nofile 65536
重启服务器以便生效
linux修改limits.conf不生效
【3】
elasticsearch启动成功,但页面通过IP+端口号无法访问。
问题:
没有关闭防火墙
解决:
在root用户下关闭防火墙:
centos6:chkconfig iptables off
centos7:systemctl stop firewalld.service
建议为了直接再次操作方便:使用shell启动elasticsearch,虚拟机界面环境root用户下关闭防火墙
linux启动elasticsearch成功后浏览器不能访问