赞
踩
本文描述了ElasticSearch5.1.1集群部署过程,包括3个节点集群搭建过程,中文插件的安装,中途遇到问题的解决等等。
* 三台机器:*
序号 主机名称 IP地址 操作系统
1 c1 192.168.xxx.157 centos7
2 c2 192.168.xxx.158 centos7
3 c3 192.168.xxx.159 centos7
* 关闭防火墙*
[root@c3 ~]# service iptables stop
[root@c3 ~]# df –lh
为了避免磁盘使用不均而导致系统问题,因而先查看磁盘的分布情况。
/dev目录共83G,只使用了8%不到,因此可以将后续的所有文件和程序存放在此目录下。当然,这要根据你的实际情况而定。
安装包5.1.1
https://www.elastic.co/downloads/elasticsearch elasticsearch-5.1.1.tar.gz
查看配置hosts
[root@c3 bin]# more /etc/hosts
具体目录创建如下:
[root@c3 local]# mkdir /usr/local/elasticsearch
先将elasticsearch文件复制到/usr/local/elasticsearch文件夹下.
[root@c3 zookeeper]# tar -zxvf elasticsearch-5.1.1.tar.gz
- [root@c3 elasticsearch]# mkdir data
- [root@c3 elasticsearch]# mkdir logs
在/usr/local/elasticsearch/elasticsearch-5.1.1/config文件夹下,复制配置文件:
[root@c3 conf]# vim elasticsearch.yml
5.1 用户创建
创建用户组
[root@c3 ~]# groupadd elsearch
创建用户,用户elsearch 密码 cfca1234
[root@c3 ~]# useradd elsearch -g elsearch -p abc1234
进入目录:/usr/local
[root@c3 local]#chown -R elsearch:elsearch elasticsearch
- [root@c3 elasticsearch]# su elsearch
- [elsearch@c3 elasticsearch-5.1.1]$ bin/elasticsearch
登录地址 http://192.168.121.157:9200/
获得结果如下,说明单节点安装成功
从c3节点复制文件到另外两个节点
语句如下:
- [root@c3 ~]# scp -r /usr/local/elasticsearch root@c2:/usr/local
- [root@c3 ~]# scp -r /usr/local/elasticsearch root@c1:/usr/local
分别登录c1,c2,参考4.2修改elasticsearch.yml文件
分别在c1,c2执行章节5创建管理用户命令,
详见下图箭头所指之处。
Install IK
源码地址:https://github.com/medcl/elasticsearch-analysis-ik,Git clone下来。
mvn package 打包生成 elasticsearch-analysis-ik-5.1.1.jar
拷贝安装目录 /usr/local/elasticsearch/elasticsearch-5.1.1/plugins
报了一大串错误,其实只是一个警告。
解决:使用新Linux版本,就不会出现此类问题了。
解决:切换到root用户,编辑limits.conf 添加类似如下内容
[elsearch@c2 elasticsearch-5.1.1]$ su root
[root@c2 elasticsearch-5.1.1]# vim /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
解决:切换到root用户,进入limits.d目录下修改配置文件。
[root@c2 ~]# vim /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
解决:切换到root用户修改配置sysctl.conf
[root@c2 elasticsearch-5.1.1]# vim /etc/sysctl.conf
添加下面配置:
[root@c2 elasticsearch-5.1.1]#vm.max_map_count=262144
并执行命令:
[root@c2 elasticsearch-5.1.1]#sysctl -p
然后,重新启动elasticsearch,即可启动成功。
一般情况下是你的
discovery.zen.ping.unicast.hosts:[“192.168.. “,”192.168.. “] 这里写错了.
问题原因:因为Centos6不支持SecComp,而ES5.2.1默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。详见 :https://github.com/elastic/elasticsearch/issues/22899
解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
注意:关闭防火墙 或者开放9200端口
仍然使用elsearch登录,然后切换目录到elsearchsearch 所在的文件夹
$ cd elasticsearch-5.3.2
执行安装命令
$ sudo ./bin/elasticsearch-plugin install analysis-smartcn
卸载命名
$ sudo ./bin/elasticsearch-plugin remove analysis-smartcn
测试分词,使用"人人编程,世界和平"为例子,进行测试,使用站长工具 将例子中的字断转换成unicode编码的字断 在的终端中,调用下面方法,验证smartcn分词插件是否已经成功运行
$ curl -XGET 'localhost:9200/_analyze?pretty' -d '{"analyzer":"smartcn", "text": "\u4eba\u4eba\u7f16\u7a0b\uff0c\u4e16\u754c\u548c\u5e73"}'
出现如下结果证明分词成功。若没有添加"analyzer":"smartcn"
指定分词,将使用默认分词。对于中文来讲,将会把所有的字单独分出来。
- {
- "tokens" : [
- {
- "token" : "人人",
- "start_offset" : 0,
- "end_offset" : 2,
- "type" : "word",
- "position" : 0
- },
- {
- "token" : "编程",
- "start_offset" : 2,
- "end_offset" : 4,
- "type" : "word",
- "position" : 1
- },
- {
- "token" : "世界",
- "start_offset" : 5,
- "end_offset" : 7,
- "type" : "word",
- "position" : 3
- },
- {
- "token" : "和平",
- "start_offset" : 7,
- "end_offset" : 9,
- "type" : "word",
- "position" : 4
- }
- ]
- }

- $ cd elasticsearch-5.3.2
- $ vim ./config/elasticsearch.yml
根据需求修改一下节点:
- cluster.name: es-5.3-test #换个集群的名字,免得跟别人的集群混在一起
-
- node.name: node-es-101 #换个节点名字
-
- network.host: 0.0.0.0 #修改一下ES的监听地址,这样别的机器也可以访问
- http.port: 9200 #端口号,默认就好
-
-
- # 增加新的参数,这样head插件可以访问es
- http.cors.enabled: true
- http.cors.allow-origin: "*"
-
-
- #增加新的参数,这样ES可以通过外网进行访问,只设置network.host: 0.0.0.0 公网仍旧无法访问
- transport.host: localhost
- transport.tcp.port: 9300
-
- @注意,设置参数的时候:后面要有空格!

对于不熟悉Linux的人来讲,使用curl是个硬伤,所以 Chrome有个插件Sense可以帮我们很方便的操作Elasticsearch。国内需要FQ。
先来测试下分词
1配置
---------------------------------------------------------------------------
切换到root账户,按顺序依次执行以下命令
- $ wget -c https://artifacts.elastic.co/downloads/kibana/kibana-5.3.2-x86_64.rpm
- $ sha1sum kibana-5.3.2-x86_64.rpm
- $ sudo rpm --install kibana-5.3.2-x86_64.rpm
- $ whereis kibana
- kibana: /etc/kibana /usr/share/kibana
如果显示以上结果表明kibana已经正确安装完成,两个目录
/etc/kibana
为kibana config文件所在的目录
/usr/share/kibana
为程序所在的目录
修改Kibana的配置文件,允许公网访问
$ vim /etc/kibana/kibana.yml
将server.host
修改为
server.host: "0.0.0.0"
配置kibana能够自动启动
$ sudo chkconfig --add kibana
启动和停止
- $ sudo -i service kibana start
- $ sudo -i service kibana stop
接下来即可使用公网访问http://IP:5601
打开Kibana了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。