安装环境
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/
,正常的话同样也可以得到上面的信息。
若尝试使用 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
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于