Linux 安装 Elasticsearch6.4.x 详细步骤以及问题解决方案

官方文档

环境

  • IP:192.168.1.101
  • 主机名:node1
  • 系统:CentOS 6.8
  • Java:1.8.0_191
  • elasticsearch:6.4.2

1 安装java环境

1.1 下载JDK

JDK的下载可以去官网上直接下载,版本为1.8.*即可;
Oracle

1.2 解压jdk

$ mkdir /opt/java

上传jdk包到/opt/java目录下,解压

$ tar xf jdk-8u191-linux-x64.tar.gz

1.3 配置软连接

使jdk指向 jdk1.8.0_191

$ ln -s jdk1.8.0_191 jdk

1.4 配置环境变量

$ vim /etc/profile.d/java.sh
JAVA_HOME=/opt/java/jdk
JRE_HOME=/opt/java/jdk/jre
CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

使用环境变量生效

$ source /etc/profile

1.5 验证

安装完成后执行如下命令查看安装是否成功;

$ java -version

2 安装ES(elasticsearch)

2.1 新建普通用户

由于Elasticsearch可以接收用户输入的脚本并且执行,为了系统安全考虑,不允许root账号启动,所以建议给Elasticsearch单独创建一个用户来运行Elasticsearch。

$ groupadd elsearch
$ useradd elsearch -g elsearch
$ echo "password" |passwd elsearch --stdin

设置目录属主和属组

$ mkdir -pv /data/ES/
$ chown -R elsearch:elsearch /data/ES/
$ su - elsearch

2.2 下载

ES 去官网直接下载,本人使用的是 6.4.2 版本;因为版本的不同安装head插件的时候安装步骤不同;好像是从5.0 以后的版本安装head 插件的步骤就不一样了;下面会详细介绍。
官网下载路径
点击“MACOS/LINUX”即可,也可以下载rpm包

2.3 解压

将安装包上传到/data/ES/目录下,解压

$ tar xf elasticsearch-6.4.2.tar.gz
$ cd elasticsearch-6.4.2

2.4 修改ES配置文件

没有配置集群,只是简单的配置了一下;详细说明可以参考官网;

$ cp -a config/elasticsearch.yml{,_$(date +%F)}
$ vim 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: my-application
cluster.name: TRAS-ES   # 集群名称
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: node1        # 主机名
#
# 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.data: /data/ES/elasticsearch-6.4.2/data    # 数据路径
#
# Path to log files:
#
#path.logs: /path/to/logs
path.logs: /data/ES/elasticsearch-6.4.2/logs    # 日志路径
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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: 192.168.1.101
#
# Set a custom port for HTTP:
#
#http.port: 9200
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数据文件和日志文件

mkdir -p /data/ES/elasticsearch-6.4.2/data
mkdir -p /data/ES/elasticsearch-6.4.2/logs

2.5 启动

执行ES文件,进入到bin 目录下执行 ./elasticsearch 命令就可以了,执行 ./elasticesrarch -d 是后台运行

