Elasticsearch 安装版本 : 7.6.2

查看当前jdk&rpm版本

jdk

[root@localhost ~]# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

rpm

[root@localhost ~]# rpm -qa|grep java
java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2019c-1.el7.noarch
[root@localhost ~]# rpm -qa|grep jdk
java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64

卸载当前rpm

[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64

下载&解压

[root@localhost java]# tar -zxf jdk-9.0.1_linux-x64_bin.tar.gz

配置环境变量

编辑

vi /etc/profile

#set java environment
JAVA_HOME=/usr/local/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

启动配置信息

[root@localhost usr]# source /etc/profile

校验

[root@localhost usr]# 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)

安装 Elasticsearch

下载&解压

  • 下载 : Elasticsearch
  • 解压 : tar -xvf elasticsearch-7.6.2-linux-x86_64.tar.gz

查看目录结构

新建数据目录:mkdir data

[root@localhost elasticsearch-7.6.2]# ll
总用量 548
drwxr-xr-x.  2 root root   4096 3月  26 2020 bin
drwxr-xr-x.  2 root root    148 3月  26 2020 config
drwxr-xr-x.  2 root root      6 11月 17 16:29 data
drwxr-xr-x.  9 root root    107 3月  26 2020 jdk
drwxr-xr-x.  3 root root   4096 3月  26 2020 lib
-rw-r--r--.  1 root root  13675 3月  26 2020 LICENSE.txt
drwxr-xr-x.  2 root root      6 3月  26 2020 logs
drwxr-xr-x. 38 root root   4096 3月  26 2020 modules
-rw-r--r--.  1 root root 523209 3月  26 2020 NOTICE.txt
drwxr-xr-x.  2 root root      6 3月  26 2020 plugins
-rw-r--r--.  1 root root   8164 3月  26 2020 README.asciidoc

bin:可执行文件,运行 ES 的命令

config:配置文件目录

data:数据目录

lib:依赖的 jar

logs:日志文件

配置

配置文件(config)

[root@localhost config]# ll
总用量 36
-rw-rw----. 1 root root  2831 3月  26 2020 elasticsearch.yml
-rw-rw----. 1 root root  2301 3月  26 2020 jvm.options
-rw-rw----. 1 root root 17545 3月  26 2020 log4j2.properties
-rw-rw----. 1 root root   473 3月  26 2020 role_mapping.yml
-rw-rw----. 1 root root   197 3月  26 2020 roles.yml
-rw-rw----. 1 root root     0 3月  26 2020 users
-rw-rw----. 1 root root     0 3月  26 2020 users_roles

elasticsearch.yml:ES 启动基础配置

jvm.options:ES 启动时JVM配置

log4j2.properties:ES 日志输出配置文件

进程数&线程数

  • 每个进程最大同时打开文件数太小,修改/etc/security/limits.conf文件(root用户)
*               soft    nofile          65536
*               hard    nofile         65536
  • 最大线程个数太低,修改/etc/security/limits.conf文件(root用户)
*               soft    nproc           4096
*               hard    nproc          4096

elasticsearch.yml 配置

集群名称

默认是被注释的,并且默认有一个集群名

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#

节点名称

默认是被注释的,并且默认有一个节点名

# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#

数据存储路径&日志文件路径

用逗号分隔多个位置

#
# 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
#

network

设置0.0.0.0可以让任何人访问到你的 Elasticsearch,设置一个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.
#

master节点列表

集群启动时,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 配置

/etc/sysctl.conf

vm.max_map_count=655360

查看是否修改成功

[root@localhost logs]# sysctl -p
vm.max_map_count = 655360

安装&启动

用户创建

创建Elasticsearch用户并赋予Elasticsearch安装目录权限,这是Elasticsearch的一种安全措施(不能使用root用户)。

  • 创建一个esroot用户并设置初始密码
[root@localhost elasticsearch-7.6.2]# useradd -c 'ES user' -d /home/esroot esroot
[root@localhost elasticsearch-7.6.2]# passwd esroot
  • elasticsearch安装目录属主权限改为 esroot 用户
[root@localhost elasticsearch-7.6.2]# chown -R esroot:esroot /usr/local/elasticsearch-7.6.2/
  • 切换用户到 esroot
[root@localhost elasticsearch-7.6.2]# su esroot

启动

[esroot@localhost elasticsearch-7.6.2]$ /usr/local/elasticsearch-7.6.2/bin/elasticsearch -d
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk-9.0.1] does not meet this requirement
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

校验

[esroot@localhost elasticsearch-7.6.2]$ curl 192.168.1.109:9200
{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "R3tfT4umQyuZ-RU5enGXPQ",
  "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"
}
{
  "name": "node-1",
  "cluster_name": "my-application",
  "cluster_uuid": "R3tfT4umQyuZ-RU5enGXPQ",
  "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"
}

开放9200端口

[root@localhost ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

停止

查找ES进程ps -ef | grep elastic

[esroot@localhost root]$ ps -ef | grep elastic
esroot    12330  11953  0 10:26 pts/0    00:00:00 grep --color=auto elastic

杀掉ES进程kill -9 11953(进程号)

[esroot@localhost root]$ kill -9 11953
已杀死

相关文章:

  • 2022-03-05
  • 2021-09-26
  • 2021-07-30
  • 2021-06-11
  • 2021-10-05
  • 2022-01-27
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2021-10-05
  • 2022-12-23
  • 2021-11-12
  • 2021-08-13
  • 2021-04-11
  • 2022-01-01
相关资源
相似解决方案