前言
- Linux 快速搭建 Elasticsearch
- 只要复制黏贴,快速搭建好。
步骤
- 参考博客
- 准备工作一:安装JDK
- 准备工作一:修改 /etc/security/limits.conf
- 准备工作三:修改 /etc/sysctl.conf
- Elasticsearch 下载、解压
- Elasticsearch 配置
- Elasticsearch 创建专门的用户
- Elasticsearch 启动
- 查看 Elasticsearch 启动日志
- 访问 Elasticsearch 看启动结果
- Elasticsearch 分词插件-安装
- 重启 Elasticsearch
- IK 分词器 2 种分词模式测试
- 安装Chrome插件Elasticsearch Head
- 错误解决
0. 参考博客
- 《芋道 Elasticsearch 极简入门 https://www.iocoder.cn/Elasticsearch/install/
1. 准备工作一:安装JDK
略
2. 准备工作一:修改 /etc/security/limits.conf
- 执行命令: vim /etc/security/limits.conf
- 添加内容
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
- 查看结果: 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
- 执行命令: vim /etc/sysctl.conf
- 添加内容
vm.max_map_count=655360
- 查看结果命令: 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 下载 解压
- 下载命令: cd /environmental/install/base && wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz
- 解压命令: tar -zxvf elasticsearch-7.12.0-linux-x86_64.tar.gz -C /environmental/software
- 进入解压文件夹命令: cd /environmental/software/elasticsearch-7.12.0
5. Elasticsearch 配置
- 编辑配置文件,开启外网访问 vim config/elasticsearch.yml
# 修改 network.host 开启外网访问
network.host: 0.0.0.0
6. Elasticsearch 创建专门的用户
- 创建用户命令: adduser elasticsearch
- 输入两次密码
- 对应的文件夹权限复制给该用户,命令: chown -R elasticsearch /environmental/software/elasticsearch-7.12.0
- 切换到elasticsearch用户,命令: su elasticsearch
7. Elasticsearch 启动
- 启动。通过 -d 参数,表示后台运行。命令: bin/elasticsearch -d
8. 查看 Elasticsearch 启动日志
- 查看命令: tail -f logs/elasticsearch.log
9. 网页访问 Elasticsearch 看启动结果
- 访问网页 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 分词插件-安装
- 下载插件。命令: wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.0/elasticsearch-analysis-ik-7.12.0.zip
- 需要解压到 plugins/ik/ 目录下。命令: unzip elasticsearch-analysis-ik-7.12.0.zip -d plugins/ik/
11. 重启 Elasticsearch
- 找到es进程命令: ps -ef | grep elastic
- 杀死进程命令: kill -15 id
- 启动 ES 进程命令: bin/elasticsearch -d
12. IK 分词器 2 种分词模式测试
- 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
}
]
}
- 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
- chrome 应用商店安装 Elasticsearch Head
14. 错误解决
- ELK搭建过程中出现的问题与解决方法汇总 https://www.cnblogs.com/hellxz/p/11057234.html