$ ./bin/elasticsearch
[2018-10-30T13:47:23,238][INFO ][o.e.n.Node               ] [node1] initializing ...
[2018-10-30T13:47:23,834][INFO ][o.e.e.NodeEnvironment    ] [node1] using [1] data paths, mounts [[/data (/dev/sda4)]], net usable_space [712.1gb], net total_space [1.6tb], types [ext4]
[2018-10-30T13:47:23,834][INFO ][o.e.e.NodeEnvironment    ] [node1] heap size [990.7mb], compressed ordinary object pointers [true]
[2018-10-30T13:47:23,835][INFO ][o.e.n.Node               ] [node1] node name [node1], node ID [IiSDNdfAS_WfGNeRQWX-Rg]
[2018-10-30T13:47:23,836][INFO ][o.e.n.Node               ] [node1] version[6.4.2], pid[5094], build[default/tar/04711c2/2018-09-26T13:34:09.098244Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_66/25.66-b17]
[2018-10-30T13:47:23,836][INFO ][o.e.n.Node               ] [node1] 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.Ol6oSUD9, -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=/data/ES/elasticsearch-6.4.2, -Des.path.conf=/data/ES/elasticsearch-6.4.2/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [aggs-matrix-stats]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [analysis-common]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [ingest-common]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [lang-expression]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [lang-mustache]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [lang-painless]
[2018-10-30T13:47:25,519][INFO ][o.e.p.PluginsService     ] [node1] loaded module [mapper-extras]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [parent-join]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [percolator]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [rank-eval]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [reindex]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [repository-url]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [transport-netty4]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [tribe]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-core]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-deprecation]
[2018-10-30T13:47:25,520][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-graph]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-logstash]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-ml]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-monitoring]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-rollup]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-security]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-sql]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-upgrade]
[2018-10-30T13:47:25,521][INFO ][o.e.p.PluginsService     ] [node1] loaded module [x-pack-watcher]
[2018-10-30T13:47:25,522][INFO ][o.e.p.PluginsService     ] [node1] no plugins loaded
[2018-10-30T13:47:29,078][INFO ][o.e.x.s.a.s.FileRolesStore] [node1] parsed [0] roles from file [/data/ES/elasticsearch-6.4.2/config/roles.yml]
[2018-10-30T13:47:29,427][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/5162] [[email protected]] controller (64 bit): Version 6.4.2 (Build 660eefe6f2ea55) Copyright (c) 2018 Elasticsearch BV
[2018-10-30T13:47:29,868][DEBUG][o.e.a.ActionModule       ] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2018-10-30T13:47:30,150][INFO ][o.e.d.DiscoveryModule    ] [node1] using discovery type [zen]
[2018-10-30T13:47:31,161][INFO ][o.e.n.Node               ] [node1] initialized
[2018-10-30T13:47:31,161][INFO ][o.e.n.Node               ] [node1] starting ...
[2018-10-30T13:47:31,281][INFO ][o.e.t.TransportService   ] [node1] publish_address {192.168.1.101:9300}, bound_addresses {192.168.1.101:9300}
[2018-10-30T13:47:31,301][INFO ][o.e.b.BootstrapChecks    ] [node1] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2018-10-30T13:47:34,392][INFO ][o.e.c.s.MasterService    ] [node1] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: new_master {node1}{IiSDNdfAS_WfGNeRQWX-Rg}{lVUD4owbQ42oQ9czQOQ_Tw}{192.168.1.101}{192.168.1.101:9300}{ml.machine_memory=16604286976, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2018-10-30T13:47:34,396][INFO ][o.e.c.s.ClusterApplierService] [node1] new_master {node1}{IiSDNdfAS_WfGNeRQWX-Rg}{lVUD4owbQ42oQ9czQOQ_Tw}{192.168.1.101}{192.168.1.101:9300}{ml.machine_memory=16604286976, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {node1}{IiSDNdfAS_WfGNeRQWX-Rg}{lVUD4owbQ42oQ9czQOQ_Tw}{192.168.1.101}{192.168.1.101:9300}{ml.machine_memory=16604286976, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]])
[2018-10-30T13:47:34,408][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [node1] publish_address {192.168.1.101:9200}, bound_addresses {192.168.1.101:9200}
[2018-10-30T13:47:34,408][INFO ][o.e.n.Node               ] [node1] started
[2018-10-30T13:47:34,748][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [node1] Failed to clear cache for realms [[]]
[2018-10-30T13:47:34,807][INFO ][o.e.l.LicenseService     ] [node1] license [ff5ebbe8-b960-4b1c-9c2c-144ed48467d8] mode [basic] - valid
[2018-10-30T13:47:34,818][INFO ][o.e.g.GatewayService     ] [node1] recovered [0] indices into cluster_state

2.6 启动遇到的问题:

2.6.1 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

原因:无法创建本地文件问题,用户最大可创建文件数太小

解决方案:切到root 用户下

$ vim /etc/security/limits.conf 在文件的末尾添加下面的参数值:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

前面的*符号必须带上,然后重新启动就可以了。执行完成后可以使用命令 ulimit -n 查看进程数

2.6.2 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
... ...
[2018-10-30T11:41:51,807][INFO ][o.e.x.m.j.p.NativeController] Native controller process has stopped - no new native processes can be started

原因:最大虚拟内存太小,需要修改系统变量的最大值。

解决方案:切换到root用户,修改配置sysctl.conf 增加配置值: vm.max_map_count=262144

$ vim /etc/sysctl.conf
vm.max_map_count=262144

执行命令

sysctl -p

2.6.3 max number of threads [1024] for user [es] likely too low, increase to at least [2048]

原因:无法创建本地线程问题,用户最大可创建线程数太小
解决方案:切换到root用户,进入limits.d目录下,修改90-nproc.conf 配置文件。

vi /etc/security/limits.d/90-nproc.conf
找到如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048

2.6.4 system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

原因:Centos6不支持SecComp,而ES6.4.2默认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

然后重新启动ES服务 就可以了。

2.7 验证

执行curl ‘http://自己配置的IP地址:9200/‘ 命令,就出现下面的结果

$ curl ‘http://192.168.1.101:9200/‘
{
  "name" : "node1",
  "cluster_name" : "TRAS-ES",
  "cluster_uuid" : "g_YrGeWpT4aEMKAdigk-rQ",
  "version" : {
    "number" : "6.4.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "04711c2",
    "build_date" : "2018-09-26T13:34:09.098244Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

如果没有什么问题话,就可以停掉前台启动,使用后台启动ES;

$ ./bin/elasticsearch -d
$ ss -tnlp |grep 9200
LISTEN     0      128    ::ffff:192.168.1.101:9200                    :::*      users:(("java",6686,246))

3 安装head 插件

为了便于管理ES,本文使用head插件,这是最初级的管理工具,在浏览器中显示ES集群,索引等信息,十分好用。

3.1 安装node.js:

grunt是基于Node.js的项目构建工具,下面先安装node.js,

3.1.1 配置nodejs的yum源,执行curl -sL https://rpm.nodesource.com/setup_8.x | bash -,显示如下:

$ curl -sL https://rpm.nodesource.com/setup_8.x | bash -

## Installing the NodeSource Node.js 8.x LTS Carbon repo...

## Inspecting system...

+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m

## Confirming "el6-x86_64" is supported...

+ curl -sLf -o /dev/null ‘https://rpm.nodesource.com/pub_8.x/el/6/x86_64/nodesource-release-el6-1.noarch.rpm‘

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o ‘/tmp/tmp.UGP0HdCahJ‘ ‘https://rpm.nodesource.com/pub_8.x/el/6/x86_64/nodesource-release-el6-1.noarch.rpm‘

## Installing release setup RPM...

+ rpm -i --nosignature --force ‘/tmp/tmp.UGP0HdCahJ‘

## Cleaning up...

+ rm -f ‘/tmp/tmp.UGP0HdCahJ‘

## Checking for existing installations...

+ rpm -qa ‘node|npm‘ | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 8.x LTS Carbon and npm.
## You may also need development tools to build native addons:
     sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn

3.1.2 安装nodejs

$ yum install -y nodejs

版本:2:8.12.0-1nodesource

3.1.3 验证

可以使用命令 node -v 验证是否安装成功,同时npm 也安装成功了;执行命令 npm -v 也是可以验证的。

$ node -v
v8.12.0
$ npm -v
6.4.1

3.2 下载head安装包

下载地址:https://github.com/mobz/elasticsearch-head/archive/master.zip

$ cd /data/ES
$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip
$ unzip master.zip
$ mv elasticsearch-head-master elasticsearch-head

由于head 插件不能放在elasticsearch-6.4.2 文件夹里,head 插件需要单独放,单独去执行;
所以在elasticsearch-6.4.2 同级目录下解压了 head 插件;解压出来的文件名字,

3.3 安装grunt

由于head 插件的执行文件是有grunt 命令来执行的,所以这个命令必须安装

$ cd /data/ES/elasticsearch-head
$ sudo npm install grunt --save-dev
npm WARN deprecated [email protected]: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] license should be a valid SPDX license expression

+ [email protected]
added 94 packages from 61 contributors and audited 162 packages in 11.256s
found 2 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

# 安装
$ sudo npm install
npm WARN deprecated [email protected]: Use the built-in module in node 9.0.0 or newer, instead

> [email protected] install /data/ES/elasticsearch-head/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
  [========================================] 100%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /data/ES/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1540884540095/phantomjs-2.1.1-linux-x86_64 -> /data/ES/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /data/ES/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm WARN [email protected] license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 413 packages from 567 contributors and audited 1750 packages in 1054.629s
found 23 vulnerabilities (17 low, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details

# 修复漏洞
$ sudo npm audit fix
npm WARN [email protected] license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ [email protected]
+ [email protected]
added 19 packages from 14 contributors, removed 5 packages and updated 9 packages in 6.614s
fixed 5 of 23 vulnerabilities in 1750 scanned packages
  3 package updates for 18 vulns involved breaking changes
  (use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)

3.4 检查是否安装成功

$ grunt -version
grunt-cli v1.3.1
grunt v1.0.1

3.5 修改head插件配置

修改配置文件,cd 进入elasticsearch-head 文件夹下,执行命令vim Gruntfile.js文件:增加hostname属性,设置为*;

$ pwd
/data/ES/elasticsearch-head
$ vim Gruntfile.js
... ...
 77                 watch: {
 78                         "scripts": {
 79                                 files: [‘src/**/*‘, ‘test/spec/*‘ ],
 80                                 tasks: [‘default‘],
 81                                 options: {
 82                                         spawn: false
 83                                 }
 84                         },
 85                         "grunt": {
 86                                 files: [ ‘Gruntfile.js‘ ]
 87                         }
 88                 },
 89
 90                 connect: {
 91                         server: {
 92                                 options: {
 93                                         port: 9100,
 94                                         hostname: ‘*‘,     # 添加此行
 95                                         base: ‘.‘,
 96                                         keepalive: true
 97                                 }
 98                         }
 99                 }
100
101         });
102
... ...

修改 vim _site/app.js 文件:修改head的连接地址:

$ pwd
/data/ES/elasticsearch-head
$ vim _site/app.js
把
4354                         this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
改为:
4354                         this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.101:9200";

3.6 运行head

前台运行

$ cd /data/ES/elasticsearch-head
$ grunt server
(node:13043) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

后台运行

$ cd /data/ES/elasticsearch-head
$ grunt server &

# 查看是否后台运行
$ ps -ef|grep grunt
elsearch     17512 30633  1 17:26 pts/1    00:00:00 grunt
elsearch     17583 30633  0 17:26 pts/1    00:00:00 grep --color=auto grunt

执行完成后就OK了

3.7 web访问head

URL:http://192.168.1.101:9100/

看到上面的出现的健康值了吗,说明的连接还是有问题的

在elasticsearch中启用CORS

$ vim elasticsearch-6.4.2/config/elasticsearch.yml
... ...
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
# 追加
http.cors.enabled: true
http.cors.allow-origin: "*"

http.cors.allow-origin: "*"是有效值,但它被视为安全风险,因为您的群集可以从任何地方开放交叉。

然后重新执行ES ./elasticsearch 成功起来就可以了,执行结果就是这样的

3.8 说明

elasticsearch:
URL:http://192.168.1.101:9200/
版本:6.4.2
安装路径:/data/ES

elasticsearch-head:
http://192.168.1.101:9100/

4 分词安装:

4.1 下载

4.1.1 方法一

下载对应版本的ik包:
https://github.com/medcl/elasticsearch-analysis-ik/releases

在/data/ES/elasticsearch-6.4.2/中新建plugins/ik目录

$ cd /data/ES/elasticsearch-6.4.2/
$ mkdir -pv plugins/ik
上传elasticsearch-analysis-ik-6.4.2.zip到当前目录下

解压到plugins/ik
$ unzip elasticsearch-analysis-ik-6.4.2.zip -d plugins/ik

4.1.2 方法二:

$ cd /data/ES/elasticsearch-6.4.2/
$./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.2/elasticsearch-analysis-ik-6.4.2.zip

注意:替换6.4.2为你的elasticsearch版本

4.2 重启elasticsearch服务

首先杀死elasticsearch服务,然后启动

./bin/elasticsearch -d

4.3 快速示例

4.3.1 创建一个索引

curl -XPUT http://http://192.168.1.101:9200/index

4.3.2 创建一个映射

curl -XPOST http://192.168.1.101:9200/index/fulltext/_mapping -H ‘Content-Type:application/json‘ -d‘
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}‘

4.3.3 索引一些文档

curl -XPOST http://192.168.1.101:9200/index/fulltext/1 -H ‘Content-Type:application/json‘ -d‘
{"content":"美国留给伊拉克的是个烂摊子吗"}
‘
curl -XPOST http://192.168.1.101:9200/index/fulltext/2 -H ‘Content-Type:application/json‘ -d‘
{"content":"公安部:各地校车将享最高路权"}
‘
curl -XPOST http://192.168.1.101:9200/index/fulltext/3 -H ‘Content-Type:application/json‘ -d‘
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
‘
curl -XPOST http://192.168.1.101:9200/index/fulltext/4 -H ‘Content-Type:application/json‘ -d‘
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
‘

4.3.4 查询显示

curl -XPOST http://192.168.1.101:9200/index/fulltext/_search  -H ‘Content-Type:application/json‘ -d‘
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
‘

结果:

{
    "took": 14,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 2,
        "hits": [
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "4",
                "_score": 2,
                "_source": {
                    "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
                },
                "highlight": {
                    "content": [
                        "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
                    ]
                }
            },
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "3",
                "_score": 2,
                "_source": {
                    "content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
                },
                "highlight": {
                    "content": [
                        "均每天扣1艘<tag1>中国</tag1>渔船 "
                    ]
                }
            }
        ]
    }
}

5 参考

http://blog.51cto.com/4925054/2083939

原文地址:http://blog.51cto.com/moerjinrong/2310817

时间: 2024-10-09 01:55:59

Linux 安装 Elasticsearch6.4.x 详细步骤以及问题解决方案的相关文章

linux下安装redmine2.5.1详细步骤

yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel yum install mysql-devel 安装rvm curl -L get.rvm.io | bash -s stable source /etc/profile

linux下安装配置JDK,详细步骤图文

1.复制jdk到安装目录 (1)假设jdk安装文件在桌面,我们指定的安装目录是:/usr/local/java .可是系统安装后在/usr/local下并没有java目录,这需要我们去创建一个java文件夹,如图(1) (2)切换到桌面下,执行复制,如图(2) 2.安装jdk (1)切换到root用户下,如图(3) (注:如果因忘记密码而认证失败,可以先修改root用户的密码,再执行第(1)步,修改root用户密码如图(4)) (2)运行jdk-6u30-linux-i586.bin,如图(5)

图例演示在Linux上快速安装软RAID的详细步骤

物理环境:虚拟机centos6.4 配置:8G内存.2*2核cpu.3块虚拟硬盘(sda,sdb,sdc,sdb和sdc是完全一样的) 在实际生产环境中,系统硬盘与数据库和应用是分开的,这样有利于系统的维护和对数据应用的使用.本环境中将sda作为系统盘,sdb+sdc做软RAID0(如果做RAID5,只需要在添加一块与sdb完全一样的硬盘即可,并在创建RAID的时候选择level 5). 软件磁盘阵列的设置很简单,因为值需要使用一个命令即可.那就是mdadm,常用参数如下: 参数: --crea

Linux离线安装mysql 5.6详细步骤

一.安装MySQL 1.下载安装包 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz 2.卸载系统自带的Mariadb rpm -qa|grep mariadb //查询已安装的mariadb rpm -e --nodeps 文件名 //卸载,文件名为使用rpm -qa|grep mariadb 命令查出的所有文件 3.删除etc目录下的my.cnf文件(如果没有就直接新建) rm /etc/my.cnf 4. 执行以下命令来创建mysql用户组 groupa

Linux下卸载OpenJDK并安装Sun JDK的详细步骤

一 卸载: (1)查看Java版本: [[email protected] src]# java -version openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode) (2)查询所有跟Java相关的安装的rpm包: [[email protected] src]# rpm -qa

linux设置iptables防火墙的详细步骤(centos防火墙设置方法)

我们 来讨论一下如何为你的CentOS 服务器来设置简单的防火墙. 这里我们以DigitalOcean的CentOS 6 VPS为基础来讨论的,同样也适用于 阿里云上其他类型的LINUX系统. (阿里云有个云盾系统,因此在你自己的VPS上不设置防火墙也是可以的) 需要说明的是: 本文只涉及最基础最常用的防火墙设置,能屏蔽一些常用的攻击,但并不能彻底保证你的服务器的安全. 系统的随时更新 以及 关闭不必要的服务 仍然是保证系统安全非常重要的步骤. 如果你需要更全面的了解iptables,阅读本文后

U盘安装Windows 7 系统详细步骤

使用U盘安装win7原版步骤: 目前很多电脑不带光驱,这个给安装系统带来了麻烦,下面介绍如何U盘进行系统的安装: 步骤一.制作可以启动的带WinPE系统U盘(需求1G以上的U盘均可,最好2G以上): 1.  下载WinPE的工具和PE ISO文件,请参考:http://www.laomaotao.org/lmtjc/184.html这个链接(工具和PE系统下载): 步骤二.下载系统的Windows 7 ISO镜像文件,关于Win7 ISO镜像文件下载链接网上搜下,很多滴: 步骤三.提取相关文件(

rhel7安装文档-附详细步骤截图--小白的首选

虚拟机配置(vmware 10  workstation) 过程不详述 截图很详细 如果选项里没有red hat7 64位  选 red hat 664位 即可 内存最小要给到 768M  我这里给2G 如果要虚拟机可上外网就选择桥接模式 即可 其他全部默认直至完成 点击光驱 选择 red hat 7.1 64位光盘镜像文件 rhel7.1 系统安装 时区设置 校验安装源 将额外的软件包选项勾上 如果安装时网络是通的 会自动更新软件包 选择 SOFTWARE SELECTION(软件选择) 选择

linux 安装jdk以及nginx详细过程

一.安装jdk 1:首先下载jdk到本地,然后通过git 上传到linux服务器上 2:进入目录usr,并创建目录java,将jdk的压缩文件移动到该目录下 cd /usr mkdir java mv jdk-xxxx /usr/java 3:解压安装jdk,并删除压缩包 tar -zxvf jdk-xxxx rm -rf jdk-xxxx 4: 编辑配置文件profile,配置环境变量,并编译配置文件 vim /etc/profile JAVA_HOME=/usr/java/jdk=XXXX