美文网首页
ELK之Linux环境下安装ElasticSearch

ELK之Linux环境下安装ElasticSearch

作者: 我我我不是明 | 来源:发表于2019-05-17 17:35 被阅读0次
1.elasticsearch是目前比较流行的搜索引擎,而我最近也在了解搜索引擎方面的知识。今天这篇文章只是讲解了Linux环境下怎么安装ElasticSearch.
2.ELK(elasticsearch,logstash,kibana),安装这三个软件最好保持版本一致。
3.先在服务器上搭建好jdk1.8环境。若还没搭建,可参考我之前写的《Ubuntu(Linux)环境下配置java环境》

为了方便书写,以下将elasticsearch简称为es

一、正文开始

1.先去es官网下载linux的版本《es官网下载》,我这里下载的是7.0.1版本

2.然后上传到服务器,我这里是放在/usr/local目录下面

es

3.解压命令: tar -zxvf 文件名字
解压之后进入es文件夹,再进入到里面的config目录

config目录

二、配置开始

2.1、首先在config目录下找到 jvm.options.通过编辑命令: vim jvm.options

jvm.options
主要是修改虚拟机分配的大小,由于我服务器配置不高,只能改小点.实际根据个人情况去配

2.2、修改elasticsearch.yml配置文件
命令: vim elasticsearch.yml

# ======================== 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
cluster.name: test-cluster
#
# ------------------------------------ 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: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/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
#
# 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 this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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、启动ES(需要去到es的bin目录下)

3.1、如果直接启动你会发现以下错误 es启动命令:./elasticsearch
错误如下:

错误

es不允许使用root用户启动,那么我们需要手动添加一个用户
添加用户命令:

groupadd elsearch //添加用户组
useradd elsearch -g elsearch -p elsearch //添加用户
chown -R elsearch:elsearch /usr/local/elasticsearch-7.0.1  //给用户分配目录权限
添加完切换用户

如上图,添加完用户后通过命令:su elsearch(用户名)进行切换用户


3.3、进行第二次启动
此时发现3个错误,如下图:

错误

解决错误前,需要切回root用户 su root之后输入服务器密码,就能切回root
第一个错误:
[1]: max number of threads [3883] for user [elsearch] is too low, increase to at least [4096]
解决方法:需要编辑 vim /etc/security/limits.conf文件

补上图中2行

第二个错误:

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

解决方法:

切换到root用户

执行命令:

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

显示:
vm.max_map_count = 262144

上述方法修改之后,如果重启虚拟机将失效,所以:

解决办法:

在 /etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

即可永久修改

第三个错误:

[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

解决:返回去config目录下面的elasticsearch.yml配置文件放开某个配置,如下图

image.png

3.4、切换回elsearch用户,再次启动
启动了一会,没有出现错误

成功
访问:服务器ip + 9200端口,出现下图说明安装成功
成功

最后如果想es后台启动
命令: ./elasticsearch -d
命令2: nohup ./elasticsearch &

相关文章

网友评论

      本文标题:ELK之Linux环境下安装ElasticSearch

      本文链接:https://www.haomeiwen.com/subject/rcpoaqtx.html