cd /usr/local/
mkdir es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.1-linux-x86_64.tar.gz
如果下载不了请自行去 ES官网 找
tar -xvf elasticsearch-7.15.1-linux-x86_64.tar.gz
vim /usr/local/es/elasticsearch-7.15.1/bin/elasticsearch-env
# 在 set -e -o pipefail 下一行插入如下内容
export JAVA_PATH=/usr/local/es/elasticsearch-7.15.1/jdk
PS: ES 7.0 以上版本需要 java 11 所以 ES自己附带了一个jdk方便使用
#!/bin/bash
set -e -o pipefail
################## 新增的内容 #####################
export JAVA_PATH=/usr/local/es/elasticsearch-7.15.1/jdk
CDPATH=""
SCRIPT="$0"
# SCRIPT might be an arbitrarily deep series of symbolic links; loop until we
# have the concrete path
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
# Drop everything prior to ->
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
# determine Elasticsearch home; to do this, we strip from the path until we find
# bin, and then strip bin (there is an assumption here that there is no nested
# directory under bin also named bin)
ES_HOME=`dirname "$SCRIPT"`
# now make ES_HOME absolute
ES_HOME=`cd "$ES_HOME"; pwd`
while [ "`basename "$ES_HOME"`" != "bin" ]; do
ES_HOME=`dirname "$ES_HOME"`
done
ES_HOME=`dirname "$ES_HOME"`
# now set the classpath
ES_CLASSPATH="$ES_HOME/lib/*"
# now set the path to java
if [ ! -z "$ES_JAVA_HOME" ]; then
JAVA="$ES_JAVA_HOME/bin/java"
JAVA_TYPE="ES_JAVA_HOME"
elif [ ! -z "$JAVA_HOME" ]; then
# fallback to JAVA_HOME
echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
JAVA="$JAVA_HOME/bin/java"
JAVA_TYPE="JAVA_HOME"
else
# use the bundled JDK (default)
if [ "$(uname -s)" = "Darwin" ]; then
# macOS has a different structure
JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
else
JAVA="$ES_HOME/jdk/bin/java"
fi
JAVA_TYPE="bundled JDK"
fi
if [ ! -x "$JAVA" ]; then
echo "could not find java in $JAVA_TYPE at $JAVA" >&2
exit 1
fi
# do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
echo "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
unset JAVA_TOOL_OPTIONS
fi
# JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
# warn them that we are not observing the value of $JAVA_OPTS
if [ ! -z "$JAVA_OPTS" ]; then
echo -n "warning: ignoring JAVA_OPTS=$JAVA_OPTS; "
echo "pass JVM parameters via ES_JAVA_OPTS"
fi
if [[ "$("$JAVA" -version 2>/dev/null)" =~ "Unable to map CDS archive" ]]; then
XSHARE="-Xshare:off"
else
XSHARE="-Xshare:auto"
fi
# check the Java version
"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
export HOSTNAME=$HOSTNAME
if [ -z "$ES_PATH_CONF" ]; then ES_PATH_CONF="$ES_HOME"/config; fi
if [ -z "$ES_PATH_CONF" ]; then
echo "ES_PATH_CONF must be set to the configuration path"
exit 1
fi
# now make ES_PATH_CONF absolute
ES_PATH_CONF=`cd "$ES_PATH_CONF"; pwd`
ES_DISTRIBUTION_FLAVOR=default
ES_DISTRIBUTION_TYPE=tar
ES_BUNDLED_JDK=true
if [[ "$ES_BUNDLED_JDK" == "false" ]]; then
echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" >&2
fi
if [[ "$ES_DISTRIBUTION_TYPE" == "docker" ]]; then
# Allow environment variables to be set by creating a file with the
# contents, and setting an environment variable with the suffix _FILE to
# point to it. This can be used to provide secrets to a container, without
# the values being specified explicitly when running the container.
source "$ES_HOME/bin/elasticsearch-env-from-file"
# Parse Docker env vars to customize Elasticsearch
#
# e.g. Setting the env var cluster.name=testcluster or ES_CLUSTER_NAME=testcluster
#
# will cause Elasticsearch to be invoked with -Ecluster.name=testcluster
#
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#_setting_default_settings
declare -a es_arg_array
# Elasticsearch settings need to either:
# a. have at least two dot separated lower case words, e.g. `cluster.name`, or
while IFS='=' read -r envvar_key envvar_value; do
if [[ -n "$envvar_value" ]]; then
es_opt="-E${envvar_key}=${envvar_value}"
es_arg_array+=("${es_opt}")
fi
done <<< "$(env | grep -E '^[-a-z0-9_]+(\.[-a-z0-9_]+)+=')"
# b. be upper cased with underscore separators and prefixed with `ES_SETTING_`, e.g. `ES_SETTING_CLUSTER_NAME`.
# Underscores in setting names are escaped by writing them as a double-underscore e.g. "__"
while IFS='=' read -r envvar_key envvar_value; do
if [[ -n "$envvar_value" ]]; then
# The long-hand sed `y` command works in any sed variant.
envvar_key="$(echo "$envvar_key" | sed -e 's/^ES_SETTING_//; s/_/./g ; s/\.\./_/g; y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' )"
es_opt="-E${envvar_key}=${envvar_value}"
es_arg_array+=("${es_opt}")
fi
done <<< "$(env | grep -E '^ES_SETTING(_{1,2}[A-Z]+)+=')"
# Reset the positional parameters to the es_arg_array values and any existing positional params
set -- "$@" "${es_arg_array[@]}"
# The virtual file /proc/self/cgroup should list the current cgroup
# membership. For each hierarchy, you can follow the cgroup path from
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and
# introspect the statistics for the cgroup for the given
# hierarchy. Alas, Docker breaks this by mounting the container
# statistics at the root while leaving the cgroup paths as the actual
# paths. Therefore, Elasticsearch provides a mechanism to override
# reading the cgroup path from /proc/self/cgroup and instead uses the
# cgroup path defined the JVM system property
# es.cgroups.hierarchy.override. Therefore, we set this value here so
# that cgroup statistics are available for the container this process
# will run in.
export ES_JAVA_OPTS="-Des.cgroups.hierarchy.override=/ $ES_JAVA_OPTS"
fi
cd "$ES_HOME"
PS:如果你的 es 被坏人黑了 那么你的服务器就裂开了。。。
##新建用户组 es
groupadd es
###新建 es_user 用户 并加入 es 组
useradd -g es es_user
#设置密码(也可跳过 建议设置)
passwd es_user
#New password: 输入你的密码(至少8位)
#Retype new password: 确认密码
vim /usr/local/es/elasticsearch-7.15.1/config/elasticsearch.yml
?network #检索
#network.host: 192.168.0.1 改为
network.host: 0.0.0.0
# 在文件末尾写入
# 初始主节点IP地址
cluster.initial_master_nodes: ["你自己的IP地址"]
# 子节点IP地址
discovery.seed_hosts: ["你自己的IP地址"]
#将 /usr/local/es 目录权限授权给 es_user 和 es 用户组
chown -Rf es_user:es /usr/local/es
cd /usr/local/es/elasticsearch-7.15.1
#查看文件信息
ll
######## 显示如下内容
drwxr-xr-x. 2 es_user es 4096 Oct 19 15:17 bin
drwxr-xr-x. 3 es_user es 199 Oct 19 15:11 config
drwxr-xr-x. 9 es_user es 121 Oct 8 06:00 jdk
drwxr-xr-x. 3 es_user es 4096 Oct 8 06:00 lib
-rw-r--r--. 1 es_user es 3860 Oct 8 05:53 LICENSE.txt
drwxr-xr-x. 2 es_user es 4096 Oct 19 15:11 logs
drwxr-xr-x. 60 es_user es 4096 Oct 8 06:00 modules
-rw-r--r--. 1 es_user es 628969 Oct 8 05:58 NOTICE.txt
drwxr-xr-x. 2 es_user es 6 Oct 8 05:58 plugins
-rw-r--r--. 1 es_user es 2710 Oct 8 05:53 README.asciidoc
vim /etc/security/limits.conf
# 在文件中插入如下内容 给 es_user 赋予更多操作空间(否则它施展不开拳脚)
es_user soft nofile 65535
es_user hard nofile 65535
es_user soft nproc 4096
es_user hard nproc 4096
# /etc/security/limits.conf
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
# -
#
#Where:
# can be:
# - a user name
# - a group name, with @group syntax
#
# can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#- can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open file descriptors
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
# -
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
es_user soft nofile 65535
es_user hard nofile 65535
es_user soft nproc 4096
es_user hard nproc 4096
# End of file
vi /etc/sysctl.conf
添加内容
# 文件中写入如下内容 增加最大运行内存
vm.max_map_count=262144
sysctl -p
firewall-cmd --zone=public --add-port=9200/tcp --permanent
#重启防火墙
firewall-cmd --reload
su es_user
cd bin
#启动 -d 后台启动
./elasticsearch -d