一、下载ElasticSearch
https://www.elastic.co/cn/elasticsearch/
二、在Linux下安装ElasticSearch
# 解压安装包
tar -zxvf elastic....
三、修改配置文件之前的准备工作
# 进入解压后的文件夹 创建一个data文件 用来存放es的数据
mkdir data
# 然后进入config文件夹,修改elasticsearch.yml文件
cd config
vi elasticsearch.yml
四、修改配置文件 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: hui-es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 节点的名称
node.name: es-node1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# es存放数据的路径
path.data: /usr/local/elasticsearch-7.4.2/data
#
# Path to log files:
#
#es存放日志的路径
path.logs: /usr/local/elasticsearch-7.4.2/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):
#
# 修改成 0.0.0.0 用于让其他服务器可以访问
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
# 跨域的设置,在使用es-header插件操作es时需要设置
http.cors.enabled: true
http.cors.allow-origin: "*"
#
# For more information, consult the network module documentation.
#
# --------------------------------- 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: ["es-node1"]
#
# For more information, consult the discovery and cluster formation 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
# 在启动es报错后 自己修改的配置
bootstrap.system_call_filter: false
xpack.ml.enabled: false
五、启动ES之前的准备工作
# 修改linux下的一些限制 修改/etc/security/limits.conf文件
vi /etc/security/limits.conf
# 输入这段内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
# 修改/etc/sysctl.conf文件
vi /etc/sysctl.conf
#输入以下内容
vm.max_map_count=262145
#加载配置
sysctl -p
在linux中,启动es不能使用root用户,所以我们需要创建一个用户,并将权限赋给此用户
useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2
# 然后切换用户 进行启动
su esuser
六、启动ES
# 进入es文件夹下的bin目录启动es
# 前台启动es
./elasticsearch
# 后台启动es
./elasticsearch
# 后台启动es后想要关闭es,使用jps命令查找es的有关进程号,使用kill命令杀掉进程 注意:jps命令 虚拟机必须存在java环境
jps
kill es的进程id
七、ES集成中文分词器
下载地址:https://github.com/medcl/elasticsearch-analysis-ik
将压缩包解压到es文件夹下的plugins文件夹下就已经安装成功
自定义分词
在ik分词器下有些网络用语无法进行分词,我们可以自定义词典
# 进入解压后的ik文件夹下的config文件夹
cd plugins/ik/config
# 在此文件夹下创建一个自定义的词典文件 custom.dic 当然文件名自定义 文件所在的目录也可以自定义
mkdir custom.dic
# custom.dic下 输入需要分词的内容 换行为一个词
# 然后将自定义词典加载的ik分词器中,需要修改config文件夹下的IKAnalyzer.cfg.xml文件
vi IKAnalyzer.cfg.xml
IKAnalyzer.cfg.xml文件的内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
八、elasticsearch-head插件的安装
1、第一种方式可以使用进入google商店安装此插件
下载路径:https://codechina.csdn.net/mirrors/mobz/elasticsearch-head?utm_source=csdn_github_accelerator
2、第二种方式使用压缩包进行使用
下载路径:https://github.com/mobz/elasticsearch-head
这种方式,需要在es的配置文件elasticsearch.yml中配置跨域,google插件不需要 在es存在虚拟机情况下
http.cors.enabled: true
http.cors.allow-origin: “*”
# 下载完成后,解压,然后进入此目录下的命令行,输入,注意在使用此种方式时,需要电脑安装node.js
# 当然在安装时可能会出现各种各样的问题,百度就可以,加油
npm install
# 启动运行
npm run start