centos7 安裝Elasticsearch7.7.0

虛擬機配置:
在這裏插入圖片描述
在這裏插入圖片描述

網絡適配器因爲怕麻煩設置爲:橋接模式

我安裝的linux.isoux.iso很乾淨啥都沒有,如果安裝好了的可以跳過了

ES環境搭建

小提示: 如果虛擬機使用wget + url 的方式下載壓縮包比較慢,那可以試試使用物理機下載,然後使用WinSCP 移動到虛擬機

  1. 安裝JDK
[test@localhost ~]# wget https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
[test@localhost ~]# tar -xf openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz

修改環境變量:

[test@localhost ~]# vim /etc/profile

在文件最末尾加上:

# JAVA_HOME: 自己jdk路徑
export JAVA_HOME=/home/test/java-se-8u41-ri
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin

修改文件後運行# source /etc/profile, 或者重啓虛擬機。

檢查jdk是否安裝成功:
下面表示安裝成功

[test@localhost ~]# java -version
openjdk version "1.8.0_41"
OpenJDK Runtime Environment (build 1.8.0_41-b04)
OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)

下載ES(Elasticsearch)
ES不能用root用戶啓動,所以ES的所有操作儘量都不要使用root用戶,如果使用,那就使用chown 賦權即可
關於 “linux 新增用戶,且分組以及賦權的操作” 可以查詢相關博客

[test@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz
[test@localhost ~]# tar -xf elasticsearch-7.7.0-linux-x86_64.tar.gz

修改ES配置,編輯elasticsearch.yml文件

[test@localhost ~]# vim elasticsearch-7.7.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: my-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):
# 可以定義爲0.0.0.0,表示允許所有ip訪問。但是這樣不太安全,可以定義爲當前虛擬機的ip
# 如果是橋接模式的話,ip可能會變,虛擬機建議使用0.0.0.0
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 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:
#  與node.name對應
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation 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, 堆棧內存建議爲機器內存的50%(當然也可以不改)
修改參數:-Xms與-Xmx
-Xms1g
-Xmx1g

[test@localhost ~]# vim elasticsearch-7.7.0/config/jvm.options

啓動ES

[test@localhost ~]# ./elasticsearch-7.7.0/bin/elasticsearch -d

ES啓動報錯合集:

  1. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
  2. max number of threads [3818] for user [es] is too low, increase to at least [4096]
  3. max virtual memory areas vm.max_map_count [6530] is too low, increase to at least [262144]
  4. java.lang.RuntimeException: can not run elasticsearch as root
  5. java.lang.IllegalStateException: failed to obtain node locks, tried [[/home/test/elasticsearch-7.7.0/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?

報錯內容1,2解決方法,新增配置:

[test@localhost ~]# vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096

報錯內容3解決方法,新增配置:

[test@localhost ~]# vim /etc/sysctl.conf
vm.max_map_count=655360

ES對JDK版本要求:
在這裏插入圖片描述
如果虛擬機安裝的JDK與ES對不上,那需要額外再配置
#配置自己的jdk11
添加這幾行即可
在這裏插入圖片描述
以下是完整文件:

[test@localhost ~]# vim elasticsearch-7.7.0/bin/elasticsearch
#!/bin/bash

# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
#   ES_PATH_CONF -- Path to config directory
#   ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Example
# values are "512m", and "10g".
#
#   ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch

#配置自己的jdk11
export JAVA_HOME=/home/test/es_jdk11/jdk-11.0.1
export PATH=$JAVA_HOME/bin:$PATH


#添加jdk判斷
if [ -x "$JAVA_HOME/bin/java" ]; then
        JAVA="/home/test/es_jdk11/jdk-11.0.1/bin/java"
else
        JAVA=`which java`
fi

source "`dirname "$0"`"/elasticsearch-env

CHECK_KEYSTORE=true
DAEMONIZE=false
for option in "$@"; do
  case "$option" in
    -h|--help|-V|--version)
      CHECK_KEYSTORE=false
      ;;
    -d|--daemonize)
      DAEMONIZE=true
      ;;
  esac
done

if [ -z "$ES_TMPDIR" ]; then
  ES_TMPDIR=`"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi

# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if [[ $CHECK_KEYSTORE = true ]] \
    && bin/elasticsearch-keystore has-passwd --silent
then
  if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
    echo "Failed to read keystore password on console" 1>&2
    exit 1
  fi
fi

# The JVM options parser produces the final JVM options to start Elasticsearch.
# It does this by incorporating JVM options in the following way:
#   - first, system JVM options are applied (these are hardcoded options in the
#     parser)
#   - second, JVM options are read from jvm.options and jvm.options.d/*.options
#   - third, JVM options from ES_JAVA_OPTS are applied
#   - fourth, ergonomic JVM options are applied
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`

# manual parsing to find out, if process should be detached
if [[ $DAEMONIZE = false ]]; then
  exec \
    "$JAVA" \
    "$XSHARE" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@" <<<"$KEYSTORE_PASSWORD"
else
  exec \
    "$JAVA" \
    "$XSHARE" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@" \
    <<<"$KEYSTORE_PASSWORD" &
  retval=$?
  pid=$!
  [ $retval -eq 0 ] || exit $retval
  if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
    sleep $ES_STARTUP_SLEEP_TIME
  fi
  if ! ps -p $pid > /dev/null ; then
    exit 1
  fi
  exit 0
fi

exit $?

報錯內容4解決方法:
切換用戶啓動ES,因爲ES不能用root用戶啓動

報錯內容5解決方法:
可能是ES沒有kill

[test@localhost ~]# kill -9 {ES_pid}

OK!
啓動ES

[test@localhost ~]# ./elasticsearch-7.7.0/bin/elasticsearch -d

查看ES是否啓動成功的方法:

[test@localhost ~]# ps -ef|grep elasticsearch
[test@localhost ~]# curl http://{ip}:9200
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章