1.Elasticsearch 6.3.1 地址:

  1. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz

2.安装配置

1.拷贝

拷贝到服务器上,解压:tar -xvzf elasticsearch-6.3.1.tar.gz 。解压后路径:/home/elasticsearch-6.3.1

2.创建用户

创建用户,创建esdata目录,并赋予权限

  1. [root@bogon home]# adduser esuser
  2. [root@bogon home]# cd /home
  3. [root@bogon home]# mkdir -p esdata/data
  4. [root@bogon home]# mkdir -p esdata/log
  5. [root@bogon home]# chown -R esuser elasticsearch-6.3.1
  6. [root@bogon home]# chown -R esuser esdata

3.配置es节点

  1. [root@bogon esdata]# cat /home/elasticsearch-6.3.1/config/elasticsearch.yml
  2. # ======================== Elasticsearch Configuration =========================
  3. #
  4. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  5. # Before you set out to tweak and tune the configuration, make sure you
  6. # understand what are you trying to accomplish and the consequences.
  7. #
  8. # The primary way of configuring a node is via this file. This template lists
  9. # the most important settings you may want to configure for a production cluster.
  10. #
  11. # Please consult the documentation for further information on configuration options:
  12. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  13. #
  14. # ---------------------------------- Cluster -----------------------------------
  15. #
  16. # Use a descriptive name for your cluster:
  17. #
  18. cluster.name: my-application
  19. #
  20. # ------------------------------------ Node ------------------------------------
  21. #
  22. # Use a descriptive name for the node:
  23. #
  24. node.name: node-1
  25. #
  26. # Add custom attributes to the node:
  27. #
  28. node.attr.rack: r1
  29. #
  30. # ----------------------------------- Paths ------------------------------------
  31. #
  32. # Path to directory where to store the data (separate multiple locations by comma):
  33. #
  34. path.data: /home/esdata/data
  35. #
  36. # Path to log files:
  37. #
  38. path.logs: /home/esdata/log
  39. #
  40. # ----------------------------------- Memory -----------------------------------
  41. #
  42. # Lock the memory on startup:
  43. #
  44. bootstrap.memory_lock: true
  45. #
  46. # Make sure that the heap size is set to about half the memory available
  47. # on the system and that the owner of the process is allowed to use this
  48. # limit.
  49. #
  50. # Elasticsearch performs poorly when the system is swapping the memory.
  51. #
  52. # ---------------------------------- Network -----------------------------------
  53. #
  54. # Set the bind address to a specific IP (IPv4 or IPv6):
  55. # 允许访问的ip,0.0.0.0表示任意ip可以访问
  56. network.host: 0.0.0.0
  57. #
  58. # Set a custom port for HTTP:
  59. # 对外端口
  60. http.port: 9200
  61. #
  62. # For more information, consult the network module documentation.
  63. #
  64. # --------------------------------- Discovery ----------------------------------
  65. #
  66. # Pass an initial list of hosts to perform discovery when new node is started:
  67. # The default list of hosts is ["127.0.0.1", "[::1]"]
  68. # 集群其他节点IP,只有一个节点写本机ip
  69. discovery.zen.ping.unicast.hosts: ["host1", "host2"]
  70. #
  71. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
  72. #
  73. #discovery.zen.minimum_master_nodes:
  74. #
  75. # For more information, consult the zen discovery module documentation.
  76. #
  77. # ---------------------------------- Gateway -----------------------------------
  78. #
  79. # Block initial recovery after a full cluster restart until N nodes are started:
  80. # 集群节点数量
  81. gateway.recover_after_nodes: 1
  82. #
  83. # For more information, consult the gateway module documentation.
  84. #
  85. # ---------------------------------- Various -----------------------------------
  86. #
  87. # Require explicit names when deleting indices:
  88. #
  89. action.destructive_requires_name: true

3.配置系统参数

  1. [root@bogon bin]# vim /etc/security/limits.conf(在文件最后添加)
  2. esuser hard nofile 65536
  3. esuser soft nofile 65536
  4. esuser soft memlock unlimited
  5. esuser hard memlock unlimited

以上配置解决问题:

  1. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
  2. memory locking requested for elasticsearch process but memory is not locked

临时设置:sysctl -w vm.max_map_count=262144
永久修改:
修改vim /etc/sysctl.conf 文件,添加 “vm.max_map_count”设置
并执行:sysctl -p

