Centos 7 installation es and exception handling

First, we download the zip package from the official website:
(Official website: https://www.elastic.co/downloads/elasticsearch)

 

 

 

 

 

It may be very slow to download directly using the browser. I usually copy the download link and then wget it down:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.0.zip

If there is no accident, the installation should be successful.

The next step is to run, this is the key, first we go to the installation directory of the installation directory elasticsearch, usually in:
cd /usr/bin/elasticsearch-5.2.0

At this time, if you run elasticsearch directly, the following error will be reported:
Execution:  bin/elasticsearch
Error message:

Exception in thread "main" org.elasticsearch.bootstrap.BootstrapException: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/config
Likely root cause: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/config ...

See picture:

 

There is an issue of this error on elasticsearch github ( https://github.com/elastic/ansible-elasticsearch/issues/58)
If you are interested, you can look at the specific cause of this error. I mainly provide solutions here.

I think this error is mainly because the configuration file cannot be found, but if you start elasticsearch directly in the installation directory, elasticsearch will only find the config folder in the current directory. If it is installed as a service, the configuration file should be found. But I didn't try it, I'll try it later.

The problem is known, we can directly copy the elasticsearch configuration file in the /etc directory:

 cp -r /etc/elasticsearch /usr/share/elasticsearch/config

At this time, we will not report the error just now when we start again. Let's try again:
bin/elasticsearch

As expected, the following error will be prompted at this time:

[2017-01-17T21:54:48,798][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:125) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.2.jar:5.1.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
        ... 6 more

The reason for this error is that elasticsearch is not allowed to use root to start, so we need to create a new user to start elasticsearch to solve this problem (reference: https://my.oschina.net/topeagle/blog/591451?fromerr=mzOr2qzZ )

The specific operations are as follows:

➜  ~ groupadd elsearch
➜  ~ useradd elsearch -g elsearch -p elsearch
➜  ~ cd /usr/share  
➜   chown -R elsearch:elsearch elasticsearch 
➜  su elsearch

At this time, when the user starts elasticsearch, under normal circumstances, it can be successful at this time, and some errors may occur, such as:

hcw-X450VC% ./elasticsearch
2017-01-17 21:03:31,158 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:541)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:258)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)
    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
    at org.elasticsearch.common.logging.LogConfigurator.configureStatusLogger(LogConfigurator.java:125)
    at org.elasticsearch.common.logging.LogConfigurator.configureWithoutConfig(LogConfigurator.java:67)
    at org.elasticsearch.cli.Command.main(Command.java:85)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82)

This is because elasticsearch needs to read and write configuration files, and we need to give permissions to the config folder. The elsearch user is newly created above. The elsearch user does not have read and write permissions, so an error will still be reported. The solution is to switch to the administrator account and give permissions. :

sudo -i
chmod -R 775 config

At this time, you can get up and see the effect:

 

View in browser:

 

So far, centos 7 installation of elasticsearch is complete

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325253041&siteId=291194637