乐趣区

关于elasticsearch:殘荷听雨

Elasticsearch

下载

下载地址 : Elasticsearch

解压

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

目录

mkdir data

[esroot@localhost elasticsearch-7.6.2]$ ll
总用量 556
drwxr-xr-x.  2 esroot root     4096 3 月  26 14:36 bin   #可执行文件,运行 es 的命令
drwxr-xr-x.  2 esroot root     4096 8 月   3 21:19 config   #配置文件目录
drwxrwxr-x.  2 esroot esroot      6 8 月   3 22:27 data   #本人创立寄存 es 存储文件
drwxr-xr-x.  9 esroot root       99 3 月  26 14:36 jdk
drwxr-xr-x.  3 esroot root     4096 3 月  26 14:36 lib    #依赖的 jar
-rw-r--r--.  1 esroot root    13675 3 月  26 14:28 LICENSE.txt
drwxr-xr-x.  2 esroot root     4096 8 月   3 21:53 logs   #日志文件夹
drwxr-xr-x. 38 esroot root     4096 3 月  26 14:37 modules
-rw-r--r--.  1 esroot root   523209 3 月  26 14:36 NOTICE.txt
drwxr-xr-x.  2 esroot root        6 3 月  26 14:36 plugins
-rw-r--r--.  1 esroot root     8164 3 月  26 14:28 README.asciidoc

配置

config 目录
[esroot@localhost config]$ ll
总用量 40
-rw-rw----. 1 esroot root   199 8 月   3 21:19 elasticsearch.keystore
-rw-rw----. 1 esroot root  2831 3 月  26 14:28 elasticsearch.yml   #ES 启动根底配置
-rw-rw----. 1 esroot root  2301 3 月  26 14:28 jvm.options   #ES 启动时 JVM 配置
-rw-rw----. 1 esroot root 17545 3 月  26 14:36 log4j2.properties   #ES 日志输入配置文件
-rw-rw----. 1 esroot root   473 3 月  26 14:36 role_mapping.yml
-rw-rw----. 1 esroot root   197 3 月  26 14:36 roles.yml
-rw-rw----. 1 esroot root     0 3 月  26 14:36 users
-rw-rw----. 1 esroot root     0 3 月  26 14:36 users_roles
elasticsearch.yml 配置
  1. 配置es 集群名称(默认是被正文的,并且默认有一个集群名)
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
  1. 配置以后es 节点名称(默认是被正文的,并且默认有一个节点名)
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
  1. 配置 存储数据目录门路 (用逗号分隔多个地位)和 日志文件门路
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-7.6.2/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-7.6.2/logs
#
  1. 绑定地址为特定 IP 地址(设置 0.0.0.0 能够让任何人拜访到你的 es),设置一个 http 申请 端口(默认 9200)
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
  1. 集群启动时,设置 master 节点列表(用逗号分隔,目前单机所以只配置了一个)
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
jvm.options 配置

XmsXmx设置为统一即可

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

-Xms256m
-Xmx256m
vm.max_map_count 配置
[root@localhost config]# vi /etc/sysctl.conf
vm.max_map_count=655360
[root@localhost logs]# sysctl -p
vm.max_map_count = 655360

创立用户并赋予 es 装置目录权限

这是 ES 的一种安全措施,不让用 root 用户

