(一)es 概述与安装
2024-10-19 22:23:17
一、基本概念介绍
1. es 核心术语
- 核心概念
ES -> 数据库
索引index -> 表
文档 document -> 行(记录)
字段 fields -> 列
早期版本有类型Type(后期7.X以后为_doc)
Type -> 表的逻辑类型
映射mapping 相当于mysql的表结构
近实时NRT near real time (搜索1秒以内)
节点node 可以集群
shard replica 数据分片
- 倒排索引
根据分词得到的值去标记位置
2:2:<2,4> 代表 第一个2 代表文档id 第二个2带表出现的频率,尖括号中的代表位置,第二个词与第四个词。
二、es的安装
1. 下载
百度搜索 es 或者点击
2. 上传解压移动
- 上传到linux 中
- 解压
tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz
- 移动到 usr/local下(这个根据个人习惯)
mv elasticsearch-7.4.2 /usr/local/
3. 配置
- 进入es目录
bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等
config:配置文件目录
JDK:java环境
lib:依赖的jar,类库
logs:日志文件
modules:es相关的模块
plugins:可以自己开发的插件
data:这个目录没有,自己新建一下,后面要用 -> mkdir data,这个作为索引目录
- 修改核心配置文件-elasticearch.yml
修改项目名 cluster.name: myestest、node.name: myestest
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: myestest
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: myestest
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
保存data地址 与log地址 /usr/local/elasticsearch-7.4.2/
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-7.4.2/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-7.4.2/logs
#
网络对外可访问 端口可改
network.host: 0.0.0.0
# ---------------------------------- 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.
#
集群节点 目前是单台,先配置一个 cluster.initial_master_nodes: ["myestest"]
# --------------------------------- 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.
- 根据自己机器配置修改JVM参数 config/jvm.options
-Xms1g
-Xmx1g
- 添加用户
- ES不允许使用root操作es,需要添加用户,操作如下:
useradd esuser # 新增用户
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2 # 给用户赋权
su esuser # 切换当前用户
whoami # 查看当前用户
- 切换完进入bin目录下
./elasticsearch
- 报错1
future versions of Elasticsearch will require Java 11; your Java version from [/home/jdk/jdk1.8.0_191/jre] does not meet this requirement
这是因为es自带jdk 与我们安装的jdk不一致,环境变量冲突了,但是是向下兼容的,所以对于我现在安装的 es7.4版本是可以用jdk1.8的。所以可以不用管这个。
- 报错二
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-10-21T15:09:26,905][INFO ][o.e.n.Node ] [VM-0-9-centos] stopping ...
[2020-10-21T15:09:27,058][INFO ][o.e.n.Node ] [VM-0-9-centos] stopped
[2020-10-21T15:09:27,058][INFO ][o.e.n.Node ] [VM-0-9-centos] closing ...
[2020-10-21T15:09:27,092][INFO ][o.e.n.Node ] [VM-0-9-centos] closed
[2020-10-21T15:09:27,098][INFO ][o.e.x.m.p.NativeController] [VM-0-9-centos] Native controller process has stopped - no new native processes can be started
这个就需要增加额外的配置(切换用户到root下),修改 /etc/security/limits.conf
# 修改配置文件 limits.conf
vim /etc/security/limits.conf
# 增加如下配置
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
修改 sysctl.conf 配置文件
# 编辑配置
vim /etc/sysctl.conf
# 增加配置
vm.max_map_count=262145
# 增加完了刷新一下配置,使其生效。
sysctl -p
- 重启搞定访问 9200 端口搞定
# 前台启动 Ctrl+c就退出了
./elasticsearch
# 后台启动 关闭使用kill 杀进程的方式
./elasticsearch -d
- 杀进程
[esuser@VM-0-9-centos logs]$ jps
15304 Elasticsearch
15773 Jps
[esuser@VM-0-9-centos logs]$ kill -9 15304
4. 安装插件
- elasticsearch-head 可以去git官网,也可以百度云
链接: https://pan.baidu.com/s/1U6sKvxOG0BfmK5SMd8GY3w
提取码: 7vh5
- 若链接有跨域问题可以在yml配置文件中增加下面配置
# 开启跨域
http.cors.enabled: true
# 允许所有域名访问
http.cors.allow-origin: "*"
# 头部标识
http.cors.allow-headers: Authorization
- 下载后安装crt文件
将文件夹elasticsearch-head-master\crx中 es-head.crx文件拖到浏览器里就可以安装插件了。
若报错参考:https://www.cnblogs.com/wzx1blog/p/13066693.html
- 官方文档
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/index.html
最新文章
- server与Portal联合,portal许可过期无法登录。
- 这是一个比较清晰的SSH框架结构,有兴趣的博友可以看一下
- CentOS 7.2 搭建 Openvpn 服务器
- ABAP中正则表达式的简单使用方法 (转老白BLOG)
- static 与 final 修饰符
- STL学习笔记序言
- Mybatis中实体类中的字段跟对应表的字段不一致时解决办法
- 解决SVN:could not start external diff program的问题。
- 使用java API查询java类
- ajax+php如何获取部分请求的信息显示在对应的div中
- koa中间件系统原理及koa+orm2实践。
- 常见C++面试题及基本知识点总结(一)
- [poj3565]Ants
- LeetCode-101.对称二叉树
- JavaScript四(DOM编程)
- flexbuilder 开发工具
- pandas groupby生成新的dataframe
- optional
- [Big Data - ZooKeeper] ZooKeeper: A Distributed Coordination Service for Distributed Applications
- Linux svn的搭建和使用