Elasticsearch的安装与简单配置

本地部署和水平扩展

水平扩展图
非常容易搭建,在个人电脑上即可进行搭建学习

? 图中几个节点的名称和含义

master node:维护元数据,管理集群各个节点的状态

coordinate node:协调节点,搜索的数据存储于不同的data node上时进行处理

data node:负责数据的查询和导入

hot node:热数据节点,保留短时间内的热数据,超过时间进行迁移到冷节点

warm node:冷数据节点,处理只读索引并且不是经常访问的数据

ml node:(TODO:考察多个文档,暂未发现该节点作用,后续补充)

安装过程

安装java

  • 运行es,需安装并配置JDK
    • 设置$JAVA_HOME
  • 各个版本对jdk版本的依赖
    • es 5需要java 8以上版本
    • es 6.5支持java 11
    • 具体支撑参考网址: https://www.elastic.co/support/matrix#matrix_jvm
    • 7.0之后内置java环境

安装es

注:

  • 可一次性将windows和linux的同时下载,在自己电脑上用windows操作,服务器上用linux
  • es全家桶要求各个版本一致,为方便起见,同时下载Elasticsearch,Kibana,Beats,Logstash,下载地址https://www.elastic.co/cn/downloads/
windows安装
  • 解压已经安装的elasticsearch压缩包,(我本地是7.2.0)
  • 到文件夹 elasticsearch-7.2.0\bin下,双击 elasticsearch.bat
linux安装
  • 解压tar包
  • elasticsearch-7.3.1/bin/elasticsearch(为防止出现问题,笔者又用最新版的测试了一下安装过程)

环境:

centos7

jdk8

[root@node2 download]# tar zxvf elasticsearch-7.3.1-linux-x86_64.tar.gz
[root@node2 download]# mv elasticsearch-7.3.1 /home/elasticsearch-7.3.1

# 注意:es不能使用root用户启动,之前我已经创建过esuser用户了,故修改用户组即可,建议创建新用户
[root@node2 home]# chown -R esuser:esuser /home/elasticsearch-7.3.1
[root@node2 home]# su esuser
[esuser@node2 home]$ cd /home/elasticsearch-7.3.1/
[esuser@node2 elasticsearch-7.3.1]$ bin/elasticsearch

如果无法访问9200,请移步本章节的 相关问题-linux出现的问题

验证es是否安装成功

  • 打开浏览器,输入地址:http://127.0.0.1:9200,如出现以下输出,代表elasticsearch启动正常

linux环境下通过curl查看

{
    "name": "DESKTOP-1AMTS94",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "8KXlt8BSRBmB4GikyjYq0A",
    "version": {
        "number": "7.2.0",
        "build_flavor": "default",
        "build_type": "zip",
        "build_hash": "508c38a",
        "build_date": "2019-06-20T15:54:18.811730Z",
        "build_snapshot": false,
        "lucene_version": "8.0.0",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
}

es插件

  • elasticsearch提供插件机制对系统进行扩展
    • Discovery Plugin
    • Analysis Plugin
    • Security Plugin
    • Management Plugin
    • Ingest Plugin
    • Mapper Plugin
    • Backup Plugin
安装analysis-icu插件
# 安装插件
bin/elasticsearch-plugin install analysis-icu

# 查看插件
bin/elasticsearch-plugin list

# 浏览器查看
http://localhost:9200/_cat/plugins
# 显示结果DESKTOP-1AMTS94 analysis-icu 7.2.0

elatsicsearch的文件目录结构

目录配置文件描述
bin脚本文件,包括启动elasticsearch,安装插件,运行统计数据等
configelasticsearch.yml集群配置文件,user,role based相关配置
JDKjava运行环境
datapath.data数据文件
libjava类库
modules日志文件
plugins包含所有已经安装的插件
logspath.log日志文件

JVM配置(可选)

  • 修改JVM
    • PATH:config/jvm.options
    • 7.2下载的默认配置是1G
  • 配置建议
    • Xmx和Xms设置成一样
    • Xmx不要超过机器内存的50%
    • 不要超过30G (https://www.elastic.co/blog/a-heap-of-trouble)

相关命令

# 启动单节点
bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data



# 运行多实例方法
#linux
bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data
bin/elasticsearch -E node.name=node1 -E cluster.name=geektime -E path.data=node1_data
bin/elasticsearch -E node.name=node2 -E cluster.name=geektime -E path.data=node2_data
bin/elasticsearch -E node.name=node3 -E cluster.name=geektime -E path.data=node3_data
# windows
 .\bin\elasticsearch.bat -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data
 .\bin\elasticsearch.bat -E node.name=node1 -E cluster.name=geektime -E path.data=node1_data
 .\bin\elasticsearch.bat -E node.name=node2 -E cluster.name=geektime -E path.data=node2_data
 .\bin\elasticsearch.bat -E node.name=node3 -E cluster.name=geektime -E path.data=node3_data

# 删除进程
ps|grep elastcsearch
kill pid

# 查看集群
GET http://localhost:9200
#查看nodes
GET _cat/nodes
GET _cluster/health

相关问题

linux出现的问题

  1. seccomp unavailable 错误
    解决方法:elasticsearch.yml 配置
    bootstrap.memory_lock: false
    bootstrap.system_call_filter: false

  2. max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
    解决方法:修改 /etc/security/limits.conf,配置:
    hard nofile 80000
    soft nofile 80000

    ps:本地测试,修改了limits后,需要重启系统

  3. max virtual memory areas vm.max_map_count [65530] is too low
    解决方法:修改 /etc/sysctl.conf,添加 :
    vm.max_map_count = 262144
    然后 sysctl -p 生效

  4. the default discovery settings are unsuitable…, last least one of […] must be configured
    解决方法:elasticsearch.yml 开启配置:
    node.name: node-1
    cluster.initial_master_nodes: ["node-1"]

  5. localhost可以连接,固定IP无法访问

    解决方法:elasticsearch.yml 开启配置

    network.host: 0.0.0.0

相关阅读

  • 安装指南 https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.
  • Elastic Support Matrix(OS / JDK ) https://www.elastic.co/cn/support/matrix
  • Elasticsearch 的一些重要配置 https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html
  • https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
  • https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html
  • Elasticsearch on Kuvernetes https://www.elastic.co/cn/blog/introducing-elastic-cloud-on-kubernetes-the-elasticsearch-operator-and-beyond
  • CAT Plugins API https://www.elastic.co/guide/en/elasticsearch/reference/7.1/cat-plugins.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值