安装Elasticsearch(单节点Linux环境)

一、到官网下载:[https://www.elastic.co/cn/downloads/elasticsearch],选择LINUX的版本。

elasticsearch2.png

二、root权限安装:

  • 在目标目录下上传下载好的tar包,用rz命令(首先,服务器要安装了rz,sz。
    yum install lrzsz命令安装)


    elasticsearch3.png
  • 解压到目标文件下:
    tar -zxvf elasticsearch-6.1.1.tar.gz -C /opt/module/

  • 在/opt/module/elasticsearch-6.1.1路径下创建data和logs文件夹

[root@bigdata elasticsearch-6.1.1]# mkdir data
[root@bigdata elasticsearch-6.1.1]# mkdir logs
  • 修改配置文件/opt/module/elasticsearch-6.1.1/config/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-2
#
# 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: /opt/module/elasticsearch-6.1.1/data
#
# Path to log files:
path.logs: /opt/module/elasticsearch-6.1.1/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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.xx.xxx
#
# 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: ["host112"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: ["node112"] 
#
# 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

  • 这里需要注意:
  1. nodename随意取但是集群内的各节点不能相同。
  2. 修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格。
  • 配置linux系统环境
[root@bigdata config]# sudo vi /etc/security/limits.conf

添加如下内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
[root@bigdata config]#sudo vi /etc/sysctl.conf

添加如下内容:

vm.max_map_count=655360

并执行命令:

[root@bigdata config]$ sudo sysctl -p

注意:ElasticSearch 不能以root用户启动,可以新建一个用户来启动它。

三、Linux新建用户

  • 建用户命令: 举例:我们创建一个名字叫 user的用户
    useradd user -----------创建用户
    passwd user -----------为用户设置密码
    vim /etc/sudoers -----------为用户赋予sudo权限
    添加 user ALL=(ALL) ALL

  • 修改文件夹及其子文件夹属主命令:
    chown -R user ./elasticsearch-6.1.1/

  • 修改后即可以使用user操作此文件夹内容并启动bin/elasticsearch

四、启动ElasticSearch

  • 切换到普通用户:
[kxxx@bigdata elasticsearch-6.1.1]$ bin/elasticsearch
  • 测试elasticsearch
[root@bigdata ~]# curl http://bigdata:9200
{
  "name" : "node-2",
  "cluster_name" : "my-application",
  "cluster_uuid" : "40AsQpxRTc2Eicg19ls19g",
  "version" : {
    "number" : "6.1.1",
    "build_hash" : "bd92e7f",
    "build_date" : "2017-12-17T20:23:25.338Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
ElasticSearch4.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容