创立一个 esroot 用户并设置初始密码
[root@localhost bin]# useradd -c 'ES user' -d /home/esroot esroot
[root@localhost bin]# passwd esroot
elasticsearch 装置目录属主权限改为 esroot 用户
[root@localhost elasticsearch-7.6.2]# chown -R esroot:esroot /usr/local/elasticsearch-7.6.2/
切换用户到 esroot
[root@localhost config]# su esroot
启动
[esroot@localhost config]$ cd /usr/local/elasticsearch-7.6.2/bin/
[esroot@localhost bin]$ ./elasticsearch -d
胜利
[esroot@localhost elasticsearch-7.6.2]$ curl 192.168.190.131:9200
{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "bo7IKZAIQsGRecAecc1lwQ",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

谬误

jdk 版本谬误

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

这是因为 jdk 版本太低造成的,jdk版本须要在 9.0 以上,因而须要重新安装jdk

  • 查看以后版本
[root@localhost local]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
  • 查看 rpm
[root@localhost local]# rpm -qa|grep java
tzdata-java-2015g-1.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
[root@localhost local]# rpm -qa|grep jdk
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
  • 卸载
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
  • 下载 9.0.1 版本 jdk
    9.0.1 版本
  • 解压

装置在 /usr/java 目录

tar -zxf jdk-9.0.1_linux-x64_bin.tar.gz
  • 配置环境变量
vi /etc/profile
#set java environment
JAVA_HOME=/usr/java/jdk-9.0.1
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$JAVA_HOME/bin:$PATH
export JAVA_HOME  CLASS_PATH PATH
  • 启动配置信息
 source /etc/profile
  • 查看是否装置胜利
[root@localhost local]# java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
过程数问题和线程数问题

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

每个过程最大同时关上文件数太小, 批改 /etc/security/limits.conf 文件(root 用户)

*               soft    nofile          65536
*               hard    nofile          65536

max number of threads [3790] for user [esroot] is too low, increase to at least [4096]

最大线程个数太低, 批改 /etc/security/limits.conf 文件(root 用户)

*               soft    nproc           4096
*               hard    nproc           4096

此文件批改后须要从新登录用户,才会失效

elasticsearch-head

必须有 node.js

下载

下载地址 : elasticsearch-head

解压

[root@localhost local]$ unzip elasticsearch-head-master.zip
[root@localhost local]$ cd elasticsearch-head-master/

elasticsearch-head 装置目录属主权限改为 esroot 用户

[root@localhost local]# chown -R esroot:esroot /usr/local/elasticsearch-head-master/

切换用户到 esroot

[root@localhost config]# su esroot

装置

先用 root 用户 装置 淘宝镜像cnpm

[root@bogon elasticsearch-head-master]$ npm install cnpm -g --registry=https://registry.npm.taobao.org
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this
/usr/local/node-v12.18.3-linux-x64/bin/cnpm -> /usr/local/node-v12.18.3-linux-x64/lib/node_modules/cnpm/bin/cnpm
+ cnpm@6.1.1
added 684 packages from 964 contributors in 30.381s

[root@bogon local]# cnpm -v
cnpm@6.1.1 (/usr/local/node-v12.18.3-linux-x64/lib/node_modules/cnpm/lib/parse_argv.js)
npm@6.14.7 (/usr/local/node-v12.18.3-linux-x64/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@12.18.3 (/usr/local/node-v12.18.3-linux-x64/bin/node)
npminstall@3.27.0 (/usr/local/node-v12.18.3-linux-x64/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local/node-v12.18.3-linux-x64 
linux x64 3.10.0-327.el7.x86_64 
registry=https://r.npm.taobao.org

[esroot@bogon elasticsearch-head-master]$ cnpm install
✔ Installed 10 packages
✔ Linked 0 latest versions
✔ Run 0 scripts
✔ All packages installed (used 130ms(network 128ms), speed 0B/s, json 0(0B), tarball 0B)

运行

[esroot@bogon node_modules]$ npm run start

> elasticsearch-head@0.0.0 start /usr/local/elasticsearch-7.6.2/plugins/elasticsearch-head-master
> grunt server

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

开启跨域

[esroot@bogon root]$ vi /usr/local/elasticsearch-7.6.2/config/elasticsearch.yml
http.cors.enabled : true
http.cors.allow-origin : "*"

kibana

下载

要和 Elasticsearch 版本统一
下载地址 : kibana

解压

[root@localhost local]$ tar -xzvf kibana-7.6.2-linux-x86_64.tar.gz
[root@localhost local]# cd kibana-7.6.2-linux-x86_64/

elasticsearch-head 装置目录属主权限改为 esroot 用户

[root@localhost elasticsearch-7.6.2]# chown -R esroot:esroot /usr/local/kibana-7.6.2-linux-x86_64

切换用户到 esroot

[root@localhost config]# su esroot

配置

$KIBANA/config/kibaba.yml

[esroot@localhost kibana-7.6.2-linux-x86_64]$ vi config/kibana.yml
i18n.locale: "zh-CN"
server.host: "0.0.0.0"

启动

[esroot@localhost kibana-7.6.2-linux-x86_64]$ ./bin/kibana

  log   [14:41:10.079] [info][status][plugin:reporting@7.6.2] Status changed from uninitialized to green - Ready
  log   [14:41:10.540] [info][listening] Server running at http://localhost:5601
  log   [14:41:11.290] [info][server][Kibana][http] http server running at http://localhost:5601

IK 分词器

下载

要和 Elasticsearch 版本统一
下载地址 : IK 分词器

新建文件夹

放到 Elasticsearchplugins

[root@localhost plugins]# mkdir ik

解压

[root@localhost ik]# unzip elasticsearch-analysis-ik-7.6.2.zip 

elasticsearch-head 装置目录属主权限改为 esroot 用户

[root@localhost plugins]# chown -R esroot:esroot ./

切换用户到esroot

[root@localhost config]# su esroot

重启Elasticsearch

[esroot@localhost bin]$ elasticsearch-plugin list
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk-9.0.1] does not meet this requirement
ik
退出移动版