When we are using Elasticsearch, if we are executing with the root permission Elasticsearch
./elasticsearch
There will be the following error
Exception in thread "main" Java.lang.RuntimeException:don ' t run Elasticsearch as root.
At Org.elasticsearch.bootstrap.Bootstrap.initializeNatives (bootstrap.java:94) at
Org.elasticsearch.bootstrap.Bootstrap.setup (bootstrap.java:160) at
Org.elasticsearch.bootstrap.Bootstrap.init (bootstrap.java:286) at
Org.elasticsearch.bootstrap.Elasticsearch.main (elasticsearch.java:35)
refer to the log for complete error details .
This is a condition set for system security considerations. Because Elasticsearch can receive user-entered scripts and execute, for system security reasons,
It is recommended that you create a separate user to run Elasticsearch
Create Elsearch user groups and Elsearch users
Groupadd elsearch
useradd elsearch-g elsearch-p elasticsearch
Change the Elasticsearch folder and internal files to the user and group as Elsearch:elsearch
Chown-r Elsearch:elsearch Elasticsearch
Elasticsearch for you elasticsearch directory name
Switch to Elsearch user restart
Su elsearch #切换账户
cd elasticsearch/bin #进入你的elasticsearch目录下的bin目录
./elasticsearch
After startup, the normal boot log information is printed as follows
[Elsearch@localhost elasticsearch-2.4.0]$./bin/elasticsearch [2016-11-30 09:00:07,658][info][node] [Black Bolt] version[2.4.0], pid[25504], build[ce9f0c7/2016-08-29t09:14:17z] [2016-11-30 09:00:07,674][info][node
] [black Bolt] initializing ... [2016-11-30 09:00:08,248] [INFO] [Plugins] [Black Bolt] modules [Lang-groovy, Reindex, lang-expression], plugins [Elasticsearch-analysis-ik, head], sites [head] [20 16-11-30 09:00:08,267][info][env] [black Bolt] using [1] data paths, mounts [[/home (/dev/mapper/ce Ntos-home)]], net usable_space [172.1GB], net total_space [172.9GB], spins? [possibly], types [XFS] [2016-11-30 09:00:08,267][info][env] [black Bolt] heap size [990.7MB], Comp Ressed ordinary Object pointers [true] [2016-11-30 09:00:08,268][warn][env] [black Bolt] Max file D Escriptors [4096] for elasticsearch process likely too low, consider increasing to at LEast [65536] [2016-11-30 09:00:09,561][info][ik-analyzer] [Dict Loading] Ik/custom/mydict.dic [2016-11-30 0 9:00:09,579][info][ik-analyzer] [Dict Loading] ik/custom/single_word_low_freq.dic [2016-11-30 09:00:09,589] [INFO] [Ik-analyzer] [Dict Loading] ik/custom/ext_stopword.dic [2016-11-30 09:00:09,935][info][node] [black Bolt] Initial
ized [2016-11-30 09:00:09,935][info][node] [black Bolt] starting ... [2016-11-30 09:00:09,975] [INFO] [Transport] [Black Bolt] publish_address {172.17.0.1:9300}, bound_addresses {[::]:9300} [2016-11-30 09:00:09,979][info][discovery ] [Black Bolt] Elasticsearch/ygwbxiwsryejtim4wqhwaa [2016-11-30 09:00:13,003][info][cluster.service ] [Black Bolt] New_master {bolt}{ygwbxiwsryejtim4wqhwaa}{172.17.0.1}{172.17.0.1:9300}, Reason:zen-disco-join ( Elected_as_master, [0] joins received) [2016-11-30 09:00:13,010][info][http ] [Black Bolt] publish_address {172.17.0.1:9200}, bound_addresses {[::]:9200} [2016-11-30 09:00:13,010][info][no De] [Black Bolt] started [2016-11-30 09:00:13,323][info][gateway] [black Bolt] Rec overed [1] indices into cluster_state [2016-11-30 09:00:15,576][info][cluster.routing.allocation] [black Bolt] Cluster h Ealth status changed from [RED] to [yellow] (reason: [Shards started [[[Sports][2]] ...]).
Then if you start again (if you are logged on to the server with root privileges), just run the switch account, and then elasticsearch it.
Su elsearch #切换账户
cd elasticsearch/bin #进入你的elasticsearch目录下的bin目录
./elasticsearch
Elasticsearch Background Start command
./elasticsearch-d
To see if the background command started successfully
PS Aux|grep Elasticsearch
Results
elsearch 3119 4.6 3.2 3535488 250876 pts/1 Sl 16:50 0:09/opt/java/jdk1.7.0_75/bin/java- Xms256m-xmx1g-djava.awt.headless=true-xx:+useparnewgc-xx:+useconcmarksweepgc-xx:cmsinitiatingoccupancyfraction =75-xx:+usecmsinitiatingoccupancyonly-xx:+heapdumponoutofmemoryerror-xx:+disableexplicitgc-dfile.encoding= UTF-8-djna.nosys=true-des.path.home=/home/py-project/elasticsearc-2.4.0-cp/home/py-project/elasticsearch-2.4.0 /lib/elasticsearch-2.4.0.jar:/home/py-project/elasticsearch-2.4.0/lib/* Org.elasticsearch.bootstrap.Elasticsearch start-d elsearch 3254 0.0 0.0 110224 916 PTS/1 s+ 16:54-0:00 grep- -color=auto Elasticsearch