centos系统的elasticsearch安装


安装2.0.0的elasticsearch服务,项目是依赖spring-boot1.5.9.RELEASE版本,指定了elasticsearch版本,否则无法使用

spring data elasticsearch elasticsearch
3.0.0.RC2 5.5.0
3.0.0.M4 5.4.0
2.0.4.RELEASE 2.4.0
2.0.0.RELEASE 2.2.0
1.4.0.M1 1.7.3
1.3.0.RELEASE 1.5.2
1.2.0.RELEASE 1.4.4
1.1.0.RELEASE 1.3.2
1.0.0.RELEASE 1.1.1

基础环境

  1. JDK1.8以上
  2. 创建elasticsearch用户
1
2
groupadd elsearch
useradd elsearch -g elsearch
  1. 提高系统线程数
1
2
3
4
5
6
vim /etc/security/limits.conf

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
1
2
3
vim /etc/security/limits.d/90-nproc.conf 

* soft nproc 2048

否则会出现错误:

1
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
  1. 提高系统变量数量
1
2
3
4
5
6
7
vim /etc/sysctl.conf

添加或者修改:
vm.max_map_count=655360

立即生效:
sysctl -p

否则出现以下错误:

1
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

elasticsearch安装

  1. 使用新创建的elsearch用户
1
su elsearch
  1. 下载2.0.0的elasticsearch包,因为程序使用的是spring-boot1.5.9.RELEASE版本,所以使用elasticsearch的2.0.0版本,否则无法启动
    如果使用的是其他版本的springboot,需要按照代码版本使用不同版本的elasticsearch服务
    下载地址:https://www.elastic.co/downloads/past-releases/elasticsearch-2-0-0
1
2
3
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.0.0/elasticsearch-2.0.0.zip

unzip elasticsearch-2.0.0.zip
  1. 给目录授权
    使用root用户给ES目录授权
1
2
chown -R elsearch:elsearch elasticsearch-2.0.0/ 

  1. 修改ES配置
1
2
3
cd elasticsearch-2.0.0

vim config/elasticsearch.yml

主要修改一下几项:

  • cluster.name: my-application:集群名称
  • node.name: node-1:当前节点名称
  • path.data: /home/elsearch/data:数据存放目录
  • path.logs: /home/elsearch/logs:日志存放目录
  • bootstrap.mlockall: false:centos系统需要修改,否则报错如下
  • bootstrap.system_call_filter: false:centos用户需要添加,否则报错如下
1
2
ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

因为Centos6不支持SecComp,而ES5.2.1默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。

  • network.host: 192.168.1.40:修改为当前服务器IP
  • http.port: 9200:ES服务API端口号
  • 添加跨域请求:
1
2
http.cors.enabled: true
http.cors.allow-origin: /.*/

启动服务

使用elsearch用户启动一下

1
2
3
cd elasticsearch-2.0.0

./bin/elasticsearch

如果出现started字样,说明启动成功

然后使用下面启动方式,为后台启动

1
./bin/elasticsearch -d

测试

浏览器访问:http://192.168.1.40:9200,出现一下为成功:

1
2
3
4
5
6
7
8
9
10
11
12
{
name: "node-1",
cluster_name: "my-application",
version: {
number: "2.0.0",
build_hash: "de54438d6af8f9340d50c5c786151783ce7d6be5",
build_timestamp: "2015-10-22T08:09:48Z",
build_snapshot: false,
lucene_version: "5.2.1"
},
tagline: "You Know, for Search"
}