es官网: ElasticSearch官网
环境
- IP: 192.168.180.46
- 系统: CentOS 7.6
HostName | IP | DES |
---|---|---|
test1 | 192.168.180.46 | 主控机 |
test2 | 192.168.180.47 | node-1 |
test3 | 192.168.180.48 | node-2 |
test4 | 192.168.181.18 | node-3 |
一、安装elasticsearch
参照:下文中的 常见问题
修改操作系统参数
1.创建用户
[root@test1 ~]# useradd elasticsearch
[root@test1 ~]# passwd elasticsearch
输入密码
passwd:所有的身份验证令牌已经成功更新。
[root@test1 ~]#
[root@test1 ~]# visudo
elasticsearch ALL=(ALL) NOPASSWD: ALL
[root@test1 ~]#
[root@test1 ~]# su - elasticsearch
[elasticsearch@test1 ~]$
2. 下载/解压
[elasticsearch@test1 deploy]$ pwd
/home/elasticsearch/deploy
[elasticsearch@test1 deploy]$
[elasticsearch@test1 ~]$ curl -L -O https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
[elasticsearch@test1 deploy]$
[elasticsearch@test1 deploy]$ tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz -C 指定目录
3. 替换配置文件中如下部分属性
注意: 不修改配置,是不可以外网访问的,如下属性都是必须要配置的
[elasticsearch@test1 deploy]$ vim elasticsearch-7.3.2/config/elasticsearch.yml
#默认是随机字符串,可默认
node.name: node-1
#可填写本机ip,也可0.0.0.0
network.host: 0.0.0.0
#可修改es访问端口,默认9200,可默认
http.port: 9200
# 允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
# ES数据和日志存放位置
path.data: /home/elasticsearch/elasticsearch-7.3.2/data
path.logs: /home/elasticsearch/elasticsearch-7.3.2/logs
# 快照路径
path.repo: /home/elasticsearch/elasticsearch-7.3.2/snapshots
cluster.initial_master_nodes: ['node-1']
##优化参数
indices.memory.index_buffer_size: 20%
indices.query.bool.max_clause_count: 100000000
4. 修改 ElasticSearch内存:
[elasticsearch@test1 ~]$ vim elasticsearch-7.3.2/config/jvm.options
5. 后台 启动 ElasticSearch
[elasticsearch@test1 ~]$ ./deploy/elasticsearch-7.3.2/bin/elasticsearch -d
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[elasticsearch@test1 ~]$
6. 查看启动是否成功
[elasticsearch@test1 ~]$ curl 192.168.180.47:9200
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "GwWYck6bRTyyMgXFxZW9Ew",
"version" : {
"number" : "7.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
"build_date" : "2019-09-27T08:36:48.569419Z",
"build_snapshot" : false,
"lucene_version" : "8.2.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[elasticsearch@test1 ~]$
7、杀死es进程
ps -ef | grep elastic
kill -9 进程id
二、安装es-head
1、安装node.js
删除旧的 nodejs 版本:
$ yum remove nodejs
第1步 - 添加Node.js Yum存储库
首先,您需要在Node.js官方网站提供的系统中启用node.js yum存储库。您还需要开发工具来构建要在系统上安装的本机加载项。
yum clean all && yum makecache fast
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -
稳定发布: -
yum clean all && yum makecache fast
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
第2步 - 在CentOS上安装Node.js.
在系统中添加yum存储库后,让我们安装Node.js包。NPM也将与node.js一起安装。此命令还将在您的系统上安装许多其他依赖包。
yum install nodejs
node -v
2、下载/解压
下载地址:https://github.com/mobz/elasticsearch-head/tree/v5.0.0
[elasticsearch@test1 deploy]$ wget https://codeload.github.com/mobz/elasticsearch-head/zip/v5.0.0 -O es-head.zip
[elasticsearch@test1 deploy]$
[elasticsearch@test1 deploy]$ unzip -o es-head.zip
[elasticsearch@test1 deploy]$
3、初始化
[elasticsearch@test1 elasticsearch-head-5.0.0]$ pwd
/home/elasticsearch/deploy/elasticsearch-head-5.0.0
[elasticsearch@test1 elasticsearch-head-5.0.0]$
[elasticsearch@test1 elasticsearch-head-5.0.0]$ npm i
[elasticsearch@test1 elasticsearch-head-5.0.0]$
[elasticsearch@test1 elasticsearch-head-5.0.0]$ nohup npm start &
三、离线安装分词器
(截止到目前为止,分词准确性从高到低依次是: hanlp> ansj >结巴>IK>Smart Chinese Analysis)
基于ElasticSearch7.3.2安装
官方下载地址:https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases
1. 下载分词器
[elasticsearch@test1 download]$ pwd
/home/elasticsearch/download
[elasticsearch@test1 download]$ wget https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.3.2/elasticsearch-analysis-hanlp-7.3.2.zip
2.安装到ES
2.1 单机安装HanLP插件到ES
[elasticsearch@test1 elasticsearch-7.3.2]$ ./bin/elasticsearch-plugin install file:///home/elasticsearch/download/elasticsearch-analysis-hanlp-7.3.2.zip
-> Downloading file:///home/elasticsearch/download/elasticsearch-analysis-hanlp-7.3.2.zip
[=================================================] 100%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.io.FilePermission <<ALL FILES>> read,write,delete
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission setContextClassLoader
* java.net.SocketPermission * connect,resolve
* java.util.PropertyPermission * read,write
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.
Continue with installation? [y/N]y
-> Installed analysis-hanlp
[elasticsearch@test1 elasticsearch-7.3.2]$
2.2 修改elasticsearch-7.3.2/config目录下的jvm.options文件,最后一行添加(相对路径不行改成绝对路径)
#相对路径
-Djava.security.policy=plugins/analysis-hanlp/plugin-security.policy
#绝对路径
-Djava.security.policy=/home/elasticsearch/deploy/elasticsearch-7.3.2/plugins/analysis-hanlp/plugin-security.policy
2.3 配置修改(如果不好用修改成绝对路径,默认是相对路径)
修改elasticsearch-7.3.2/config/analysis-hanlp目录下的hanlp.properties文件,
修改其中root的属性
#需要执行上一步才能生成这个文件夹
vim elasticsearch-7.3.2/config/analysis-hanlp/hanlp.properties
# Root path of data #绝对路径
root=/home/elasticsearch/deploy/elasticsearch-7.3.2/plugins/analysis-hanlp/
#root=plugins/analysis-hanlp/
3. 重启ES
4. 查看安装是否成功
curl -X GET "http://192.168.180.47:9200/_analyze" -H "Content-Type: application/json" -d '
{
"text": "我们大家的中华人民共和国"
}'
# 默认不使用分词器的查询结果
{
"tokens": [
{
"token": "我",
"start_offset": 0,
"end_offset": 1,
"type": "<IDEOGRAPHIC>",
"position": 0
},
{
"token": "们",
"start_offset": 1,
"end_offset": 2,
"type": "<IDEOGRAPHIC>",
"position": 1
},
{
"token": "大",
"start_offset": 2,
"end_offset": 3,
"type": "<IDEOGRAPHIC>",
"position": 2
},
{
"token": "家",
"start_offset": 3,
"end_offset": 4,
"type": "<IDEOGRAPHIC>",
"position": 3
},
{
"token": "的",
"start_offset": 4,
"end_offset": 5,
"type": "<IDEOGRAPHIC>",
"position": 4
},
{
"token": "中",
"start_offset": 5,
"end_offset": 6,
"type": "<IDEOGRAPHIC>",
"position": 5
},
{
"token": "华",
"start_offset": 6,
"end_offset": 7,
"type": "<IDEOGRAPHIC>",
"position": 6
},
{
"token": "人",
"start_offset": 7,
"end_offset": 8,
"type": "<IDEOGRAPHIC>",
"position": 7
},
{
"token": "民",
"start_offset": 8,
"end_offset": 9,
"type": "<IDEOGRAPHIC>",
"position": 8
},
{
"token": "共",
"start_offset": 9,
"end_offset": 10,
"type": "<IDEOGRAPHIC>",
"position": 9
},
{
"token": "和",
"start_offset": 10,
"end_offset": 11,
"type": "<IDEOGRAPHIC>",
"position": 10
},
{
"token": "国",
"start_offset": 11,
"end_offset": 12,
"type": "<IDEOGRAPHIC>",
"position": 11
}
]
}
分词器使用测试
curl -X GET "http://192.168.180.47:9200/_analyze" -H "Content-Type: application/json" -d '
{
"text": "我们大家的中华人民共和国",
"analyzer": "hanlp"
}'
# 使用分词器后的查询结果
{
"tokens": [
{
"token": "我们",
"start_offset": 0,
"end_offset": 2,
"type": "rr",
"position": 0
},
{
"token": "大家",
"start_offset": 2,
"end_offset": 4,
"type": "rr",
"position": 1
},
{
"token": "的",
"start_offset": 4,
"end_offset": 5,
"type": "ude1",
"position": 2
},
{
"token": "中华人民共和国",
"start_offset": 5,
"end_offset": 12,
"type": "ns",
"position": 3
}
]
}