以上配置解决问题:

  1. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
  1. [root@bogon logs]# visudo
  2. 。。。。。。。。
  3. ## Allow root to run any commands anywhere
  4. root ALL=(ALL) ALL
  5. esuser ALL=(ALL) ALL
  6. 。。。。。。。。

以上配置解决某些情况下无法读写的问题
ulimit -n和-u可以查看linux的最大进程数和最大文件打开数
1、vim /etc/security/limits.d/90-nproc.conf文件尾添加

  1. * soft nproc 204800
  2. * hard nproc 204800

2、vim /etc/security/limits.d/def.conf文件尾添加

  1. * soft nofile 204800
  2. * hard nofile 204800

这两个文件的设置将会覆盖前面的设置。重启后生效

  1. 以上配置解决问题:max number of threads [3895] for user [esuser] is too low, increase to at least [4096]

问题一:警告提示
[2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0]
at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0]
报了一大串错误,其实只是一个警告。
解决:使用新的centOS版本,centOS7就不会出现此类问题了。

问题二:报错
报错:
ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因:
这是在因为Centos6不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。
解决:
在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

4.启动

  1. [root@bogon ~]# cd /home/elasticsearch-6.3.1/bin/
  2. [root@bogon bin]# su esuser
  3. [esuser@bogon bin]$ ./elasticsearch
  4. [2018-07-17T10:17:30,139][INFO ][o.e.n.Node ] [node-1] initializing ...
  5. [2018-07-17T10:17:30,234][INFO ][o.e.e.NodeEnvironment ] [node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [22.1gb], net total_space [27.6gb], types [rootfs]
  6. [2018-07-17T10:17:30,234][INFO ][o.e.e.NodeEnvironment ] [node-1] heap size [1007.3mb], compressed ordinary object pointers [true]
  7. [2018-07-17T10:17:30,236][INFO ][o.e.n.Node ] [node-1] node name [node-1], node ID [cb69e4JjSBKeHJ9y-q-hNA]
  8. [2018-07-17T10:17:30,236][INFO ][o.e.n.Node ] [node-1] version[6.3.1], pid[26327], build[default/tar/eb782d0/2018-06-29T21:59:26.107521Z], OS[Linux/3.10.0-514.6.1.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_92/25.92-b14]
  9. [2018-07-17T10:17:30,236][INFO ][o.e.n.Node ] [node-1] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.F1Jh0AOB, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/home/elasticsearch-6.3.1, -Des.path.conf=/home/elasticsearch-6.3.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
  10. [2018-07-17T10:17:33,136][INFO ][o.e.p.PluginsService ] [node-1] loaded module [aggs-matrix-stats]
  11. [2018-07-17T10:17:33,136][INFO ][o.e.p.PluginsService ] [node-1] loaded module [analysis-common]
  12. [2018-07-17T10:17:33,137][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-common]
  13. 。。。。。。

5.验证

浏览器访问:http://192.168.20.115:9200/ (192.168.20.115是es服务器的IP,另外请确保9200端口能够被外部访问),返回:

  1. {
  2. "name" : "node-1",
  3. "cluster_name" : "my-application",
  4. "cluster_uuid" : "_na_",
  5. "version" : {
  6. "number" : "6.3.1",
  7. "build_flavor" : "default",
  8. "build_type" : "tar",
  9. "build_hash" : "eb782d0",
  10. "build_date" : "2018-06-29T21:59:26.107521Z",
  11. "build_snapshot" : false,
  12. "lucene_version" : "7.3.1",
  13. "minimum_wire_compatibility_version" : "5.6.0",
  14. "minimum_index_compatibility_version" : "5.0.0"
  15. },
  16. "tagline" : "You Know, for Search"
  17. }

ES系列一、CentOS7安装ES 6.3.1、集成IK分词器 - 图1

当然最方便的安装方法还是下载docker镜像,官方安装手册:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html 步骤:
1)下载镜像:docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.1
2)运行容器:docker run -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” docker.elastic.co/elasticsearch/elasticsearch:6.3.1

6.ElasticSearch Head安装

官方的模拟工具是控制台的curl,不是很直观,可以在chrome浏览器中安装head插件来作为请求的工具:head插件的地址:Cenos7安装ES head6.3.1
ES系列一、CentOS7安装ES 6.3.1、集成IK分词器 - 图2

