SpringBoot整合Elasticsearch+ik分词器+kibana

话不多说直接开整

首先是版本对应,SpringBoot和ES之间的版本必须要按照官方给的对照表进行安装,最新版本对照表如下:

SpringBoot整合Elasticsearch+ik分词器+kibana

 

  (官网链接:https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.requirements

开始安装ES:

  我本地的SpringBoot版本是2.3.4,所以我采用的ES版本是7.6.2版本,然后前往官网进行下载,小伙伴们也可以直接下载我所用的版本(链接:https://pan.baidu.com/s/1KoRo5h1nHY82c3B5RxfmrA  提取码:bcov):

  ES官方下载链接:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

  将下载下来的文件上传到服务器上,我上传的目录是usr/local/es,然后开始解压:

tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz

  解压后修改config目录下的elasticsearch.yml文件,贴一下我修改的内容: 

 1 # ======================== Elasticsearch Configuration =========================
 2 #
 3 # NOTE: Elasticsearch comes with reasonable defaults for most settings.
 4 #       Before you set out to tweak and tune the configuration, make sure you
 5 #       understand what are you trying to accomplish and the consequences.
 6 #
 7 # The primary way of configuring a node is via this file. This template lists
 8 # the most important settings you may want to configure for a production cluster.
 9 #
10 # Please consult the documentation for further information on configuration options:
11 # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
12 #
13 # ---------------------------------- Cluster -----------------------------------
14 #
15 # Use a descriptive name for your cluster:
16 # 这个是名字
17 cluster.name: my-application
18 #
19 # ------------------------------------ Node ------------------------------------
20 #
21 # Use a descriptive name for the node:
22 # 这个是节点名称
23 node.name: es-node-0
24 #
25 # Add custom attributes to the node:
26 #
27 #node.attr.rack: r1
28 #
29 # ----------------------------------- Paths ------------------------------------
30 #
31 # Path to directory where to store the data (separate multiple locations by comma):
32 # 这个是数据存放的路径
33 path.data: /usr/local/elasticsearch-7.6.2/data
34 #
35 # Path to log files:
36 # 这个是log存放的路径
37 path.logs: /usr/local/elasticsearch-7.6.2/logs
38 #
39 # ----------------------------------- Memory -----------------------------------
40 #
41 # Lock the memory on startup:
42 #
43 #bootstrap.memory_lock: true
44 #
45 # Make sure that the heap size is set to about half the memory available
46 # on the system and that the owner of the process is allowed to use this
47 # limit.
48 #
49 
50 
51 # Elasticsearch performs poorly when the system is swapping the memory.
52 #
53 # ---------------------------------- Network -----------------------------------
54 #
55 # Set the bind address to a specific IP (IPv4 or IPv6):
56 # 注:如果是云服务器的话需要填写内外地址,我这里是内网。
57 network.host: 192.168.0.4
58 http.host: 0.0.0.0
59 #
60 # Set a custom port for HTTP:
61 # 启动端口号
62 http.port: 9200
63 #
64 # For more information, consult the network module documentation.
65 #
66 # --------------------------------- Discovery ----------------------------------
67 #
68 # Pass an initial list of hosts to perform discovery when this node is started:
69 # The default list of hosts is ["127.0.0.1", "[::1]"]
70 #
71 #discovery.seed_hosts: ["host1", "host2"]
72 #
73 # Bootstrap the cluster using an initial set of master-eligible nodes:
74 # 初始化节点,可以有多个
75 cluster.initial_master_nodes: ["es-node-0"]
76 #
77 # For more information, consult the discovery and cluster formation module documentation.
78 #
79 # ---------------------------------- Gateway -----------------------------------
80 #
81 # Block initial recovery after a full cluster restart until N nodes are started:
82 #
83 #gateway.recover_after_nodes: 3
84 #
85 # For more information, consult the gateway module documentation.
86 #
87 # ---------------------------------- Various -----------------------------------
88 #
89 # Require explicit names when deleting indices:
90 #
91 #action.destructive_requires_name: true
  # 开启账号验证 92 xpack.security.enabled: true 93 xpack.license.self_generated.type: basic 94 xpack.security.transport.ssl.enabled: true 95 # 跨域的配置,可配可不配 96 http.cors.enabled: true 97 http.cors.allow-origin: "*"

   因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户:

useradd es
passwd es

  然后输入密码,最小8位数,为用户赋权限:

chown -R es:es /usr/local/es/

  切换成es用户,cd 到bin目录下启动,第一种是前台启动,第二种是后台启动:

./elasticsearch
./elasticsearch -d

SpringBoot整合Elasticsearch+ik分词器+kibana

   如果启动提示了这个错误需要在/etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

  执行/sbin/sysctl -p 立即生效,之后再重新启动就好了;

  在上面ES的yml配置中,我们配置了账号验证,所以我们需要重置一下ES账号的密码(确保es已经成功启动才能重置;在es的bin目录下执行):

./elasticsearch-setup-passwords interactive

SpringBoot整合Elasticsearch+ik分词器+kibana

   建议设置成相同的密码,方便记忆,设置成功后就可以直接打开网页去访问了,访问地址是ip:9200,然后输入账号:“elastic”,密码:“123456”(设置的123456)

SpringBoot整合Elasticsearch+ik分词器+kibana

   能看到这些就代表ES已经成功启动了!!!

 接下来我们开始配置Kibana:

  Kibana的版本也需要和ES对应才行(官方地址:https://www.elastic.co/cn/support/matrix#matrix_compatibility):

SpringBoot整合Elasticsearch+ik分词器+kibana

 

 

 SpringBoot整合Elasticsearch+ik分词器+kibana

   下载好的Kibana上传后进行解压缩:

tar -zxvf kibana-7.6.2-linux-x86_64.tar.gz

  

# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601

# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
#server.host: "localhost"
# 代表都能访问 server.host: "0.0.0.0" # Enables you to specify a path to mount Kibana at if you are running behind a proxy. # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath # from requests it receives, and to prevent a deprecation warning at startup. # This setting cannot end in a slash. #server.basePath: "" # Specifies whether Kibana should rewrite requests that are prefixed with # `server.basePath` or require that they are rewritten by your reverse proxy. # This setting was effectively always `false` before Kibana 6.3 and will # default to `true` starting in Kibana 7.0. #server.rewriteBasePath: false # The maximum payload size in bytes for incoming server requests. #server.maxPayloadBytes: 1048576 # The Kibana server's name. This is used for display purposes. #server.name: "your-hostname" # The URLs of the Elasticsearch instances to use for all your queries.
# 配置ES的地址 elasticsearch.hosts: ["http://192.168.0.4:9200"] # When this setting's value is true Kibana uses the hostname specified in the server.host # setting. When the value of this setting is false, Kibana uses the hostname of the host # that connects to this Kibana instance. #elasticsearch.preserveHost: true # Kibana uses an index in Elasticsearch to store saved searches, visualizations and # dashboards. Kibana creates a new index if the index doesn't already exist. #kibana.index: ".kibana" # The default application to load. #kibana.defaultAppId: "home" # If your Elasticsearch is protected with basic authentication, these settings provide # the username and password that the Kibana server uses to perform maintenance on the Kibana # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which # is proxied through the Kibana server.
# ES的账号密码 elasticsearch.username: "elastic" elasticsearch.password: "123456" # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively. # These settings enable SSL for outgoing requests from the Kibana server to the browser. #server.ssl.enabled: false #server.ssl.certificate: /path/to/your/server.crt #server.ssl.key: /path/to/your/server.key # Optional settings that provide the paths to the PEM-format SSL certificate and key files. # These files are used to verify the identity of Kibana to Elasticsearch and are required when # xpack.security.http.ssl.client_authentication in Elasticsearch is set to required. #elasticsearch.ssl.certificate: /path/to/your/client.crt #elasticsearch.ssl.key: /path/to/your/client.key # Optional setting that enables you to specify a path to the PEM file for the certificate # authority for your Elasticsearch instance. #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ] # To disregard the validity of SSL certificates, change this setting's value to 'none'. #elasticsearch.ssl.verificationMode: full # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of # the elasticsearch.requestTimeout setting. #elasticsearch.pingTimeout: 1500 # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value # must be a positive integer. #elasticsearch.requestTimeout: 30000 # List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side # headers, set this value to [] (an empty list). #elasticsearch.requestHeadersWhitelist: [ authorization ] # Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten # by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration. #elasticsearch.customHeaders: {} # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable. #elasticsearch.shardTimeout: 30000 # Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying. #elasticsearch.startupTimeout: 5000 # Logs queries sent to Elasticsearch. Requires logging.verbose set to true. #elasticsearch.logQueries: false # Specifies the path where Kibana creates the process ID file. #pid.file: /var/run/kibana.pid # Enables you specify a file where Kibana stores log output. #logging.dest: stdout # Set the value of this setting to true to suppress all logging output. #logging.silent: false # Set the value of this setting to true to suppress all logging output other than error messages. #logging.quiet: false # Set the value of this setting to true to log all events, including system usage information # and all requests. #logging.verbose: false # Set the interval in milliseconds to sample system and process performance # metrics. Minimum is 100ms. Defaults to 5000. #ops.interval: 5000 # Specifies locale to be used for all localizable strings, dates and number formats. # Supported languages are the following: English - en , by default , Chinese - zh-CN .
# 配置中文 i18n.locale: "zh-CN"

 

上一篇:专项测试 数学4


下一篇:elasticsearch7实战(三)——通用选项