Elasticsearch:安装并启动

231 阅读2分钟

[toc]

  1. 去官网下载最新的版本 elasticsearch官网

  2. 上传至linux服务器,解压到usr/local目录,解压后的目录如下:

bin:脚本目录,包括:启动、停止等可执行脚本

config:配置文件目录

data:索引目录,存放索引文件的地方

logs:日志目录

modules:模块目录,包括了es的功能模块

plugins :插件目录,es支持插件机制

  1. 修改config目录下elasticsearch.yml配置文件

编辑 vim elasticsearch.yml

修改集群的名字和nodo节点(单机可以使用默认值,集群环境都要改)

cluster.name: imooc-elasticsearch

node.name:es-node1

配置数据和日志路径

path.data:/usr/local/elasticsearch/data

path.logs:/usr/local/elasticsearch/logs

配置网络和端口(端口默认是9200,不配就是使用默认值)

network.host:0.0.0.0

配置发现的节点:(与上面的node节点保持一致)

cluster.initial_master_nodes:["es-node1"]

  1. 修改config目录下jvm.options配置文件

编辑 vim jvm.options

修改内存(默认1G,看实际情况配置)

-Xms128m

-Xmx128m

  1. 创建ES用户

ES无法使用root用户启动,需要添加一个新用户

添加用户:useradd esuser

授权:chown -R esuser:esuser /usr/local/elasticsearch

  1. 启动ES

进入到bin目录

切换到es用户:su esuser

前台启动命令./elasticsearch

如果启动报异常,查看相关的java异常内容,修改后再启动即可

后台启动./elasticsearch -d

停止进程:使用kill命令


  1. 启动报error错误,可能需要修改系统配置

1)root用户编辑文件:vim /etc/security/limits.conf

在最后加上:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

2)root用户编辑文件:vim /etc/sysctl.conf 在最下方加上

vm.max_map_count:262144

刷新配置文件:sysctl -p


  1. 修复跨域问题

编辑 vim elasticsearch.yml

在最后一行加上如下命令

开启跨域:http.cors.enabled: true

任何地址都可以请求:http.cors.allow-origin: "*"