Centos7下安装Elasticsearch6步骤

Posted willem_chen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7下安装Elasticsearch6步骤相关的知识,希望对你有一定的参考价值。

1、安装jdk

由于es是基于Java开发的,所以在安装es之前我得先安装jdk,要求版本在1.8以上,如果linux上还没有安装jdk1.8的可以参考。

CentOS 7 安装 JAVA环境(JDK 1.8

2、安装Elasticsearch

下载地址:https://download.csdn.net/download/weiguang102/18936517

上传安装包,并解压

tar -zxvf elasticsearch-6.2.4.tar.gz 

在这里插入图片描述

bin          //主要存放的是elasticsearch相关的脚本文件
config       // 存放的是elasticsearch的配置文件
jdk         //elasticsearch自带的jdk
logs        //elasticsearch存放日志
modules     //elasticsearch的功能模块
plugins     //elasticsearch的插件,我们安装的插件存放在此目录

1、新建一个esGroup组和用户(出于安全考虑,Elasticsearch默认是不允许使用root账号运行的)

#新建组
groupadd esGroup 
#新建用户 
useradd esUser -g esGroup 
#切换用户
su esUser

2、更改Elasticsearch文件的拥有者,默认所属root

使用如下命令更改文件所属:

chown esUser:esGroup elasticsearch-6.2.4/ -R

在这里插入图片描述

3、编辑 elasticsearch.yml

在这里我们需要对elasticsearch进行相关的配置,编辑config目录下的elasticsearch.yml文件,重点关注以下7个配置项:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-6.2.4/data  # 数据目录位置(没有需要创建目录属于主esUser)
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-6.2.4/logs  # 日志目录位置
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0  # 任何主机(绑定的ip)
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

3. 运行elasticsearch

首先先切换事先创建的esUser 用户 然后 进行 elasticsearch-6.2.4下的bin目录启动

su -es #切换用户
 
cd /elasticsearch-6.2.4/bin 
 
./elasticsearch #启动elasticsearch

在这里插入图片描述
需要注意是图中绑定了两个端口(9300和 9200):

9300:集群节点间通讯接口 9200:客户端访问接口

elasticsearch 的默认端口为9200,为方便测试,笔者将服务器9200端口开放,执行命令如下:

firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

然后 打开浏览器进行测试:

在这里插入图片描述

4、 在启动过程中的错误

注意:所有错误修改完毕,一定要重启你的 Xshell终端,否则配置无效。


ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决第一个错误:

打开新的窗口切换到root用户,使用vim /etc/security/limits.conf命令编辑limits.conf,添加以下内容:

*  soft  nofile  65536
*  hard  nofile  65536

解决第二个错误:

elasticsearch用户拥有的内存权限太小,至少需要262144。切换root用户下,使用vim /etc/sysctl.conf命令编辑sysctl.conf文件。

添加以下内容:

vm.max_map_count=262144

执行 sysctl -p 使修改生效。

这里两个错误修改以后,在服务器没有重启的情况下重新启动 elasticsearch,第一个问题依然存在,需要重启服务器。

以上是关于Centos7下安装Elasticsearch6步骤的主要内容,如果未能解决你的问题,请参考以下文章

centos7虚拟机安装elasticsearch6.4.x-遇到的坑

Centos7.4 安装elasticsearch6.1.3集群部署

centos7安装elasticsearch6.8.3安装指南

Centos7 单机安装Elasticsearch6.3.0

在centos7中安装elasticsearch6.3

基于docker 搭建Elasticsearch6.2.4