Elasticsearch 安装和使用 6.2.2 ,IK分词器

全文搜索说了很久,一直没弄,现在有时间了,准备开始做了。

1.准备工作

先说版本,因为公司的环境是 6.2.2 版本,所以测试环境也安装6.2.2 版本的,官网找了好久没有找到,后来一个小技巧下载到了。
官网:https://www.elastic.co/downloads/elasticsearch
官网的中文说明文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
也是找了好久,硬是没找到中文版本的使用说明,特别隐蔽
中文分词器: https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-6.2.2.zip
我现在官网上面是6.3.2版本的,但是我需要的是 6.2.2 版本的,找不到对应的地址,但是又不想去别的地方下载
灵机一动,把6.3.2 版本的下载地址中的 版本号改一下,就是我想要的了。(一般下载包都会放同一个目录下面)
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

注意: elasticsearch 5.x.x版本以上都要要求 Jdk 8 了。

2.安装

因为elasticsearch 不允许root用户安装和使用。所以我要先创建用户组 和用户
groupadd smkpp //创建组
useradd es //创建新用户
passwd es //用户修改密码

usermod -G smkapp es //将用户添加到组里面
这里写图片描述

然后使用命令:visudo 修改用户可执行的命令

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
es      ALL=(ALL)       ALL

这里写图片描述

最后切换用户 su es

这里需要把服务器上的 文件夹权限改一下
sudo chown -R es:smkapp elasticsearch-6.2.2/

这里写图片描述

开始配置配置文件
6.2.2的配置文件和网上比对了一下,会少一点其他的配置

# ======================== 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: smk_app_es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#该节点名称,不通节点配置不同的名称
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#数据目录
path.data: /home/smkapp/elasticsearchdata/data
#
# Path to log files:
#日志目录
path.logs: /home/smkapp/elasticsearchdata/log
#
# ----------------------------------- 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):
#服务器当前IP
network.host: 192.168.23.10
#
# Set a custom port for HTTP:
#端口
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#其他节点
discovery.zen.ping.unicast.hosts: ["192.168.23.10", "192.168.23.11"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#最大master节点
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery 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

保存之后就开始启动了

扫描二维码关注公众号,回复: 5828747 查看本文章

进入到安装目录的bin目录
/home/smkapp/elasticsearch-6.2.2/bin
./elastucsearch -d

但是没能成功,查看日志
这里写图片描述
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
还要改一下配置
vi /etc/security/limits.conf
# End of file
*           soft   nofile       65536
*           hard   nofile       131072
*           soft    memlock unlimited
*           hard    memlock unlimited
*           hard    nproc   4096
*           soft    nproc   4096

重新登录 生效

vi /etc/sysctl.conf

vm.max_map_count=262144
vm.swappiness=1

用命令sysctl -p 生效

再次./elastucsearch -d
然后就可以了。
但是我们还忘记了一个插件 中文分词器

中文分词器 elasticsearch-analysis-ik

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-6.2.2.zip
这个安装比较简单,直接下载好了 zip 包,直接解压到elasticsearch的安装目录下面的plugins 目录就行了
/home/smkapp/elasticsearch-6.2.2/plugins/elasticsearch-ik
这里写图片描述

sudo chown -R es:smkapp elasticsearch-6.2.2/
再次修改一下文件夹的权限

./elasticserch -d
启动
这里写图片描述
ik分词器以及完美的加载进去了。

用同样的方法安装另外一台服务器

ik 带有两个分词器

ik_max_word :会将文本做最细粒度的拆分;尽可能多的拆分出词语
ik_smart:会做最粗粒度的拆分;已被分出的词语将不会再次被其它词语占有

ik_max_word,这种分词会把词句分为最小和各种组合:
举例:我想去少年宫
分词是: 我,想,去,少,年,宫
用户查找的时候,输入任何一个包含的词句都会查找的到记录,

使用ik_smart: 会分词:想去,少年宫

用户输入 少年,会查不到记录。

猜你喜欢

转载自blog.csdn.net/walle167/article/details/80705521
今日推荐