0%

Linux安装Elasticsearch

安装命令

1
2
3
4
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-x86_64.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-x86_64.rpm.sha512
shasum -a 512 -c elasticsearch-7.9.3-x86_64.rpm.sha512
sudo rpm --install elasticsearch-7.9.3-x86_64.rpm

需要先安装wget

1
yum install wget

安装目录**/usr/share/elasticsearch**

启动

1
2
cd elasticsearch-<version>
./bin/elasticsearch

如果你想把 Elasticsearch 作为一个守护进程在后台运行,那么可以在后面添加参数 -d

启动报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_191/jre] does not meet this requirement
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_191/jre] does not meet this requirement
[2020-10-26T17:51:37,275][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.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)
For complete error details, refer to the log at /var/log/elasticsearch/elasticsearch.log
2020-10-26 09:51:37,598820 UTC [5212] ERROR CLogger.cc@310 Cannot log to named pipe /tmp/elasticsearch-8630107584639609731/controller_log_5047 as it could not be opened for writing
原因:

  为了安全不允许使用root用户启动

解决:

  es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户

创建用户:elasticsearch. adduser elasticsearch

创建用户密码,需要输入两次. passwd elasticsearch

将对应的文件夹权限赋给该用户. chown -R elasticsearch /usr/share/elasticsearch

切换至elasticsearch用户. su elasticsearch

切换用户报错

1
This account is currently not available
原因:

​ 用户的shell禁止登录

解决:

​ 用cat看看 elasticsearch`的帐号信息

1
cat /etc/passwd | grep elasticsearch

发现它的shell是“/sbin /nologin”,需要改成“/bin/bash”

再次启动报错

1
/var/log/elasticsearch/elasticsearch_server.json (权限不够)
解决:
1
chown elasticsearch /var/log -R

再次启动报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
uncaught exception in thread [main]
java.lang.IllegalStateException: failed to obtain node locks, tried [[/var/lib/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:301)
at org.elasticsearch.node.Node.<init>(Node.java:344)
at org.elasticsearch.node.Node.<init>(Node.java:277)
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227)
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 /var/log/elasticsearch/elasticsearch.log
原因:

​ 可能是因为之前运行的es还没有正常关闭

解决:
1
2
ps -ef|grep elastic
kill -9 xxx

验证是否启动成功

打开另一个终端,执行以下操作

1
curl 'http://localhost:9200/?pretty'

以下响应表示成功,意味着你现在已经启动并运行一个 Elasticsearch 节点了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "w_tfyzSiSIy3ArcZ4_MwFw",
"version" : {
"number" : "7.9.3",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868",
"build_date" : "2020-10-16T10:36:16.141335Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}