ElasticSearch 6.5.1 集群搭建以及 ElasticSearch-Head 插件安装使用

本贴最后更新于 2164 天前,其中的信息可能已经物是人非

ElasticSearch 6.5.1 集群搭建以及 ElasticSearch-Head 插件安装使用

ElasticSearch 集群搭建

  1. elasticsearch 官网下载对应的版本,这里我们使用的是 6.5.1 版本。

    注意:elasticsearch 要依赖 Jdk1.8.x

    检查服务器 Java 环境

    java -version
    

    解压到对应的位置

    tar -zxvf elasticsearch-6.5.1.tar.gz
    
  2. 配置 elasticsearch.yml 文件

    cd elasticsearch-6.5.1/config
    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:
    
    #配置的集群名称,默认是elasticsearch,es服务会通过广播方式自动连接在同一网段下的es服务,通过多播方式进行通信,同一网段下可以有多个集群,通过集群名称这个属性来区分不同的集群。
    cluster.name: elasticsearch-cluster
    #
    # ------------------------------------ Node ------------------------------------
    #
    # Use a descriptive name for the node:
    #
    #当前配置所在机器的节点名,你不设置就默认随机指定一个name列表中名字,该name列表在es的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字。当创建ES集群时,保证同一集群中的cluster.name名称是相同的,node.name节点名称是不同的;
    #
    node.name: node-master
    #指定该节点是否有资格被选举成为node(注意这里只是设置成有资格, 不代表该node一定就是master),默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。
    node.master: true
    #是否是数据节点  默认情况下任何一个集群中的节点都有可能被选为主节点。索引数据和搜索查询等操作会占用大量的cpu,内存,io资源,为了确保一个集群的稳定,分离主节点和数据节点是一个比较好的选择。虽然主节点也可以协调节点,路由搜索和从客户端新增数据到数据节点,但最好不要使用这些专用的主节点。一个重要的原则是,尽可能做尽量少的工作
    node.data: false
    #
    # 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.240
    #
    # Set a custom port for HTTP:
    #http端口
    http.port: 9200
    #tcp 通讯端口配置多节点的话使用9331,9332,9333....
    transport.tcp.port: 9331
    #开启跨域访问支持,默认为false
    http.cors.enabled: true
    #跨域访问允许的域名地址,(允许所有域名)以上使用正则
    http.cors.allow-origin: /.*/
    #
    # For more information, consult the network mofangfadule 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]"]
    #集群信息,默认的通讯端口是9300
    discovery.zen.ping.unicast.hosts:    ["192.168.0.240:9331","192.168.0.241:9332","192.168.0.242:9333","192.168.0.244:9334"]
    #
    # 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. 在其他服务器安装配置 elasticsearch6.5.1

    重复上述方法

# ======================== 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:

#配置的集群名称,默认是elasticsearch,es服务会通过广播方式自动连接在同一网段下的es服务,通过多播方式进行通信,同一网段下可以有多个集群,通过集群名称这个属性来区分不同的集群。
cluster.name: elasticsearch-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#当前配置所在机器的节点名,你不设置就默认随机指定一个name列表中名字,该name列表在es的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字。当创建ES集群时,保证同一集群中的cluster.name名称是相同的,node.name节点名称是不同的;
#
node.name: node-data1
#指定该节点是否有资格被选举成为node(注意这里只是设置成有资格, 不代表该node一定就是master),默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。
node.master: false
#是否是数据节点  默认情况下任何一个集群中的节点都有可能被选为主节点。索引数据和搜索查询等操作会占用大量的cpu,内存,io资源,为了确保一个集群的稳定,分离主节点和数据节点是一个比较好的选择。虽然主节点也可以协调节点,路由搜索和从客户端新增数据到数据节点,但最好不要使用这些专用的主节点。一个重要的原则是,尽可能做尽量少的工作
node.data: true
#
# 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.241
#
# Set a custom port for HTTP:
#http端口
http.port: 9200
#tcp 通讯端口配置多节点的话使用9331,9332,9333....
transport.tcp.port: 9332
#开启跨域访问支持,默认为false
http.cors.enabled: true
#跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: /.*/
#
# For more information, consult the network mofangfadule 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]"]
#集群信息,默认的通讯端口是9300
discovery.zen.ping.unicast.hosts:    ["192.168.0.240:9331","192.168.0.241:9332","192.168.0.242:9333","192.168.0.244:9334"]
#
# 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

4.启动 elasticsearch 集群

​ 由于 elasticsearch 不能由 root 用户启动所以我们要添加用户

新建用户组

groupadd elasticsearch

给elasticsearch用户组添加es用户

useradd  -g elasticsearch es

这里要注意文件的权限问题

启动并查看日志

./bin/elasticsearch -d ;tail -f /logspath/elasticsearch-cluster.log

另外的都是依次启动就行了。。。。

ElasticSearch-Head 插件安装

github 项目地址可以看看

  1. ​ 首先检查服务器是否安装 node 环境

    node -v
    npm -v
    
  2. ​ 安装

    cd elasticsearch-head
    
    #淘宝镜像
    npm install -g grunt --registry=https://registry.npm.taobao.org
    
    npm install
    
    npm run start
    
    #后台运行
    #nohup npm run start & 
    
  3. 测试连接是否成功

    浏览器打开

    curl -X GET http://localhost:9100/
    

esheadpng

  • Elasticsearch

    Elasticsearch 是一个基于 Lucene 的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于 RESTful 接口。Elasticsearch 是用 Java 开发的,并作为 Apache 许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

    117 引用 • 99 回帖 • 211 关注
  • 集群
    29 引用 • 65 回帖 • 1 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...