首页 > 技术文章 > CentOS7安装Elasticsearch5.5.3

longrui 2018-10-19 17:29 原文

一、准备

安装Java环境,elasticsearch推荐安装java1.8.0_131或更高的版本,安装教程CentOS7安装JDK1.8

二、安装

CentOS下可以选择.tar.gzrpm方式安装Elasticsearch,但由于生产环境不能访问外网,因此采用.tar.gz的方式安装。

下载安装包

通过浏览器下载对用版本的安装包,下载地址:https://www.elastic.co/downloads/past-releases

如果安装服务器可以连接外网,也可以输入命令直接下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.3.tar.gz

解压及安装

tar -xzf elasticsearch-5.5.3.tar.gz

运行

cd elasticsearch-5.5.3/
./bin/elasticsearch

./bin/elasticsearch -d后台运行

添加用户

如果启动会出现can not run elasticsearch as root的错误,是由于出于安全考虑,Elasticsearch不允许以root用户启动,因此需要添加用于运行Elasticsearch的用户。

adduser xxx                             #添加用户:xxx
passwd ********                         #给xxx用户设置密码
chown -R xxx /opt/elasticsearch-5.5.3   #为xxx添加权限

然后再执行elasticsearch命令则可正常启动Elasticsearch

验证

curl http://localhost:9200

验证结果:

{
  "name" : "Cp8oag6",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
  "version" : {
    "number" : "5.5.3",
    "build_hash" : "f27399d",
    "build_date" : "2016-03-30T09:51:41.449Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.1"
  },
  "tagline" : "You Know, for Search"
}

配置

Elasticsearch的配置文件在[安装目录]/config/文件夹下

elasticsearch.yml

开启外网访问

network.host: 0.0.0.0

锁定物理内存

避免交换,提高性能,以下来源官网:

bootstrap.memory_lock: true

jvm.options

修改JVM堆大小设置

-Xms16g
-Xmx16g

对于内存设置官方提供了一些建议,如:

  • XmsXmx设置成相等的,避免每次垃圾回收完成后JVM重新分配内存;

  • Xmx的大小不要超过物理内存的50%等

详细请参考官方文档:heap-size

错误

max file descriptors太小

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

切换root用户,编辑/etc/security/limits.conf,按照要求改为65536即可,修改后结果:

* soft nofile 65536
* hard nofile 65536

重新登录后生效

max_map_count太小

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

切换root用户,编辑/etc/sysctl.conf,在最后一行增加以下配置:

vm.max_map_count = 262114

需重启后生效

内存锁定失败

memory locking requested for elasticsearch process but memory is not locked

当设置bootstrap.memory_lock: true时,如果没有锁定内存,会报该错误
需切换回root用户,编辑/etc/security/limits.conf,增加以下配置:

* soft memlock unlimited
* hard memlock unlimited

同样重新登录后生效

推荐阅读