建立软连接,好处可以处理多个版本的需要,方便环境变量的配置。相当于windows下的快捷方式!
博主,我这里以jdk为例,对于大数据的其他子项目的搭建,一样的操作。方便!这里我不多赘述。
如何建立jdk1.7版本的软链接?
[hadoop@master app]$ pwd
/home/hadoop/app
[hadoop@master app]$ ln -s jdk1.7.0_79 jdk
#java export JAVA_HOME=/home/hadoop/app/jdk export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin
[root@master hadoop]# vim /etc/profile [root@master hadoop]# source /etc/profile [root@master hadoop]# su hadoop [hadoop@master ~]$ java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode) [hadoop@master ~]$
如何删除建立好的软链接?
[root@master app]# pwd /home/hadoop/app [root@master app]# ll total 326920 lrwxrwxrwx. 1 hadoop hadoop 11 Apr 12 09:55 jdk -> jdk1.7.0_79 drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79 drwxr-xr-x. 8 hadoop hadoop 4096 Aug 5 2015 jdk1.8.0_60 -rw-r--r--. 1 hadoop hadoop 153512879 Oct 23 2015 jdk-7u79-linux-x64.tar.gz -rw-r--r--. 1 hadoop hadoop 181238643 Sep 3 2016 jdk-8u60-linux-x64.tar.gz [root@master app]# rm -rf jdk [root@master app]# ll total 326920 drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79 drwxr-xr-x. 8 hadoop hadoop 4096 Aug 5 2015 jdk1.8.0_60 -rw-r--r--. 1 hadoop hadoop 153512879 Oct 23 2015 jdk-7u79-linux-x64.tar.gz -rw-r--r--. 1 hadoop hadoop 181238643 Sep 3 2016 jdk-8u60-linux-x64.tar.gz [root@master app]#
如何建立jdk1.8版本的软链接?
[hadoop@master app]$ pwd /home/hadoop/app [hadoop@master app]$ ll total 326920 drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79 drwxr-xr-x. 8 hadoop hadoop 4096 Aug 5 2015 jdk1.8.0_60 -rw-r--r--. 1 hadoop hadoop 153512879 Oct 23 2015 jdk-7u79-linux-x64.tar.gz -rw-r--r--. 1 hadoop hadoop 181238643 Sep 3 2016 jdk-8u60-linux-x64.tar.gz [hadoop@master app]$ ln -s jdk1.8.0_60 jdk [hadoop@master app]$ ll total 326920 lrwxrwxrwx. 1 hadoop hadoop 11 Apr 12 10:15 jdk -> jdk1.8.0_60 drwxr-xr-x. 8 hadoop hadoop 4096 Apr 11 2015 jdk1.7.0_79 drwxr-xr-x. 8 hadoop hadoop 4096 Aug 5 2015 jdk1.8.0_60 -rw-r--r--. 1 hadoop hadoop 153512879 Oct 23 2015 jdk-7u79-linux-x64.tar.gz -rw-r--r--. 1 hadoop hadoop 181238643 Sep 3 2016 jdk-8u60-linux-x64.tar.gz [hadoop@master app]$
[hadoop@master app]$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) [hadoop@master app]$
成功!
补充
对于多版本的安装,其实还有另外一种方式,如
/home/hadoop/app/jdk/jdk1.7.0_79
/home/hadoop/app/jdk/jdk1.8.0_60
然后,每次去环境变量配置文件/etc/proflie下,去修改
#java export JAVA_HOME=/home/hadoop/app/jdk/jdk1.7.0_79 或 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin
或
#java export JAVA_HOME=/home/hadoop/app/jdk/jdk1.8.0_60 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin