CentOS 7.9 安装 Elasticsearch 7.8.1

安装环境

CentOS 安装的是最小版本:CentOS-7-x86_64-Minimal-2009

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

关闭防火墙:

systemctl stop firewalld.service
systemctl disable firewalld.service

前期准备

新建用户

默认情况下,Elasticsearch 不允许使用 root 用户启动。

groupadd esgroup
useradd esapp -g esgroup

修改资源配置

修改 /etc/security/limits.conf 文件,在文件中添加以下内容:

esapp  -  nofile  65535
esapp  -  nproc   4096

修改 /etc/sysctl.conf 文件,在文件中添加以下内容:

vm.max_map_count=262144

禁用内存交换

临时关闭命令:

swapoff -a

永久修改的方法:修改 /etc/fstab 文件,将注释掉所有包含 swap 的行。

全部配置完后,重启电脑,因为有些配置需要重启电脑才能生效。

关于 Java

因为 Elasticsearch 自带了 OpenJDK,所以我这里没有额外安装 JDK。

下载安装

使用 esapp 用户登录,或使用 su - esapp 切换到 esapp 用户,运行下面的命令:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.1-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-7.8.1-linux-x86_64.tar.gz.sha512
tar -xzf elasticsearch-7.8.1-linux-x86_64.tar.gz
cd elasticsearch-7.8.1/

如果在校验时,提示 -bash: shasum: command not found,则需要安装 perl-Digest-SHA

yum install -y perl-Digest-SHA

修改配置文件

cd /home/esapp/elasticsearch-7.8.1/config
cp elasticsearch.yml elasticsearch.yml.bak
vi elasticsearch.yml

network.host: 192.168.0.1 改为 network.host: 0.0.0.0 并取消注释。以便外部浏览器可以访问。

添加 discovery.type: single-node

启动并验证

启动

# 依然使用普通用户
cd /home/esapp/elasticsearch-7.8.1/bin
# 启动
./elasticsearch

检查是否启动成功

打开新的终端,输入下面的命令。

[root@localhost ~]# curl -X GET "localhost:9200/?pretty"
{
  "name" : "localhost.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "7iE1xknOQLiIJiDnK7dJug",
  "version" : {
    "number" : "7.8.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89",
    "build_date" : "2020-07-21T16:40:44.668009Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

在非本地浏览器中访问 http://ES所在机器的IP:9200/,正常的话同样也可以得到上面的信息。
image202112310934021de4oar.png

若尝试使用 root 用户启动,则会报错:

[root@localhost bin]# ./elasticsearch
[2021-12-31T02:26:51,276][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] 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.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127) ~[elasticsearch-cli-7.8.1.jar:7.8.1]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.8.1.jar:7.8.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393) ~[elasticsearch-7.8.1.jar:7.8.1]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.8.1.jar:7.8.1]
        ... 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)
For complete error details, refer to the log at /home/esapp/elasticsearch-7.8.1/logs/elasticsearch.log

相关资料

Install Elasticsearch from archive on Linux or MacOS

Important System Configuration

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值