centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成

前序:关于ElasticSearch安装部署,以及SpringBoot2集成ES相关的工作使用的一些操作步骤和注意点,以便于后续再次部署方便使用,仅为自己笔记记录。

ElasticSearch(百度百科简介) 基于全文搜索引擎Apache Lucene基础上的搜索引擎。JAVA开发,基于倒排索引,RESTful web接口,准实时,主要使用了聚合和搜索。

工作中主要使用ES来搜索屏幕内的行政区区域的POI数据的聚合和详情,速度快。

1. ElasticSearch 下载

官网 :

 https://www.elastic.co/cn/

官网下载路劲

https://www.elastic.co/cn/downloads/

centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第1张图片

如果选用最新版本,直接下载系统对应的版本。如果选用指定版本的话 ,点击past releases可选用历史版本

centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第2张图片centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第3张图片

2. centos7.6 安装部署ES

  2.1 centos 关闭防火墙

     2.1.1 开机禁止启动防火墙

systemctl enable firewalld

systemctl enable firewalld.service

    2.1.2 查看防火墙状态

systemctl status firewalld.service

systemctl status firewalld

   2.1.3 关闭防火墙

systemctl stop firewalld

systemctl stop firewalld.service

其他防火墙命令

  2.1.4 添加开放服务

firewall-cmd --add-service=http  --permanent 

#http改为要开放的服务,--permanent参数表示永久生效,不加重启后失效

  2.1.5 添加开放端口

firewall-cmd --zone=public --add-port=80/tcp --permanent     

#80改为要开放的服务,--permanent参数表示永久生效,不加重启后失效

   2.1.6 更新防火墙规则

firewall-cmd --reload	

#重新加载防火墙

2.2 centos7 添加用户和用户组

useradd -g es es

#新建es用户并增加到es工作组

2.3  (./elasticsearch-6.8.0/config/elasticsearch.yml) 修改配置
     红色部分是需要自定义修改的,其余都是默认配置

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#配置的集群名称
cluster.name: es-application

#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#节点名称
node.name: node-1

#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
#设置访问交互的地址
network.host: 0.0.0.0

#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# es 解决访问跨越
http.cors.enabled: true
http.cors.allow-origin: "*"

 2.4 修改centos系统

  (/etc/sysctl.conf) 添加一条jvm支持线程数

vm.max_map_count=655360

执行下行命令使配置生效 

 sysctl -p

(/etc/security/limits.conf)添加当前用户所有线程打开的文件数据

* soft nofile 65536

* hard nofile 131072

* soft nproc 65536

* hard nproc 131072

2.5 修改文件所有者

chown -R es:es /opt/elk/  

2.6 (./elk/elasticsearch-6.8.0/config/jvm.options) 修改jvm 内存大小。红色部分为修改之处

   从mysql 导入数据到ES时,会出现内存溢出情况

## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms4g
-Xmx4g

################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################

## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly

## G1GC Configuration
# NOTE: G1GC is only supported on JDK version 10 or later.
# To use G1GC uncomment the lines below.
# 10-:-XX:-UseConcMarkSweepGC
# 10-:-XX:-UseCMSInitiatingOccupancyOnly
# 10-:-XX:+UseG1GC
# 10-:-XX:InitiatingHeapOccupancyPercent=75

## DNS cache policy
# cache ttl in seconds for positive DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.ttl; set to -1 to cache forever
-Des.networkaddress.cache.ttl=60
# cache ttl in seconds for negative DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.negative ttl; set to -1 to cache
# forever
-Des.networkaddress.cache.negative.ttl=10

## optimizations

# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch

## basic

# explicitly set the stack size
-Xss1m

# set to headless, just in case
-Djava.awt.headless=true

# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8

# use our provided JNA always versus the system one
-Djna.nosys=true

# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow

# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0

# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true

-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging

8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
# time/date parsing will break in an incompatible way for some date patterns and locals
9-:-Djava.locale.providers=COMPAT

# temporary workaround for C2 bug with JDK 10 on hardware with AVX-512
10-:-XX:UseAVX=2
 

 

 3. 后台启动ElasticSearch

su es -c "./elk/elasticsearch-6.8.0/bin/elasticsearch -d"

以上基本完成常规配置。

3.1 安装Elasticsearch head插件

 https://github.com/mobz/elasticsearch-head

三种方式:

   3.1.1 本地编译启动

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start

3.1.2 chrome 安装扩展

https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm/ 

3.1.3 下载官方编译成功复制到(../elasticsearch-6.8.0/plugins)文件夹下

https://github.com/mobz/elasticsearch-head/releases

3.2 安装 ElasticSearch ik 分词器

https://github.com/medcl/elasticsearch-analysis-ik

 3.3 安装ElasricSearch 拼音分词器

https://github.com/medcl/elasticsearch-analysis-pinyin

4. FAQ 

 4.1 只读不能写入的修改

PUT _settings
{
"index": {
"blocks": {
"read_only_allow_delete": "false"
        }
    }

4.2  completion suggest 搜索联想自动补全

PUT /my_data
{
  "mappings": {
    "news" : {
      "properties" : {
        "title" : {
          "type": "text",
          "analyzer": "ik_max_word",
          "fields": {
            "suggest" : {
              "type" : "completion",
              "analyzer": "ik_max_word"
            }
          }
        },
        "content": {
          "type": "text",
          "analyzer": "ik_max_word"
        }
      }
    }
  }
}

 centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第4张图片centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第5张图片centos7.6 安装部署 ElasticSearch6.8 以及与 SpringBoot2 集成_第6张图片

你可能感兴趣的:(JAVA,GIS)