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

配置最大可打开文件数:

图片.png
DefaultLimitNOFILE=65535   
* hard nofile 65535
* soft nofile 65535

配置elsaticsearch.yml

图片.png
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下载。
解压缩,进入文件夹。
先修改配置(也可以不修改,只不过有告警):

图片.png

然后在文件夹中执行:

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
打开浏览器: 图片.png

说明:也可以用plugin -install mobz/elasticsearch-head来在线安装

下面是另外一个索引有数据的情况:


图片.png

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$ 

效果:


图片.png

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


图片.png

Sense是Marvel内置的一个插件

1. 5 中文分词器安装(IK Analyzer)

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

图片.png

从这下载太慢,我最后是从csdn上一个不要积分的地方下的


图片.png

然后重启es即可

通过kibana测试一下: 图片.png

2. 创建

2. 1创建Index

2.1.1 用Restful接口创建

创建之前是这样的:

图片.png
创建一个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:~$ 

创建后的效果

图片.png

2.1.2 用图形界面创建

图片.png
效果为: 图片.png

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" }
}
}
}'
图片.png

3. 有关Analyzer

图片.png

3.1 分类

3.1.1 Character filters类型

3.1.2 Tokenizers类型

3.1.3 Token filters类型

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安装后的配置

image.png
image.png
image.png
image.png
image.png
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默认文字是英文,变更成中文
image.png
上一篇下一篇

猜你喜欢

热点阅读