Elasticsearch 单机快速搭建

前言

  1. Linux 快速搭建 Elasticsearch
  2. 只要复制黏贴,快速搭建好。

步骤

  1. 参考博客
  2. 准备工作一:安装JDK
  3. 准备工作一:修改 /etc/security/limits.conf
  4. 准备工作三:修改 /etc/sysctl.conf
  5. Elasticsearch 下载、解压
  6. Elasticsearch 配置
  7. Elasticsearch 创建专门的用户
  8. Elasticsearch 启动
  9. 查看 Elasticsearch 启动日志
  10. 访问 Elasticsearch 看启动结果
  11. Elasticsearch 分词插件-安装
  12. 重启 Elasticsearch
  13. IK 分词器 2 种分词模式测试
  14. 安装Chrome插件Elasticsearch Head
  15. 错误解决

0. 参考博客

  1. 《芋道 Elasticsearch 极简入门 https://www.iocoder.cn/Elasticsearch/install/

1. 准备工作一:安装JDK

2. 准备工作一:修改 /etc/security/limits.conf

  1. 执行命令: vim /etc/security/limits.conf
  2. 添加内容
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
  1. 查看结果: cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
......
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
# End of file

3. 准备工作三:修改 /etc/sysctl.conf

  1. 执行命令: vim /etc/sysctl.conf
  2. 添加内容
vm.max_map_count=655360
  1. 查看结果命令: cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

vm.max_map_count=655360

4. Elasticsearch 下载 解压

  1. 下载命令: cd /environmental/install/base && wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz
  2. 解压命令: tar -zxvf elasticsearch-7.12.0-linux-x86_64.tar.gz -C /environmental/software
  3. 进入解压文件夹命令: cd /environmental/software/elasticsearch-7.12.0

5. Elasticsearch 配置

  1. 编辑配置文件,开启外网访问 vim config/elasticsearch.yml
# 修改 network.host 开启外网访问
network.host: 0.0.0.0 

6. Elasticsearch 创建专门的用户

  1. 创建用户命令: adduser elasticsearch
  2. 输入两次密码
  3. 对应的文件夹权限复制给该用户,命令: chown -R elasticsearch /environmental/software/elasticsearch-7.12.0
  4. 切换到elasticsearch用户,命令: su elasticsearch

7. Elasticsearch 启动

  1. 启动。通过 -d 参数,表示后台运行。命令: bin/elasticsearch -d

8. 查看 Elasticsearch 启动日志

  1. 查看命令: tail -f logs/elasticsearch.log

9. 网页访问 Elasticsearch 看启动结果

  1. 访问网页 http://ip:9200/ 返回结果。
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "UyciDGkPT9ulLdNdoV7XDg",
  "version" : {
    "number" : "7.12.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a",
    "build_date" : "2021-03-18T06:17:15.410153305Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

10. Elasticsearch 分词插件-安装

  1. 下载插件。命令: wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.0/elasticsearch-analysis-ik-7.12.0.zip
  2. 需要解压到 plugins/ik/ 目录下。命令: unzip elasticsearch-analysis-ik-7.12.0.zip -d plugins/ik/

11. 重启 Elasticsearch

  1. 找到es进程命令: ps -ef | grep elastic
  2. 杀死进程命令: kill -15 id
  3. 启动 ES 进程命令: bin/elasticsearch -d

12. IK 分词器 2 种分词模式测试

  1. ik_max_word :IK 最大化分词,会将文本做最细粒度的拆分。
# curl 请求
curl -X POST \
  http://localhost:9200/_analyze \
  -H 'content-type: application/json' \
  -d '{
	"analyzer": "ik_max_word",
	"text": "百事可乐"
}'
# 响应分词结果
{
    "tokens":[
        {
            "token":"百事可乐",
            "start_offset":0,
            "end_offset":4,
            "type":"CN_WORD",
            "position":0
        },
        {
            "token":"百事",
            "start_offset":0,
            "end_offset":2,
            "type":"CN_WORD",
            "position":1
        },
        {
            "token":"百",
            "start_offset":0,
            "end_offset":1,
            "type":"TYPE_CNUM",
            "position":2
        },
        {
            "token":"事",
            "start_offset":1,
            "end_offset":2,
            "type":"CN_CHAR",
            "position":3
        },
        {
            "token":"可乐",
            "start_offset":2,
            "end_offset":4,
            "type":"CN_WORD",
            "position":4
        }
    ]
}
  1. ik_smart :IK 智能分词,会做最粗粒度的拆分。
# curl 请求
curl -X POST \
  http://localhost:9200/_analyze \
  -H 'content-type: application/json' \
  -d '{
	"analyzer": "ik_smart",
	"text": "百事可乐"
}'
# 响应分词结果
{
    "tokens":[
        {
            "token":"百事可乐",
            "start_offset":0,
            "end_offset":4,
            "type":"CN_WORD",
            "position":0
        }
    ]
}

13. 安装Chrome插件Elasticsearch Head

  1. chrome 应用商店安装 Elasticsearch Head

14. 错误解决

  1. ELK搭建过程中出现的问题与解决方法汇总 https://www.cnblogs.com/hellxz/p/11057234.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值