**下载ES文件**
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.zip
unzip elasticsearch-6.3.1.zip
cd elasticsearch-6.3.1/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
tar -xzf elasticsearch-6.3.1.tar.gz
cd elasticsearch-6.3.1/
**安装JAVA**
#下载java到opt目录
mkdir /usr/java
tar zxvf /opt/jdk-8u172-linux-x64.tar.gz -C /usr/java #解压到/usr/java下(重要)
vim /etc/profile #编辑环境变量
#在文件末尾增加以下配置并执行 source /etc/profile 让其生效
JAVA_HOME=/usr/java/jdk1.8.0_172
JRE_HOME=/usr/java/jdk1.8.0_172/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME PATH
#新建一个软链接到/usr/bin 下
ln -s /usr/java/jdk1.8.0_172/bin/java /usr/bin/java
#测试
java -version
运行./bin/elasticsearch
#报错 需要创建用户
[2018-07-17T19:24:45,552][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:140) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.1.jar:6.3.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.1.jar:6.3.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.1.jar:6.3.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.1.jar:6.3.1]
... 6 more
**创建elasticsearch用户**
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
运行./bin/elasticsearch
#提示权限不足
Exception in thread "main" java.nio.file.AccessDeniedException: /opt/elasticsearch-6.3.1/config/jvm.options
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:58)
**设置权限**
chown -R elsearch:elsearch elasticsearch-6.3.1
运行./bin/elasticsearch
curl 127.0.0.1:9200 #成功安装但是外网无法访问
**设置外网访问和按需设置iptables**
vim elasticsearch-6.3.1/config/elasticsearch.yml
#修改:network.host: 0.0.0.0
jps | grep Elasticsearch
kill pid
运行./bin/elasticsearch
#重启后报错虚拟机
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决:切换root账户修改配置limits.conf 添加下面两行然后重启计算机
vim /etc/security/limits.conf
#<domain><type><item><value>
* hard nofile 65536
* soft nofile 65536
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决:切换root账户 vim /etc/sysctl.conf
增加一行 vm.max_map_count=655360
接着执行 sysctl -p
运行./bin/elasticsearch #外网访问成功
喜欢可以收藏或者点赞,有疑问可以留言谢谢。
参考链接
https://www.elastic.co/guide/...
http://immm.in/2018/05/centos...
https://www.cnblogs.com/woxpp...
https://blog.csdn.net/qq_3167...
https://blog.csdn.net/buzaiqq...