设为首页 收藏本站
云服务器等爆品抢先购,低至4.2元/月
查看: 1682|回复: 0

[经验分享] Elasticsearch安装配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-17 10:20:40 | 显示全部楼层 |阅读模式
环境配置
1
2
3
4
5
操作系统:Cent OS 6.5
ElasticSearch:2.4.3
JDK:1.7
maven:3.3.9
elasticsearch-analysis-ik:1.4.1




1、首先要把jdk安装好,然后下载elasticsearch-2.3.4.tar.gz
1
wget https://download.elastic.co/elas ... search-2.3.4.tar.gz



2、解压下载好的elasticsearch-2.3.4.tar.gz
1
2
3
4
[iyunv@localhost opt]# cd /opt/
[iyunv@localhost opt]# ls
elasticsearch-2.3.4.tar.gz  git-1.8.3.2.tar.gz
[iyunv@localhost opt]# tar zxvf elasticsearch-2.3.4.tar.gz



3、创建用户和用户组(elasticsearch 2.0.0版本后不能以root用户启动。)
1
2
[iyunv@localhost opt]# groupadd elsearch
[iyunv@localhost opt]# useradd elsearch -g elsearch -p elasticsearch



4、把解压好的目录移动到/usr/local/elasticsearch
1
[iyunv@localhost opt]# mv elasticsearch-2.3.4 /usr/local/elasticsearch



5、设置权限
1
chown -R elsearch:elsearch  /usr/local/elasticsearch



6、安装es-head插件
1
2
[iyunv@localhost plugins]# cd /usr/local/elasticsearch/bin/
[iyunv@localhost plugins]# ./plugin –install mobz/elasticsearch-head



7、在浏览器中输入http://localhost:9200,http://localhost:9200/_plugin/head/如下图所示则ES启动成功。
QQ截图20161017102019.png

8、若要停止服务,则输入sh elasticsearch stop
1
2
[iyunv@localhost opt]# cd /usr/local/elasticsearch/bin
[iyunv@localhost opt]# sh elasticsearch stop



9、安装ik中文分词,首先要安装java 和 elasticsearch
(1)安装maven

1
2
3
[iyunv@localhost opt]# tar zxvf apache-maven-3.3.9-bin.tar.gz
[iyunv@localhost opt]# mv apache-maven-3.3.9 /usr/local/maven
[iyunv@localhost opt]# vim /etc/profile



1
2
3
export PATH=$PATH:$JAVA_HOME/bin
export M2_HOME=/usr/local/maven
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin



1
[iyunv@localhost opt]# source /etc/profile



(2)安装elasticsearch-analysis-ik
1
2
3
4
5
6
[iyunv@localhost opt]# wget -c
[iyunv@localhost opt]# unzip master.zip
[iyunv@localhost opt]# cd elasticsearch-analysis-ik-master/  
[iyunv@localhost elasticsearch-analysis-ik-master]# cp -Rf config/* ik /usr/local/elasticsearch/config/
[iyunv@localhost elasticsearch-analysis-ik-master]# mvn package
[iyunv@localhost elasticsearch-analysis-ik-master]# /usr/local/elasticsearch/bin/plugin --install analysis-ik --url file:///alidata/download/elasticsearch-analysis-ik-master/target/releases/elasticsearch-analysis-ik-1.4.1.zip



(3)修改elasticsearch.yml,在该文件后面添加下面的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@localhost ~]# cd /usr/local/elasticsearch/config
[iyunv@localhost config]# vim elasticsearch.yml
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
index.analysis.analyzer.default.type: ik



(4)重新启动elasticsearch
1
[iyunv@localhost config]# /usr/local/elasticsearch/bin/elasticsearch -d



(5) ik分词测试,创建一个索引,名为index
1
[iyunv@localhost config]# curl -XPUT http://localhost:9200/index



为索引index创建mapping
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@localhost config]# 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
            }
        }
    }
}'



测试
1
2
3
4
[iyunv@localhost config]# curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"www.acp.com 教程太好了受益匪浅,望ttlsa越来越好"
}'



显示结果如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{
  "tokens" : [ {
    "token" : "text",
    "start_offset" : 4,
    "end_offset" : 8,
    "type" : "ENGLISH",
    "position" : 1
  }, {
    "token" : "www.acp.com",
    "start_offset" : 11,
    "end_offset" : 24,
    "type" : "LETTER",
    "position" : 2
  }, {
    "token" : "www",
    "start_offset" : 11,
    "end_offset" : 14,
    "type" : "ENGLISH",
    "position" : 3
  }, {
    "token" : "ttlsa",
    "start_offset" : 15,
    "end_offset" : 20,
    "type" : "ENGLISH",
    "position" : 4
  }, {
    "token" : "com",
    "start_offset" : 21,
    "end_offset" : 24,
    "type" : "ENGLISH",
    "position" : 5
  }, {
    "token" : "教程",
    "start_offset" : 25,
    "end_offset" : 27,
    "type" : "CN_WORD",
    "position" : 6
  }, {
    "token" : "太好了",
    "start_offset" : 27,
    "end_offset" : 30,
    "type" : "CN_WORD",
    "position" : 7
  }, {
    "token" : "太好",
    "start_offset" : 27,
    "end_offset" : 29,
    "type" : "CN_WORD",
    "position" : 8
  }, {
    "token" : "好了",
    "start_offset" : 28,
    "end_offset" : 30,
    "type" : "CN_WORD",
    "position" : 9
  }, {
    "token" : "受益匪浅",
    "start_offset" : 30,
    "end_offset" : 34,
    "type" : "CN_WORD",
    "position" : 10
  }, {
    "token" : "受益",
    "start_offset" : 30,
    "end_offset" : 32,
    "type" : "CN_WORD",
    "position" : 11
  }, {
    "token" : "匪",
    "start_offset" : 32,
    "end_offset" : 33,
    "type" : "CN_CHAR",
    "position" : 12
  }, {
    "token" : "浅",
    "start_offset" : 33,
    "end_offset" : 34,
    "type" : "CN_CHAR",
    "position" : 13
  }, {
    "token" : "望",
    "start_offset" : 35,
    "end_offset" : 36,
    "type" : "CN_CHAR",
    "position" : 14
  }, {
    "token" : "ttlsa",
    "start_offset" : 36,
    "end_offset" : 41,
    "type" : "ENGLISH",
    "position" : 15
  }, {
    "token" : "越来越好",
    "start_offset" : 41,
    "end_offset" : 45,
    "type" : "CN_WORD",
    "position" : 16
  }, {
    "token" : "越来越",
    "start_offset" : 41,
    "end_offset" : 44,
    "type" : "CN_WORD",
    "position" : 17
  }, {
    "token" : "越来",
    "start_offset" : 41,
    "end_offset" : 43,
    "type" : "CN_WORD",
    "position" : 18
  }, {
    "token" : "越好",
    "start_offset" : 43,
    "end_offset" : 45,
    "type" : "CN_WORD",
    "position" : 19
  } ]
}







运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-287371-1-1.html 上篇帖子: Elasticsearch Index API & Aggregations API & Query DSL 下篇帖子: ElasticSearch搜索引擎使用—从0到1
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表