7.集成集成Ikanalyzer分词器

1. 获取 ES-IKAnalyzer插件

一定和ES的版本一致( 6.3.1)
地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
ES系列一、CentOS7安装ES 6.3.1、集成IK分词器 - 图3

2. 安装插件

将 ik 的压缩包解压到 ES安装目录的plugins/目录下(最好把解出的目录名改一下,防止安装别的插件时同名冲突),然后重启ES。
ES系列一、CentOS7安装ES 6.3.1、集成IK分词器 - 图4

3. 扩展词库

扩展词典可以修改配置文件config/IKAnalyzer.cfg.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
  3. <properties>
  4. <comment>IK Analyzer 扩展配置</comment>
  5. <!--用户可以在这里配置自己的扩展字典 -->
  6. <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
  7. <!--用户可以在这里配置自己的扩展停止词字典-->
  8. <entry key="ext_stopwords">custom/ext_stopword.dic</entry>
  9. <!--用户可以在这里配置远程扩展字典 远程词库,可热更新,在一处地方维护-->
  10. <!-- <entry key="remote_ext_dict">words_location</entry> -->
  11. <!--用户可以在这里配置远程扩展停止词字典-->
  12. <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
  13. </properties>

4. 测试 IK

1.创建一个索引

  1. http://start.com:9200/iktest
  2. {
  3. "mappings":{
  4. "_doc":{
  5. "properties": {
  6. "content": {
  7. "type": "text",
  8. "analyzer": "ik_max_word",
  9. "search_analyzer": "ik_max_word"
  10. }
  11. }
  12. }
  13. }
  14. }

2.分词测试

  1. http://start.com:9200/_analyze
  2. {
  3. "analyzer":"ik_smart",
  4. "text":"天团S.H.E昨在两厅院艺文广场举办17万人露天音乐会,3人献唱多首经典好歌,让现场粉丝听得如痴如醉"
  5. }

结果:

  1. {
  2. "tokens": [
  3. {
  4. "token": "天",
  5. "start_offset": 0,
  6. "end_offset": 1,
  7. "type": "CN_CHAR",
  8. "position": 0
  9. },
  10. {
  11. "token": "团",
  12. "start_offset": 1,
  13. "end_offset": 2,
  14. "type": "CN_CHAR",
  15. "position": 1
  16. },
  17. {
  18. "token": "s.h.e",
  19. "start_offset": 2,
  20. "end_offset": 7,
  21. "type": "LETTER",
  22. "position": 2
  23. },
  24. {
  25. "token": "昨在",
  26. "start_offset": 7,
  27. "end_offset": 9,
  28. "type": "CN_WORD",
  29. "position": 3
  30. },
  31. {
  32. "token": "两厅",
  33. "start_offset": 9,
  34. "end_offset": 11,
  35. "type": "CN_WORD",
  36. "position": 4
  37. },
  38. {
  39. "token": "院",
  40. "start_offset": 11,
  41. "end_offset": 12,
  42. "type": "CN_CHAR",
  43. "position": 5
  44. },
  45. {
  46. "token": "艺文",
  47. "start_offset": 12,
  48. "end_offset": 14,
  49. "type": "CN_WORD",
  50. "position": 6
  51. },
  52. {
  53. "token": "广场",
  54. "start_offset": 14,
  55. "end_offset": 16,
  56. "type": "CN_WORD",
  57. "position": 7
  58. },
  59. {
  60. "token": "举办",
  61. "start_offset": 16,
  62. "end_offset": 18,
  63. "type": "CN_WORD",
  64. "position": 8
  65. },
  66. {
  67. "token": "17",
  68. "start_offset": 18,
  69. "end_offset": 20,
  70. "type": "ARABIC",
  71. "position": 9
  72. },
  73. {
  74. "token": "万人",
  75. "start_offset": 20,
  76. "end_offset": 22,
  77. "type": "CN_WORD",
  78. "position": 10
  79. },
  80. {
  81. "token": "露天",
  82. "start_offset": 22,
  83. "end_offset": 24,
  84. "type": "CN_WORD",
  85. "position": 11
  86. },
  87. {
  88. "token": "音乐会",
  89. "start_offset": 24,
  90. "end_offset": 27,
  91. "type": "CN_WORD",
  92. "position": 12
  93. },
  94. {
  95. "token": "3人",
  96. "start_offset": 28,
  97. "end_offset": 30,
  98. "type": "TYPE_CQUAN",
  99. "position": 13
  100. },
  101. {
  102. "token": "献",
  103. "start_offset": 30,
  104. "end_offset": 31,
  105. "type": "CN_CHAR",
  106. "position": 14
  107. },
  108. {
  109. "token": "唱",
  110. "start_offset": 31,
  111. "end_offset": 32,
  112. "type": "CN_CHAR",
  113. "position": 15
  114. },
  115. {
  116. "token": "多首",
  117. "start_offset": 32,
  118. "end_offset": 34,
  119. "type": "CN_WORD",
  120. "position": 16
  121. },
  122. {
  123. "token": "经典",
  124. "start_offset": 34,
  125. "end_offset": 36,
  126. "type": "CN_WORD",
  127. "position": 17
  128. },
  129. {
  130. "token": "好歌",
  131. "start_offset": 36,
  132. "end_offset": 38,
  133. "type": "CN_WORD",
  134. "position": 18
  135. },
  136. {
  137. "token": "让",
  138. "start_offset": 39,
  139. "end_offset": 40,
  140. "type": "CN_CHAR",
  141. "position": 19
  142. },
  143. {
  144. "token": "现场",
  145. "start_offset": 40,
  146. "end_offset": 42,
  147. "type": "CN_WORD",
  148. "position": 20
  149. },
  150. {
  151. "token": "粉丝",
  152. "start_offset": 42,
  153. "end_offset": 44,
  154. "type": "CN_WORD",
  155. "position": 21
  156. },
  157. {
  158. "token": "听得",
  159. "start_offset": 44,
  160. "end_offset": 46,
  161. "type": "CN_WORD",
  162. "position": 22
  163. },
  164. {
  165. "token": "如痴如醉",
  166. "start_offset": 46,
  167. "end_offset": 50,
  168. "type": "CN_WORD",
  169. "position": 23
  170. }
  171. ]
  172. }

