Elasticsearch在Centos 6.6上找不到Java,所有路径变量都已设置并正常工作 [英] Java not found by Elasticsearch on Centos 6.6, all path variables are set and working
问题描述
我最近开了一个流浪汉服务器,想让Elasticsearch继续使用它。因此,我在chef / Centos-6.6流浪云虚拟机上安装了Oracle Java和ES。我使用etc / profile.d中的shell脚本设置我的Java路径。
I recently spun up a vagrant server and wanted to get Elasticsearch going on it. So, I installed Oracle Java and ES on a "chef/Centos-6.6" vagrant cloud VM. I set my Java path using a shell script in "etc/profile.d".
这是我的配置脚本:
#!/usr/bin/env bash
yum -y update
wget -O /opt/jdk-7u67-linux-x64.tar.gz --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz"
tar xzf /opt/jdk-7u67-linux-x64.tar.gz -C /opt/
touch /etc/profile.d/java.sh
echo "export JAVA_HOME=/opt/jdk1.7.0_67" >> /etc/profile.d/java.sh
echo "export JRE_HOME=/opt/jdk1.7.0_67/jre" >> /etc/profile.d/java.sh
echo "export PATH=$PATH:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin" >> /etc/profile.d/java.sh
rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
REPO="[elasticsearch-1.3]
name=Elasticsearch repository for 1.3.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/1.3/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1"
echo "$REPO" > /etc/yum.repos.d/elasticsearch.repo
yum install -y elasticsearch
安装一切顺利。但是,当我运行sudo service elasticsearch start时,我得到:
The install all goes fine. However, when I run "sudo service elasticsearch start" I get:
which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
但如果我为家庭用户回显$ PATH我得到:
but if I "echo $PATH" for home user i get:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin:/home/vagrant/bin
和root用户$ PATH我得到:
and for root user $PATH i get:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin
和echo $ JAVA_HOME我得到:
and "echo $JAVA_HOME" i get:
/opt/jdk1.7.0_67
如果我运行哪个java我获取:
if I run "which java" i get:
/opt/jdk1.7.0_67/bin/java
如果我运行java,它会显示手册页。
and if I run "java" it shows up with the man page.
如何在弹性搜索中查找java的路径?为什么只查看默认的Centos路径?我在这里缺少什么?
How is it that elasticsearch is not looking in my path for java? Why is it only looking in the default Centos path? What am i missing here?
推荐答案
您的问题的根源可能是init脚本(本例中为Elastic init脚本)看不到大多数环境变量(例如 JAVA_HOME
, JRE_HOME
等)。
The source of your problem is probably that init scripts (Elastic init script in this case) don't see most environment variables (eg JAVA_HOME
, JRE_HOME
, etc).
如果你看一下 ElasticSearch init脚本,您将看到 PATH
变量在该init脚本中显式设置, JAVA_HOME
是通过循环预定义的一组可能位置来确定:
If you look at the ElasticSearch init script, you will see that PATH
variable is set explicitly in that init script and JAVA_HOME
is determined by looping through predefined set of possible locations:
JDK_DIRS="/usr/lib/jvm/jdk-7-oracle-x64 /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-7-openjdk /usr/lib/jvm/java-7-openjdk-amd64/ /usr/lib/jvm/java-7-openjdk-armhf /usr/lib/jvm/java-7-openjdk-i386/ /usr/lib/jvm/default-java"
所以你可以将你的Java安装例如放到 / usr / lib / jvm / jdk-7-orac le-x64
目录和init脚本应该选择它。
So you could put your Java installation for example to /usr/lib/jvm/jdk-7-oracle-x64
directory and the init script should pick it up.
更新
查看init脚本我注意到你可以在 / etc / default / elasticsearch $ c中设置
JAVA_HOME
$ c>跳过如上所述的预定义JDK位置的循环(来源)。
Looking at the init script I noticed that you can set JAVA_HOME
in /etc/default/elasticsearch
to skip looping through the predefined JDK locations as mentioned above (Source).
这篇关于Elasticsearch在Centos 6.6上找不到Java,所有路径变量都已设置并正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!