Elasticsearch 5.5 入门必会之Java client(二)java
Elasticsearch 5.5 SQL语句转Java Client 及相关注意事项(三)node
1.linux添加单独用户,由于ES不能使用root用户启动,会报错!linux
java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.1.jar:5.5.1] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.1.jar:5.5.1]
groupadd search #建立用户 useradd search-g search #设置密码 passwd search #建立es安装目录,而且用户受权 mkdir /opt/elasticsearch cd /opt chown -R search:search elasticsearch
2. 切换到search用户,而后去官网下载es安装包,解压到/opt/elasticsearch目录解压。 git
3. 启动ESgithub
cd elasticsearch/bin ./elasticsearch
4.你可能遇到以下问题:npm
#这个是linux内核不支持 syscall filter,centos 7以上听说没这个问题,可是不影响使用 unable to install syscall filter: java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed #经过配置后面第[4]个好像就没有报错了
#linux max file配置太低 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] #经过配置 /etc/security/limits.conf 解决 * soft nofile 65536 * hard nofile 65536 * soft nproc 2048 * hard nproc 4096
#使用最大线程数太低 [2]: max number of threads [1024] for user [search] is too low, increase to at least [2048] #经过配置/etc/security/limits.d/90-nproc.conf 解决 * soft nproc 2048
#虚拟内存配置过低 [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] #经过配置 /etc/sysctl.conf 追加一行以下解决 vm.max_map_count=655360
#system call filters安装失败 [4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk #解决办法经过配置 /opt/elasticsearch/config/elasticsearch.yml参数解决 bootstrap.memory_lock: false bootstrap.system_call_filter: false
5. ES启动JVM配置,在config/jvm.options调整了一下jvm参数bootstrap
-Xms8g -Xmx8g
6. 个人master的ES启动配置参数,集群服务器的115这个节点也是和一下配置相似,只是IP不同centos
cluster.name: onesearch node.name: master-node1 path.logs: /home/search/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.1.1.114 network.bind_host: 10.1.1.114 network.publish_host: 10.1.1.114 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" node.master: true node.data: true #我配置了两个节点 discovery.zen.ping.unicast.hosts: ["10.1.1.114","10.1.1.115"]
7. OK,如今启动master节点,您会看到日志就表明启动成功了浏览器
[2017-08-11T15:25:24,405][INFO ][o.e.n.Node ] [ZikeeFb] started
8. 而后在启动另一个master节点的时候,您会看到日志里面提示另一个节点已经链接,由于ES是自动发现节点的。bash
1. 安装head插件,在使用ES 5.5的时候,我在网上搜了一些文档,可是都过期了,5.5安装head插件还不如说是本身单独安装了一个node 而后跑了一个node程序去经过http接口访问es接口。网上文档都是一概的把插件解压到ES的plugins目录里面,然而,我并无跑起来,或许是我本身的问题。下面介绍单独跑node来部署head程序吧
#安装node,安装目录你本身随意定了 wget https://nodejs.org/dist/v6.11.2/node-v6.11.2-linux-x64.tar.xz #配置nodejs环境变量 编辑 /etc/profile ,我直接使用的root安装,这个所谓,主要安装node相关工具须要一些权限 export PATH=/root/node-v6.11.2-linux-x64/bin:$PATH #安装git,这里注意下,若是是自动安装git 1.7的话 clone会报403错,我是本身手动下载安装了1.9 yum -y install git #clone head插件源码 git clone git clone git://github.com/mobz/elasticsearch-head.git #进入head插件目录执行 npm install grunt --save npm install #这个慢得一批 #安装grunt cli npm install -g grunt-cli #编辑Gruntfile.js里面的hostname connect: { server: { options: { port: 9100, base: '.', hostname: '0.0.0.0', ##这里,这里 keepalive: true } } } #编辑_site/app.js ,找到下面这一行,加行后面一截,若是IP不同,你本身修改,我是和master部署到同一个节点的 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; ## <-注意这里,本身加 #启动head程序 grunt server -d #而后访问 http://IP:9100/ 便可看到简洁的界面
head程序(我不叫插件,由于我单独部署的)界面以下:
2. ik分词器插件安装,顺便说一句,使用yml配置方式来配置分词器已经在5.5不适用,启动会报错
#传说用的./elasticsearch-plugin install 方式来安装插件,我也没安装成功 #ik的github上提供了 ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip 我没试,由于我用的另一种方式安装成功了 #下载https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.2/elasticsearch-analysis-ik-5.5.2.zip #在/opt/elasticsearch/plugins/下 建立ik目录 mkdir ik #而后把 elasticsearch-analysis-ik-5.5.2.zip 解压到ik目录,重启ES便可
#!!注意 下面链接里面的 megacorp 是我经过head程序手动建立了一个索引 #浏览器访问http://10.1.1.114:9200/megacorp/_analyze?analyzer=standard&pretty=true&text=我是卡尔码农 #获得一下访问结果 { "tokens" : [ { "token" : "我", "start_offset" : 0, "end_offset" : 1, "type" : "<IDEOGRAPHIC>", "position" : 0 }, { "token" : "是", "start_offset" : 1, "end_offset" : 2, "type" : "<IDEOGRAPHIC>", "position" : 1 }, { "token" : "卡", "start_offset" : 2, "end_offset" : 3, "type" : "<IDEOGRAPHIC>", "position" : 2 }, { "token" : "尔", "start_offset" : 3, "end_offset" : 4, "type" : "<IDEOGRAPHIC>", "position" : 3 }, { "token" : "码", "start_offset" : 4, "end_offset" : 5, "type" : "<IDEOGRAPHIC>", "position" : 4 }, { "token" : "农", "start_offset" : 5, "end_offset" : 6, "type" : "<IDEOGRAPHIC>", "position" : 5 } ] }
#浏览器请求http://10.1.1.114:9200/megacorp/_analyze?analyzer=ik_smart&pretty=true&text=我是卡尔码农 #其中analyzer=ik_smart能够换成analyzer=ik_max_word 是ik提供两种分词方式 #获得返回结果 { "tokens" : [ { "token" : "我", "start_offset" : 0, "end_offset" : 1, "type" : "CN_CHAR", "position" : 0 }, { "token" : "是", "start_offset" : 1, "end_offset" : 2, "type" : "CN_CHAR", "position" : 1 }, { "token" : "卡尔", "start_offset" : 2, "end_offset" : 4, "type" : "CN_WORD", "position" : 2 }, { "token" : "码", "start_offset" : 4, "end_offset" : 5, "type" : "CN_CHAR", "position" : 3 }, { "token" : "农", "start_offset" : 5, "end_offset" : 6, "type" : "CN_CHAR", "position" : 4 } ] }
仍是有一点效果,其实搜索引擎分词颇有讲究,如今我所了解的医疗行业的分词已经有公司经过机器学习病例样生成好用的字典给ik来使用,虽然上面"卡尔"被认为在一块儿,可是“码农”很明显也应该合并一下,这个咱们均可以经过配置ik的字典来解决这个问题,当前不讨论这个问题了。
当初有接触过lucene、后来接触compass、再后来接触TB的终搜、solrj包括如今的ES,搜索引擎在各行业中都发挥这重要做用,后面我会提到ES在咱们单位的使用实战状况。感谢您的关注!