linux安装部署Elasticsearch6.6

啥都不管,先安装ES

学什么东西都先二话不说的先来一个hello world
																	——鲁迅

本教程仅做个人工作笔记,可能不适用于他人的工作/学习

几个注意的点

  • 需要在linux中创建新用户,不能直接使用root启动ES
  • elasticsearch.yml中的配置,尤其是network.host
  • 需要另外配置etc下的配置文件

tar包下载地址 https://www.elastic.co/cn/downloads/elasticsearch
博主是下载之后用ftp将tar包传输到服务器上的;
也可以使用weget的方式直接在linux上下载;

下载之后解压
tar -xzvf xxxx.tar
解压后需要做改动的地方是config文件夹下的elasticsearch.yml

vi一下丫的
vi 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
#
# ------------------------------------ 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: 192.168.0.1
#
# 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

需要注意的几个配置cluster.namenode.namenetwork.hosthttp.port,其中前两个是自定义的名字,network.host设置为“0.0.0.0”,这样你的浏览器才能连接上,http.port默认为9200,结果如下

cluster.name="elastic_demo"
node.name="elastic_demo_node"
network.host="0.0.0.0"
http.port=9200

简单配置后就是尝试启动,那么我们的问题就踏着轻快的脚步来了

1、can not run elasticsearch as root
为了安全,elasticsearch不允许使用root用户直接启动,解决方案如下

新建用户:
useradd elasticUser
给用户添加密码:
passwd elasticUser
系统会提示你输入密码并确认密码
在root的环境下给新建的用户赋予elastic文件夹的权限:
chown -R elasticUser elastic/
切换到新用户 :
su elasticUser
然后再进到bin目录下启动脚本:
./elasticsearch

2、你以为这样就启动成功了吗?MD不可能

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

问题[1]的解决方案

编辑 /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
记得要切换回root账户去修改,修改后启动,发现只剩一个问题,修改生效

问题[2]的解决方案

编辑 /etc/sysctl.conf,追加以下内容:
vm.max_map_count=655360
保存后,执行:
sysctl -p

最后为了能测试访问es,还需要再elasticsearch.yml文件中追加配置

http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true

然后重启,访问ip:9200,如果浏览器出现以下信息

{
  "name" : "XXX",
  "cluster_name" : "XXX",
  "cluster_uuid" : "XXXXXXXX",
  "version" : {
    "number" : "6.6.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "a9861f4",
    "build_date" : "2019-01-24T11:27:09.439740Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

这是最简单的启动成功了


2020/4/8补充

  • swapping性能问题

elasticsearch.yml配置文件中有这么一行配置#bootstrap.memory_lock: true默认是屏蔽掉的,也就是false属性,官网的解释 是:发生系统swapping的时候ES节点的性能会非常差,也会影响节点的稳定性。所以要不惜一切代价来避免swapping。swapping会导致Java GC的周期延迟从毫秒级恶化到分钟,更严重的是会引起节点响应延迟甚至脱离集群。

通常我们的做法只是限制es进程所占用的内存,在VM的相关文件中进行限制即可,保险期间,还是将该配置设置为true,但是设置之后无法直接重启

memory locking requested for elasticsearch process but memory is not locked

解决:Hellxz技术小筑的博客

  • 设置用户密码
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值