简体   繁体   English

以 root 用户身份运行弹性搜索

[英]Run elastic search as root user

Im getting below error when i tried to start elastic search 5.0 with command ./elasticsearch and getting below error.当我尝试使用命令./elasticsearch启动弹性搜索 5.0 并出现以下错误时,我遇到了以下错误。

[2016-11-23T13:44:09,507][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:116) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73) ~[elasticsearch-5.0.1.jar:5.0.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:96) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:155) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286) ~[elasticsearch-5.0.1.jar:5.0.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:112) ~[elasticsearch-5.0.1.jar:5.0.1]
    ... 6 more

I tried to start by switching to other user and tried sudo ./elasticsearch and got the same error.我尝试首先切换到其他用户并尝试sudo ./elasticsearch并得到相同的错误。 How to start elastic search as root user ?如何以 root 用户身份启动弹性搜索?

Elasticsearch can't be run an root user. Elasticsearch 不能以 root 用户运行。 Elasticsearch itself restricts this. Elasticsearch 本身对此进行了限制。 A new user named elasticsearch and group named elasticsearch is automatically created when we install elasticsearch.当我们安装 elasticsearch 时,会自动创建一个名为 elasticsearch 的新用户和名为 elasticsearch 的组。 Can check entries by using following commands可以使用以下命令检查条目

$ sudo less /etc/passwd | grep "elasticsearch"
$ sudo less /etc/group | grep "elasticsearch"

We need to change ownership of all elasticsearch related files .我们需要更改所有与 elasticsearch 相关的文件的所有权。 Please follow the steps mentioned below.请按照下面提到的步骤操作。

Steps:步骤:

1.Change owership of all ES related files from root to elasticsearch using example cmd below. 1.使用下面的示例cmd将所有ES相关文件的所有权从root更改为elasticsearch。

$ sudo chown elasticsearch:elasticsearch -R /usr/share/elasticsearch
$ sudo chown elasticsearch:elasticsearch -R /var/log/elasticsearch
$ sudo chown elasticsearch:elasticsearch -R /var/lib/elasticsearch
$ sudo chown elasticsearch:elasticsearch -R /etc/default/elasticsearch
$ sudo chown elasticsearch:elasticsearch -R /etc/elasticsearch

2.Open /etc/default/elasticsearch file and do the following things 2.打开/etc/default/elasticsearch文件,做以下事情

  a)JAVA_HOME=your/java/home/path
  b)add the following entries at the end
      i)   START_DAEMON=true
      ii)  ES_USER=elasticsearch
      iii) ES_GROUP=elasticsearch

3.Now enable elasticsearch service and start 3.现在启用elasticsearch服务并启动

  $ sudo systemctl enable elasticsearch
  $ sudo systemctl start elasticsearch
  $ sudo systemctl status elasticsearch

4.Test elasticsearch by using curl. 4.使用curl测试elasticsearch。 Say your host ip is 192.168.5.194 and ES running on port 9200假设您的主机 IP 是 192.168.5.194 并且 ES 在端口 9200 上运行

$ curl -X GET ‘192.168.5.194:9200’

DONE!!完成!!

Ref.参考: https://stackoverflow.com/a/48390311/1445978 : https://stackoverflow.com/a/48390311/1445978

Root cause of this issue is: ElasticSearch is not allowed to run from root owner.此问题的根本原因是:不允许从 root 所有者运行 ElasticSearch。 There is another possiblity for this issue "Java path is set for root user only not for all other users".这个问题还有另一种可能性“Java 路径只为 root 用户设置,而不是为所有其他用户设置”。 Solution of this issue:此问题的解决方案:

Step 1: Change the ownership of elasticSearch directory from root to other user by command.步骤1:通过命令将elasticSearch目录的所有权从root更改为其他用户。 $sudo chown -R current_User:Group_Name elasticsearch-5.5.0 $sudo chown -R current_User:Group_Name elasticsearch-5.5.0

Setp 2: Check Java set in classpath for current user[not only for root]. Setp 2:检查当前用户在类路径中设置的Java [不仅对于 root]。 If command : $java -version or echo $JAVA_HOME command giving empty result.如果命令: $java -version 或 echo $JAVA_HOME 命令给出空结果。 That means we should set Java in classpath [system env varible] for current user then Follow Step 3. otherwise start elasticsearch service.这意味着我们应该在 classpath [system env varible] 中为当前用户设置 Java,然后按照步骤 3。否则启动 elasticsearch 服务。

Step 3: Edit /etc/profile and add two lines as per your system dir export JAVA_HOME="Java dir location"第 3 步:编辑 /etc/profile 并根据您的系统目录添加两行 export JAVA_HOME="Java dir location"

export PATH=$JAVA_HOME/bin:$PATH Run $source source /etc/profile export PATH=$JAVA_HOME/bin:$PATH 运行 $source source /etc/profile

After this run elasticSearch service.在此之后运行 elasticSearch 服务。 It worked for me perfectly.它非常适合我。

There are two ways to solve this problem :有两种方法可以解决这个问题:

Method1: download zip file n unzip then start by following command方法一:下载 zip 文件 n 解压后按以下命令启动

bin/elasticsearch -Des.insecure.allow.root=true -d

Method2:方法二:

vi bin/elasticsearch

Add property for allow root:添加允许 root 的属性:

ES_JAVA_OPTS="-Des.insecure.allow.root=true"

Save and close.保存并关闭。 You can start by root now.您现在可以从 root 开始。