对比standard分词器:

  1. http://start.com:9200/_analyze
  2. {
  3. "analyzer":"standard",
  4. "text":"天团S.H.E昨在两厅院艺文广场 举办17万人露 天音乐会,3人献唱多首 经典好歌,让现场 粉丝听得如痴如醉"
  5. }

结果:

  1. {
  2. "tokens": [
  3. {
  4. "token": "天",
  5. "start_offset": 0,
  6. "end_offset": 1,
  7. "type": "<IDEOGRAPHIC>",
  8. "position": 0
  9. },
  10. {
  11. "token": "团",
  12. "start_offset": 1,
  13. "end_offset": 2,
  14. "type": "<IDEOGRAPHIC>",
  15. "position": 1
  16. },
  17. {
  18. "token": "s.h.e",
  19. "start_offset": 2,
  20. "end_offset": 7,
  21. "type": "<ALPHANUM>",
  22. "position": 2
  23. },
  24. {
  25. "token": "昨",
  26. "start_offset": 7,
  27. "end_offset": 8,
  28. "type": "<IDEOGRAPHIC>",
  29. "position": 3
  30. },
  31. {
  32. "token": "在",
  33. "start_offset": 8,
  34. "end_offset": 9,
  35. "type": "<IDEOGRAPHIC>",
  36. "position": 4
  37. },
  38. {
  39. "token": "两",
  40. "start_offset": 9,
  41. "end_offset": 10,
  42. "type": "<IDEOGRAPHIC>",
  43. "position": 5
  44. },
  45. {
  46. "token": "厅",
  47. "start_offset": 10,
  48. "end_offset": 11,
  49. "type": "<IDEOGRAPHIC>",
  50. "position": 6
  51. },
  52. {
  53. "token": "院",
  54. "start_offset": 11,
  55. "end_offset": 12,
  56. "type": "<IDEOGRAPHIC>",
  57. "position": 7
  58. },
  59. {
  60. "token": "艺",
  61. "start_offset": 12,
  62. "end_offset": 13,
  63. "type": "<IDEOGRAPHIC>",
  64. "position": 8
  65. },
  66. {
  67. "token": "文",
  68. "start_offset": 13,
  69. "end_offset": 14,
  70. "type": "<IDEOGRAPHIC>",
  71. "position": 9
  72. }
  73.  。。。
  74. ]
  75. }

standard分词器把中文都拆分成了单个字。IK分词器拆分成了字和词语。