ElasticSearch及其插件的安装(二)

来源:互联网 发布:linux 修改密码文件 编辑:程序博客网 时间:2024/05/16 06:51

ElasticSearch安装
1.http://www.elasticsearch.org/下载所需的ElastiSearch版本。
2.移动下载的压缩包到安装目录 我的目录是/usr/local/

 sudo  mv  elasticsearch-x-x-x  /usr/local/

3.进入/usr/local/解压下载文

sudo    tar  -zxvf  elasticsearch-x-x-x 

4.cd到/usr/local/elasticsearchx-x-x/bin/,执行elasticsearch启动。

 ./elasticsearch  

5.此时打开网页http:// localhost:9200 出现一下内容为安装成功

 {             "status" : 200,             "name" : "node_yang",             "cluster_name" : "elasticsearch",             "version" : {             "number" : "1.7.2",             "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",             "build_timestamp" : "2015-09-14T09:49:53Z",             "build_snapshot" : false,             "lucene_version" : "4.10.4"         },            "tagline" : "You Know, for Search"        }

6.使用curl -XPOST localhost:9200/_shutdown关闭ES。
7.或者使用ctrl + c 关闭

ElasticSearch的基本配置(这部分配置可以不理会,取默认值)
1.编辑文件/usr/local/elasticsearchx-x-x/conf/elasticsearcy.yml
2.cluster.name:集群名称,es可以自我发现,拥有相同集群名字的es会构成集群。
3 node.name:节点名称,当前节点的名字。唯一。
4.node.master:是否允许当前节点成为master。
5.node.data:是否允许当前节点存储数据。
6.index.number_of_shards:一个索引默认的shard数量。
7.index.number_of_replicas:一个索引默认的副本数量。
8.path.data:数据存储.
9.path.log:日志存储。
10.bootstrap.mlockall:是否只使用内存(不使用swap)。
11.network.bind_host:设置绑定的ip地址,用于访问es。
12.network.publish_host:与其他node通信的地址,用于cluster间数据传输。

插件安装(head、bigdesk、ik-analyzer)
head,一款H5的数据查看客户端:
1 在cd /usr/local/elasticsearchx-x-x/bin/下执行

 ./plugin -install mobz/elasticsearch-head 

bigdesk,状态查看客户端:
2 在cd /usr/local/elasticsearchx-x-x/bin/下执行

./plugin -install lukas-vlcek/bigdesk/<bigdesk_version> 

3 如果不确定版本号可写为

./plugin -install lukas-vlcek/bigdesk/

ik-analyzer,中文分词器:
1.git clone https://github.com/medcl/elasticsearch-analysis-ik.git (下载的时候要注意版本号。不同版本的elasticsearch 对应不同的ik版本 如果版本不对就会报错。然后head 中集群安全会报红)
这里写图片描述
2.mvn clean install(前提是配置了maven)。
3.将target中的elasticsearch-analysis-ik-xxx.zip 或elasticsearch-analysis-ik-xxx.jar或复制到/usr/local/elasticsearchx-x-x/plugins/ik/。
并解压目录如下
这里写图片描述

4.复制elasticsearch-analysis-ik(git repository)中config目录下ik内容到/usr/local/elasticsearchx-x-x/config。目录如下
这里写图片描述
5.配置/usr/local/elasticsearchx-x-x/conf/elasticsearch.yml,在最下方加入:

################################## Analyzer ##yang############################index:  analysis:                       analyzer:            ik:          alias: [ik_analyzer]          type: org.elasticsearch.index.analysis.IkAnalyzerProvider      ik_max_word:          type: ik          use_smart: false      ik_smart:          type: ik          use_smart: true

head 测试

http://localhost:9200/_plugin/head/

bigdesk测试

http://localhost:9200/_plugin/bigdesk/

ik分词测试
1、创建一个索引,名为index。

curl -XPUT http://localhost:9200/index

2、为索引index创建mapping。

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'{    "fulltext": {             "_all": {            "analyzer": "ik"        },        "properties": {            "content": {                "type" : "string",                "boost" : 8.0,                "term_vector" : "with_positions_offsets",                "analyzer" : "ik",                "include_in_all" : true            }        }    }}'

3、测试

curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '{"text":"世界如此之大"}'

显示结果如下:

{  "tokens" : [ {    "token" : "text",    "start_offset" : 4,    "end_offset" : 8,    "type" : "ENGLISH",    "position" : 1  }, {    "token" : "世界",    "start_offset" : 11,    "end_offset" : 13,    "type" : "CN_WORD",    "position" : 2  }, {    "token" : "如此",    "start_offset" : 13,    "end_offset" : 15,    "type" : "CN_WORD",    "position" : 3  }, {    "token" : "之大",    "start_offset" : 15,    "end_offset" : 17,    "type" : "CN_WORD",    "position" : 4  } ]}
0 0
原创粉丝点击