您的位置:首页 > 大数据

大数据学习[06]:elasticsearch5.6.1初探

2017-09-21 21:29 483 查看


摘要:主要初步接触一下ES及其相关组件。安装的ES版本为5.6.1,先在单节点上运行,初步探一探。然后安装IK,用来作中文的分词的,接着安装X-pack用来作各集群的监控的,再安装Kibana, 用来显示数据的。

前置

代码下载:git源码安装(linux)

请求工具:Curl安装(Linux)

JDK环境:大数据学习前夕[02]:JDK安装升级

elasticsearch

下载:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.1.zip[/code] 
解压:

unzip elasticsearch-5.6.1.zip


启动

cd elasticsearch-5.6.1/
./bin/elasticsearch


可能在启动时会出现错误,由于系统版本低引起的。可以不管,不影响使用。

java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:351) ~[elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:639) ~[elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:258) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:113) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.6.0.jar:5.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.6.0.jar:5.6.0]


IK

源码:https://github.com/medcl/elasticsearch-analysis-ik

也有release版本:https://github.com/medcl/elasticsearch-analysis-ik/releases

下载release版

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.1/elasticsearch-analysis-ik-5.6.1.zip[/code] 
安装,引用官网:

1.download or compile

下载与编译

• optional 1 - download pre-build package from here:

选择1,从下面提前下载build好的包:

https://github.com/medcl/elasticsearch-analysis-ik/releases

unzip plugin to folder your-es-root/plugins/

unzip 插件到’你的es根/plugins/‘目录下

• optional 2 - use elasticsearch-plugin to install ( version > v5.5.1 ):

选择2,使用ES自带的elasticsearch-plugin去安装(版本>v5.51):

./bin/elasticsearch-plugin install

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.1/elasticsearch-analysis-ik-5.6.1.zip

2.restart elasticsearch

还有一种是采用在本地文件来安装的,先下载好,然后用plugin来安装的,上面的第二种总是由于网络问题,安装得很慢。如下安装:
[hadoop@hadoop01 elasticsearch-5.6.1]$ ./bin/elasticsearch-plugin install file:/home/hadoop/elasticsearch-analysis-ik-5.6.1.zip
-> Downloading file:/home/hadoop/elasticsearch-analysis-ik-5.6.1.zip
[=================================================] 100%
-> Installed analysis-ik


测试:

[hadoop@hadoop01 config]$ curl --user elastic:changeme -XPUT 'http://localhost:9200/index?pretty'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "index"
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme -XPOST 'http://localhost:9200/index/fulltext/_mapping?pretty' -d'
> {
>         "properties": {
>             "content": {
>                 "type": "text",
>                 "analyzer": "ik_max_word",
>                 "search_analyzer": "ik_max_word"
>             }
>         }
>
> }'
{
"acknowledged" : true
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme  -XPOST http://localhost:9200/index/fulltext/1?pretty -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme  -XPOST http://localhost:9200/index/fulltext/2?pretty -d'
{"content":"公安部:各地校车将享最高路权"}
'
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme  -XPOST http://localhost:9200/index/fulltext/3?pretty -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme  -XPOST http://localhost:9200/index/fulltext/4?pretty -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "4",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
[hadoop@hadoop01 config]$ curl --user elastic:changeme -XPOST http://localhost:9200/index/fulltext/_search?pretty  -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'
{
"took" : 111,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.6099695,
"hits" : [
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "4",
"_score" : 0.6099695,
"_source" : {
"content" : "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
},
"highlight" : {
"content" : [
"<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
]
}
},
{
"_index" : "index",
"_type" : "fulltext",
"_id" : "3",
"_score" : 0.27179778,
"_source" : {
"content" : "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
},
"highlight" : {
"content" : [
"中韩渔警冲突调查:韩警平均每天扣1艘<tag1>中国</tag1>渔船"
]
}
}
]
}
}


Kibana

下载:

https://artifacts.elastic.co/downloads/kibana/kibana-5.6.1-linux-x86_64.tar.gz


解压:

tar -xzf kibana-5.6.1-linux-x86_64.tar.gz


配置:

vim $KIBANA_HOME/config/kibana.yml


设置elasticserch的URL,默认那个就可以,如果都安装在同一个机器;

启动:

[hadoop@testhdp01 kibana-5.6.1-linux-x86_64]$ ./bin/kibana
log   [07:37:38.848] [info][status][plugin:kibana@5.6.1] Status changed from uninitialized to green - Ready
log   [07:37:38.901] [info][status][plugin:elasticsearch@5.6.1] Status changed from uninitialized to yellow - Waiting for Elasticsearch
log   [07:37:38.921] [info][status][plugin:console@5.6.1] Status changed from uninitialized to green - Ready
log   [07:37:38.946] [info][status][plugin:metrics@5.6.1] Status changed from uninitialized to green - Ready
log   [07:37:39.109] [info][status][plugin:timelion@5.6.1] Status changed from uninitialized to green - Ready
log   [07:37:39.113] [info][listening] Server running at http://localhost:5601 log   [07:37:39.114] [info][status][ui settings] Status changed from uninitialized to yellow - Elasticsearch plugin is yellow
log   [07:37:44.118] [info][status][plugin:elasticsearch@5.6.1] Status changed from yellow to yellow - No existing Kibana index found
log   [07:37:45.873] [info][status][plugin:elasticsearch@5.6.1] Status changed from yellow to green - Kibana index ready
log   [07:37:45.874] [info][status][ui settings] Status changed from yellow to green - Ready


测试: 浏览器输入http://localhost:5601





了解更多参考:https://www.elastic.co/guide/en/kibana/current/getting-started.html

x-pack

安装01[如果网络慢,这个安装方法不太好]:

[hadoop@hadoop01 elasticsearch-5.6.1]$ bin/elasticsearch-plugin install x-pack
-> Downloading x-pack from elastic
[=================================================] 100%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.io.FilePermission \\.\pipe\* read,write
* java.lang.RuntimePermission accessClassInPackage.com.sun.activation.registries
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission setContextClassLoader
* java.lang.RuntimePermission setFactory
* java.security.SecurityPermission createPolicy.JavaPolicy
* java.security.SecurityPermission getPolicy
* java.security.SecurityPermission putProviderProperty.BC
* java.security.SecurityPermission setPolicy
* java.util.PropertyPermission * read,write
* java.util.PropertyPermission sun.nio.ch.bugLevel write
* javax.net.ssl.SSLPermission setHostnameVerifier
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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@        WARNING: plugin forks a native controller        @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This plugin launches a native controller that is not subject to the Java
security manager nor to system call filters.

Continue with installation? [y/N]y
-> Installed x-pack


安装02:

下载地址

https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-5.6.1.zip


安装

bin/elasticsearch-plugin install file:///path/to/file/x-pack-5.6.1.zip


同时也在kibana上安装:

bin/kibana-plugin install file:///path/to/file/x-pack-5.6.1.zip


官网的安装:

https://www.elastic.co/guide/en/kibana/5.6/installing-xpack-kb.html#installing-xpack-kb

重启ES;

重启kibana

bin/kibana
[hadoop@testhdp01 kibana-5.6.1-linux-x86_64]$ bin/kibana-plugin install file:///home/hadoop/liangr/x-pack-5.6.1.zip
Attempting to transfer from file:///home/hadoop/liangr/x-pack-5.6.1.zip
Transferring 160211259 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete


提示:

To verify X-Pack installation, point your web browser at http://localhost:5601/ to open Kibana. You should be prompted to log in to Kibana. To log in, you can use the built-in elastic user and the password changeme.

安装了X-pack,一会儿要登录这个用户名与密码{elastic:changeme}。



美美的登录{账号:elastic | 密码:changeme}



多了一个监控与用户的东西,可以修改密码的



另外:curl来查看下没有密码的情况

[hadoop@hadoop01 config]$ curl -XGET 'localhost:9200/_search?pretty'
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/_search?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/_search?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status" : 401
}


修正为:

curl --user elastic:changeme -XGET 'localhost:9200/_search?pretty'


后记:也尝试过用安装head,现在head不是简单的plugin安装了,它是一个nodejs项目,有一大堆的前端框架之类的东西,如果用head来监控的话,kibana也可以看了,初探完毕, 请多多指教。

附上一个ES1.2安装了head的图:



推荐资料

ES官网说明文档:

https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

ES权威指南

https://es.xiaoleilu.com/index.html

一堆资料集合

http://www.cnblogs.com/xing901022/p/4704319.html

【作者:happyprince; http://blog.csdn.net/ld326/article/details/78057145
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch 大数据