ES安装
2020-04-16 本文已影响0人
逸章
这里给出了索引核心实现的简单说明,可以参考:https://blog.csdn.net/CrankZ/article/details/80615789
image.png
1. 安装
1.1 Node.js和NPM安装
yay@yay-ThinkPad-T470-W10DG:~/software/elasticsearch-7.6.2/bin$ sudo apt install nodejs
yay@yay-ThinkPad-T470-W10DG:~/software/elasticsearch-7.6.2/bin$ sudo apt install libssl1.0-dev nodejs-dev node-gyp npm
1.2 Elasticsearch安装和启动
配置vm.max_map_count
在 /etc/sysctl.conf文件最后添加一行:
vm.max_map_count=262144
配置最大可打开文件数:

DefaultLimitNOFILE=65535
* hard nofile 65535
* soft nofile 65535
配置elsaticsearch.yml

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, X-User"
注意上面的key和value间的空格不能删除
启动:
下面的命令是在把elasticsearch的bin目录加入path的基础上执行的
yay@yay-ThinkPad-T470-W10DG:~$ elasticsearch
1.3 安装Elasticsearch-head
从https://github.com/mobz/elasticsearch-head下载。
解压缩,进入文件夹。
先修改配置(也可以不修改,只不过有告警):

然后在文件夹中执行:
root@yay-ThinkPad-T470-W10DG:/home/yay/software/elastersearch-head/elasticsearch-head-master# npm install --no-optional
启动:
root@yay-ThinkPad-T470-W10DG:/home/yay/software/elastersearch-head/elasticsearch-head-master# npm run start
打开浏览器:

说明:也可以用plugin -install mobz/elasticsearch-head来在线安装
下面是另外一个索引有数据的情况:

1.4 可选安装Marvel插件
使用plugin -i elasticsearch/marvel/latest命令
yay@yay-ThinkPad-T470-W10DG:~/software/elasticsearch-1.7.6/bin$ ./plugin -i elasticsearch/marvel/latest
-> Installing elasticsearch/marvel/latest...
Trying http://download.elasticsearch.org/elasticsearch/marvel/marvel-latest.zip...
Downloading ..................................................................................................................................................................................................................................................................................................DONE
Installed elasticsearch/marvel/latest into /home/yay/software/elasticsearch-1.7.6/plugins/marvel
yay@yay-ThinkPad-T470-W10DG:~/software/elasticsearch-1.7.6/bin$ curl http://127.0.0.1:9200/_nodes/_local/plugins
{"cluster_name":"elasticsearchWithHadoop","nodes":{"7Jg7vvVuTMmRmfR9uSkMJQ":{"name":"esWithHadoop Node","transport_address":"inet[/172.20.10.2:9300]","host":"yay-ThinkPad-T470-W10DG","ip":"127.0.1.1","version":"1.7.6","build":"c730b59","http_address":"inet[/172.20.10.2:9200]","plugins":[{"name":"marvel","version":"NA","description":"No description found.","url":"/_plugin/marvel/","jvm":false,"site":true}]}}}yay@yay-ThinkPad-T470-W10DG:~/software/elasticsearch-1.7.6/bin$
效果:

此时,你可以使用Sense浏览数据:

Sense是Marvel内置的一个插件
1. 5 中文分词器安装(IK Analyzer)
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

从这下载太慢,我最后是从csdn上一个不要积分的地方下的
图片.png
然后重启es即可

2. 创建
2. 1创建Index
2.1.1 用Restful接口创建
创建之前是这样的:

创建一个name为news的Index
yay@yay-ThinkPad-T470-W10DG:~$ curl -H "Content-Type: application/json" -X PUT "localhost:9200/news" -d '{
> "settings": {
> "index": {
> "number_of_shards": 2,
> "number_of_replicas": 1
> }
> }
> }'
{"acknowledged":true,"shards_acknowledged":true,"index":"news"}yay@yay-ThinkPad-T470-W10DG:~$
创建后的效果

2.1.2 用图形界面创建

效果为:

2.2 再创建type
curl -H "Content-Type: application/json" -X PUT "localhost:9200/news/public/_mapping" -d '{
"public" :{
"properties" :{
"Title" : {"type" : "text" },
"Content": {"type" : "text" },
"DOP": {"type" : "date" }
}
}
}'

3. 有关Analyzer

3.1 分类
3.1.1 Character filters类型
-
HTML stripper: strips the HTML tags out of the text.
"html_strip" -
Mapping char filter: convert a set of characters or strings to another set of characters or strings. 比如:
"mappings" : ["ph=>f", "qu=>q"]
3.1.2 Tokenizers类型
- The whitespace tokenizer
-
The shingle tokenizer: 比如每n个token组合成a single token. 比如Token generation for a 2Gram tokenizer :
"Latin America is a great place to go in summer"
=> { "Latin America" ,"America is" , "is a" , "a great" ,"great place" , "place to" , "to go" , "go in" ,"in summer" } - The lowercase tokenizer: This converts text into lowercase, thereby decreasing the index size(保证我们搜索时候不区分大小写).
3.1.3 Token filters类型
- The stop word token filter: 包括 words like "is", "the", as well as "and" that don't add facts to the statement, 它们只是为了语法正确性.
- The length token filter
- The stemmer token filter: 有些单词,比如 "learn", "learning", "learnt", 都是表示同一个单词,只不过时态不同(in different tenses)而已. Here, we only need to index the actual word "learn" for any of its tenses.
3.2 配置
curl -H "Content-Type: application/json" -X PUT "http://localhost:9200/wiki" -d '{
"index" : {
"number_of_shards" : 4,
"number_of_replicas" : 1 ,
"analysis":{
"analyzer":{
"content" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : ["lowercase" , "stop" , "kstem"],
"char_filter" : ["html_strip"]
}
}
}
}
}'
二、ES7和Kibana7安装后的配置





cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
cluster.initial_master_nodes: ["node-1"]
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
server.port: 5601 #kibana端口
server.host: "192.168.56.56" #绑定的主机IP地址
elasticsearch.hosts: ["http://192.168.56.56:9200"] #elasticsearch的主机IP
kibana.index: ".kibana" #开启此选项
i18n.locale: "zh-CN" #kibana默认文字是英文,变更成中文