I had the same problem and I had to connect with another user.我遇到了同样的问题,我不得不与另一个用户连接。 But first, I had to grant him the rights to execute the bin/elasticsearch.但首先,我必须授予他执行 bin/elasticsearch 的权限。

A little late reply, but relevant still now.回复有点晚,但现在仍然相关。 I faced the same problem when i followed this , the last resort was to change the ownership of the folders which got un-zipped.我在遵循此操作时遇到了同样的问题,最后的方法是更改​​解压缩的文件夹的所有权。

Just did sudo chown <nonrootuser> <unzipped-es-folder> -R does the trick.只是sudo chown <nonrootuser> <unzipped-es-folder> -R做到了这一点。

PS i was doing it on Ubuntu 17.04 LTS. PS 我是在 Ubuntu 17.04 LTS 上做的。

从根文件夹运行 bin/elasticsearch 是一个常见的错误。

If you're trying to run with systemd or as a service make sure that your .service file is running as user and group elasticsearch.如果您尝试使用systemd或作为服务运行,请确保您的.service文件以用户和组.service运行。 You can specify your user and group under the Service field.您可以在“服务”字段下指定您的用户和组。

It's usually located in /etc/systemd/system/elasticsearch.service :它通常位于/etc/systemd/system/elasticsearch.service

[Service]
Type=simple
ExecStart=/usr/share/elasticsearch/bin/elasticsearch
Restart=on-failure
RestartSec=10
KillMode=process
User=elasticsearch
Group=elasticsearch

-Ees.insecure.allow.root method did not work for me, as I was on version 7.9.0. -Ees.insecure.allow.root方法对我不起作用,因为我使用的是 7.9.0 版。

And I was too lazy to go for chown method, mentioned by @Devasish .而且我懒得去使用@Devasish提到的chown方法。

Instead, tried a bit lengthy one:相反,尝试了一个有点冗长的:

Create a non-root user for elastic-search:为elastic-search创建一个非root用户:

ubuntu ~ # adduser elasticuser

Must use adduser command, not useradd.必须使用adduser命令,而不是 useradd。 adduser will auto-create the home directory. adduser将自动创建主目录。

Copy elastic-search folder from root's home-directory to elasticuser's home-directory:将 elastic-search 文件夹从 root 的主目录复制到 elasticuser 的主目录:

ubuntu ~ # cp -R ./elasticsearch-7.9.0 /home/elasticuser/elasticsearch-7.9.0

Switch to the non-root user:切换到非root用户:

ubuntu ~ # su - elasticuser

Now, run elastic-search from the non-root user:现在,从非 root 用户运行 elastic-search:

elasticuser@ubuntu ~ $ ./elasticsearch-7.9.0/bin/elasticsearch

Why to run everything as a root user.为什么要以 root 用户身份运行一切。 Use a normal user instead of root user.使用普通用户而不是 root 用户。

Switch to normal user and run it.切换到普通用户并运行它。 If you don't have a any other user refer to Linuxize document on creating a user.如果您没有任何其他用户,请参阅有关创建用户的Linuxize 文档

If you can't run it as a normal user then check the permissions for the file, Give complete access to the user over the file or folder using chmod 777 <elastic_search_folder> .如果您不能以普通用户身份运行它,请检查文件的权限,使用chmod 777 <elastic_search_folder>授予用户对文件或文件夹的完全访问权限。

Please refer to chmod wiki document for further details.请参阅chmod wiki 文档以获取更多详细信息。

If you want to use root user then do the following command from the elastic search folder.如果要使用 root 用户,请从弹性搜索文件夹执行以下命令。

./elasticsearch -Des.insecure.allow.root=true

re-run the the elastic search.重新运行弹性搜索。 It should definately work.它应该肯定有效。

This was asked before for ES2 ( How to run Elasticsearch 2.1.1 as root user in Linux machine )这是 ES2 之前问过的( 如何在 Linux 机器中以 root 用户身份运行 Elasticsearch 2.1.1

The same solution may work for 5.相同的解决方案可能适用于 5。

As stated previously, you should probably not so this..如前所述,您可能不应该这样..

Create a separate user without giving sudo privileges.创建一个单独的用户而不授予sudo权限。 ex: adduser elasticsearch then grant ownership of the folder to that user ex: chown -R elasticsearch:elasticsearch elasticsearch-folder then switch to that user ex: su elasticsearch Now try running the service ex: ./elasticsearch-xxx/bin/elasticsearch例如: adduser elasticsearch然后将该文件夹的所有权授予该用户例如: chown -R elasticsearch:elasticsearch elasticsearch-folder ./elasticsearch-xxx/bin/elasticsearch : ./elasticsearch-xxx/bin/elasticsearch chown -R elasticsearch:elasticsearch elasticsearch-folder然后切换到该用户例如: su elasticsearch ./elasticsearch-xxx/bin/elasticsearch现在尝试运行服务例如: ./elasticsearch-xxx/bin/elasticsearch

On centos 8,在centos 8上,

adduser elasticuser
chown -R elasticuser:elasticsearch /usr/share/elasticsearch/
chown -R elasticuser:elasticsearch /etc/sysconfig/elasticsearch
chown -R elasticuser:elasticsearch /etc/elasticsearch
chown -R elasticuser:elasticsearch /var/log/elasticsearch/
chown -R elasticuser:elasticsearch /var/lib/elasticsearch

To run elasticsearch:运行弹性搜索:

su elasticuser
/usr/share/elasticsearch/bin/elasticsearch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM