查看Linus中自带的jdk ,设置JAVA_HOME
在配置hadoop是,进行格式化hadoop的时候,出现找不到jdk
我用Red hat是32位的,没有现成的32位的,敲java , 发现本机有java ,就找了一下其位置
找到了jdk-1.6.0
which java
[root@host2 hadoop-1.1.2]# which java
/usr/bin/java
[root@host2 hadoop-1.1.2]# ls /usr/bin/java
/usr/bin/java
[root@host2 hadoop-1.1.2]# ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 22 Jun 20 03:00 /usr/bin/java -> /etc/alternatives/java
[root@host2 hadoop-1.1.2]# ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 39 Jun 20 03:00 /etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk/bin/java (可以看出文件是link ,是个链接)
[root@host2 hadoop-1.1.2]# ls -l /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
-rwxr-xr-x. 1 root root 36548 Oct 25 2011 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
[root@host2 hadoop-1.1.2]# cd /usr/lib/jvm/jre-1.6.0-openjdk
[root@host2 jre-1.6.0-openjdk]# ls
bin lib
如此来,可以暂时的断定是 /usr/lib/jvm/jre-1.6.0-openjdk
root用户下改配置文件 : vi /etc/profile
找到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
在下面写上:
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
:wq 保存退出
用echo $JAVA_HOME
在进行格式化:
[root@host2 jre-1.6.0-openjdk]# hadoop namenode -format
16/07/11 19:16:37 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = host2/192.168.8.202
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 1.1.2
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.1 -r 1440782; compiled by 'hortonfo' on Thu Jan 31 02:03:24 UTC 2013
************************************************************/
16/07/11 19:16:38 INFO util.GSet: VM type = 32-bit
16/07/11 19:16:38 INFO util.GSet: 2% max memory = 17.77875 MB
16/07/11 19:16:38 INFO util.GSet: capacity = 2^22 = 4194304 entries
16/07/11 19:16:38 INFO util.GSet: recommended=4194304, actual=4194304
16/07/11 19:16:38 INFO namenode.FSNamesystem: fsOwner=root
16/07/11 19:16:38 INFO namenode.FSNamesystem: supergroup=supergroup
16/07/11 19:16:38 INFO namenode.FSNamesystem: isPermissionEnabled=true
16/07/11 19:16:38 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100
16/07/11 19:16:38 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s)
16/07/11 19:16:38 INFO namenode.NameNode: Caching file names occuring more than 10 times
16/07/11 19:16:38 INFO common.Storage: Image file of size 110 saved in 0 seconds.
16/07/11 19:16:38 INFO namenode.FSEditLog: closing edit log: position=4, editlog=/home/hadoop/dfs/filesystem/name/current/edits
16/07/11 19:16:38 INFO namenode.FSEditLog: close success: truncate to 4, editlog=/home/hadoop/dfs/filesystem/name/current/edits
16/07/11 19:16:39 INFO common.Storage: Storage directory /home/hadoop/dfs/filesystem/name has been successfully formatted.
16/07/11 19:16:39 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at host2/192.168.8.202
************************************************************/
可以了格式化,但是运行不起来hadoop
star-all.sh
[hadoop@host2 ~]$ start-all.sh
starting namenode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-namenode-host2.out
host8: starting datanode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-datanode-host8.out
host2: starting datanode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-datanode-host2.out
host6: starting datanode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-datanode-host6.out
host8: Error: JAVA_HOME is not set.
host2: Error: JAVA_HOME is not set.
host6: Error: JAVA_HOME is not set.
host2: starting secondarynamenode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-secondarynamenode-host2.out
host2: Error: JAVA_HOME is not set.
jobtracker running as process 5607. Stop it first.
host6: starting tasktracker, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-tasktracker-host6.out
host2: starting tasktracker, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-tasktracker-host2.out
host8: starting tasktracker, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-tasktracker-host8.out
host6: Error: JAVA_HOME is not set.
host2: Error: JAVA_HOME is not set.
host8: Error: JAVA_HOME is not set.
看来,是不行的,进行查找配置的dt.jar 和tools.jar是找不见的
看来还得去下载官方的jdk
下载"1.7.0_79"
下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
或者下载1.6 ,
下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u21-oth-JPR
下载后用tar -zxvf jdk-7u79-linux-i586.tar.gz 解压到/opt 目录下
root 用户下修改
vim ~/.bashrc
export JAVA_HOME=/opt/jdk1.7.0_79
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source ~/.bashrc
update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 300
update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 300
update-alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 300
update-alternatives --config java
选择带有jdk1.7.0_79 的选项
即可以了