java 8 安装
下载tar包:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
解压java包到: mkdir /usr/local/java tar xzvf jdk-8u181-linux-x64.tar.gz
添加环境变量:
vim /etc/profile export JAVA_HOME=/usr/local/java/jdk1.8.0_181 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin source /etc/profile
测试安装是否成功:
elasticsearch 安装
下载tar包:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz
解压缩后直接运行即可
[root@elastic elasticsearch-6.4.0]# ./bin/elasticsearch -d [2018-09-12T17:53:48,547][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.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.0.jar:6.4.0] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.0.jar:6.4.0] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.0.jar:6.4.0] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.0.jar:6.4.0] ... 6 more
运行报错:can not run elasticsearch as root
root用户不能执行elasticsearch,所以需要创建额外的用户(参考https://my.oschina.net/topeagle/blog/591451?fromerr=mzOr2qzZ):
创建elsearch用户组及elsearch用户
[root@elastic elasticsearch-6.4.0]# groupadd elsearch [root@elastic elasticsearch-6.4.0]# useradd elsearch -g elsearch -p elasticsearch
最好修改一下密码,密码elasticsearch也没办法直接用,因为是需要输入加密后的字符串,加密后是elasticsearch的字符串我也不晓得是啥
[root@elastic elasticsearch-6.4.0]# passwd elsearch
Changing password for user elsearch.New password: BAD PASSWORD: The password is shorter than 8 charactersRetype new password: passwd: all authentication tokens updated successfully. 修改elasticsearch目录权限
[root@elastic ~]# chown -R elsearch:elsearch elasticsearch-6.4.0
切换用户
[root@elastic elasticsearch-6.4.0]# su elsearch
再次运行elasticsearch
[elsearch@elastic bin]$ ./elasticsearch -d Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker
提示找不到java类,分析原因如下(参考https://discuss.elastic.co/t/error-could-not-find-or-load-main-class-org-elasticsearch-tools-javaversionchecker/82213):
调试运行
[elsearch@elastic bin]$ bash -x elasticsearch
发现问题是在cp jar包的时候,elsearch用户没有权限拷贝root目录下的内容
把elasticsearch整个目录移动到/home/elsearch下后,再次执行,成功
后面又报了两个小错误,
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536][2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]修改配置即可
vi /etc/security/limits.conf 修改 * soft nofile 65536
vi /etc/sysctl.conf 增加 vm.max_map_count=262144
或者 sysctl -w vm.max_map_count=262144 sysctl -psysctl -a|grep vm.max_map_count 查看修改结果
改完后重启,再运行elasticsearch可成功启动