CentOS7安装elasticsearch-7.9

763 阅读3分钟

官方

选择版本

移至学习,点击- 文档,点击- other versions

image.png

选择- Getting Started: 7.10,点击- Getting started with the Elastic Stack

image.png

点击- Elasticsearch

deb:

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-amd64.deb
sudo dpkg -i elasticsearch-7.9.3-amd64.deb
sudo /etc/init.d/elasticsearch start

rpm:

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-x86_64.rpm
sudo rpm -i elasticsearch-7.9.3-x86_64.rpm
sudo service elasticsearch start

mac:

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-darwin-x86_64.tar.gz
tar -xzvf elasticsearch-7.9.3-darwin-x86_64.tar.gz
cd elasticsearch-7.9.3
./bin/elasticsearch

brew:

brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
elasticsearch

linux:

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
tar -xzvf elasticsearch-7.9.3-linux-x86_64.tar.gz
cd elasticsearch-7.9.3
./bin/elasticsearch

选择Linux安装方式

下载

[root@localhost home]# curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  304M  100  304M    0     0  28.3M      0  0:00:10  0:00:10 --:--:-- 31.5M


解压

#解压
[root@localhost software]# tar -zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz

#创建数据目录和日志文件
[root@localhost elasticsearch-7.9.3]# sudo mkdir -p /path/to/data
[root@localhost elasticsearch-7.9.3]# sudo mkdir -p /path/to/logs
[root@localhost elasticsearch-7.9.3]# sudo chown -R ela.ela /path/to/
[root@localhost elasticsearch-7.9.3]# sudo chown -R ela.ela /path/to/logs


# 进入目录
[root@localhost software]# cd elasticsearch-7.9.3/

配置elasticsearch.yml

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

启动

[root@localhost elasticsearch-7.9.3]# ./bin/elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/home/user/software/jdk1.8/jre] does not meet this requirement
future versions of Elasticsearch will require Java 11; your Java version from [/home/user/software/jdk1.8/jre] does not meet this requirement
[2022-09-06T19:18:20,340][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-32] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127) ~[elasticsearch-cli-7.9.3.jar:7.9.3]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.9.3.jar:7.9.3]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393) ~[elasticsearch-7.9.3.jar:7.9.3]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.9.3.jar:7.9.3]
	... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111)
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178)
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)

问题1

java.lang.RuntimeException: can not run elasticsearch as root

解决1

#创建ela组
[root@localhost elasticsearch-7.9.3]# groupadd ela
#创建ela用户,并且加入ela组
[root@localhost elasticsearch-7.9.3]# useradd -g ela ela
#设置ela密码
[root@localhost elasticsearch-7.9.3]# passwd ela
Changing password for user ela.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

#添加一行ela   ALL=(ALL)       ALL,为elasticSearch用户分配执行权限
[root@localhost elasticsearch-7.9.3]# vim /etc/sudoers

#将软件包更改属主属组
[root@localhost elasticsearch-7.9.3]# chown -R ela.ela /home/software/elasticsearch-7.9.3

#切换用户
[root@localhost elasticsearch-7.9.3]# su ela


启动

[root@localhost elasticsearch-7.9.3]# su ela
[ela@localhost elasticsearch-7.9.3]$ ./bin/elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/home/software/jdk1.8.0_333/jre] does not meet this requirement
future versions of Elasticsearch will require Java 11; your Java version from [/home/software/jdk1.8.0_333/jre] does not meet this requirement

xxx
[2022-02-23T03:51:23,102][INFO ][o.e.n.Node               ] [node-1] initialized
[2022-02-23T03:51:23,103][INFO ][o.e.n.Node               ] [node-1] starting ...
[2022-02-23T03:51:23,226][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.0.196:9301}, bound_addresses {[::]:9301}
[2022-02-23T03:51:23,368][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
ERROR: Elasticsearch did not exit normally - check the logs at /home/software/elasticsearch-7.9.3/logs/my-application.log
[2022-02-23T03:51:23,376][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2022-02-23T03:51:23,430][INFO ][o.e.n.Node               ] [node-1] stopped
[2022-02-23T03:51:23,431][INFO ][o.e.n.Node               ] [node-1] closing ...
[2022-02-23T03:51:23,455][INFO ][o.e.n.Node               ] [node-1] closed
[2022-02-23T03:51:23,458][INFO ][o.e.x.m.p.NativeController] [node-1] Native controller process has stopped - no new native processes can be started

问题2

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

解决2

[ela@localhost elasticsearch-7.9.3]$ su root
Password: 
# 添加如下配置
[root@localhost elasticsearch-7.9.3]# vim /etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536

启动


[root@localhost elasticsearch-7.9.3]# su ela
# -d 是后台启动./bin/elasticsearch -d
[ela@localhost elasticsearch-7.9.3]$ ./bin/elasticsearch

xxx
[2022-02-23T04:03:28,284][INFO ][o.e.h.AbstractHttpServerTransport] [node-1] publish_address {192.168.0.196:9200}, bound_addresses {[::]:9200}
[2022-02-23T04:03:28,285][INFO ][o.e.n.Node               ] [node-1] started
[2022-02-23T04:03:28,502][INFO ][o.e.l.LicenseService     ] [node-1] license [45ce77e1-70db-4566-b5ec-6d470597e9a2] mode [basic] - valid
[2022-02-23T04:03:28,504][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1] Active license is now [BASIC]; Security is disabled
[2022-02-23T04:03:28,508][INFO ][o.e.g.GatewayService     ] [node-1] recovered [0] indices into cluster_state

指定jdk11启动

Java (JVM) Version

Elasticsearch is built using Java, and includes a bundled version of OpenJDK from the JDK maintainers (GPLv2+CE) within each distribution. The bundled JVM is the recommended JVM and is located within the jdk directory of the Elasticsearch home directory.

To use your own version of Java, set the JAVA_HOME environment variable. If you must use a version of Java that is different from the bundled JVM, we recommend using a supported LTS version of Java. Elasticsearch will refuse to start if a known-bad version of Java is used. The bundled JVM directory may be removed when using your own JVM.

根据启动信息我们看到Elasticsearch7.9.3推荐使用JDK11

下载解压jdk11

tar -zxvf jdk-11.0.9_linux-x64_bin.tar.gz

jdk11路径

#jdk11路径,未配置环境变量就不影响jdk8环境
[root@localhost jdk-11.0.9]# pwd
/home/jdk-11.0.9

配置elasticsearch

vim elasticsearch-7.9.3/bin/elasticsearch

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

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

#在”source "`dirname "$0"`"/elasticsearch-env“前加入

image.png

测试

http://你的ip:9200/

image.png