Debian 7 Wheezy 安装Oracle JDK6, JDK5和Tomcat6
网上搜的很多安装方法都无效, 包括 apt-get install, sudo apt-get install java-package, sudo apt-get install java-package 这些, 在Debian Wheezy上都无效.
所以只能用最直接的安装方法了. 因为开发环境要用到JDK5和JDK6, 所以先到Oracle的网站上下载了5和6的安装包, 分别是jdk-1_5_0_22-linux-amd64.bin 和 jdk-6u45-linux-x64.bin
以下是安装步骤:
分别解开两个安装包, 移动到/usr/lib/jvm
184 chmod a+x jdk-1_5_0_22-linux-amd64.bin
186 ./jdk-1_5_0_22-linux-amd64.bin
190 sudo mv jdk1.5.0_22/ /usr/lib/jvm/
192 chmod a+x jdk-6u45-linux-x64.bin
194 ./jdk-6u45-linux-x64.bin
196 sudo mv jdk1.6.0_45/ /usr/lib/jvm/
将 /usr/lib/jvm/default-java -> java-1.6.0-openjdk-amd64 的软链删除, 添加到jdk1.6.0_45的软链:
sudo rm default-java
sudo ln -s jdk1.6.0_45 default-java
这一步在系统自带的tomcat6中, 用于开机启动的 /etc/init.d/tomcat6 脚本中会用到, 不修改的话会导致启动时以open jdk为jvm.
将JDK5 and JDK6 加入alternatives:
sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.5.0_22/bin/java” 1
sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.6.0_45/bin/java” 2
sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/jdk1.6.0_45/bin/javaws” 2
再将java和javaws切换到JDK6:
sudo update-alternatives –config java
sudo update-alternatives –config javaws
查看java版本对不对:
java -version
添加JAVA_HOME:
sudo vi /etc/profile
在 export PATH的后面添加 export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45/
安装Tomcat6
因为没有找到Tomcat5的64位安装包, 所以只好用Tomcat6, 命令很简单
sudo apt-get install tomcat6
命令行输出信息:
Creating config file /etc/default/tomcat6 with new version
Adding system user `tomcat6′ (UID 115) …
Adding new user `tomcat6′ (UID 115) with group `tomcat6′ …
Now creating home directory `/usr/share/tomcat6′.
Creating config file /etc/logrotate.d/tomcat6 with new version
[ ok ] Starting Tomcat servlet engine: tomcat6.
这时候就已经可以通过 sudo service tomcat6 status 来查看运行信息了.
访问http://本机IP:8080/ 就可以看到tomcat It works的信息, 上面提供了以下重要的信息:
CATALINA_HOME in /usr/share/tomcat6
CATALINA_BASE in /var/lib/tomcat6
web项目的放置目录: /var/lib/tomcat6/webapps/ROOT/index.html
配置Tomcat6不要自启动. 因为Debian Wheezy在安装tomcat6的时候自动将其设置位开机启动了, 而开发中是在有需要是才打开的, 需要将其从开机启动的服务中挪出去. 这里需要用到的命令是update-rc.d 参考的是这篇文章
首先查看一下tomcat6都在哪些启动level中出现 ls -l /etc/rc?.d/*apache2
结果是
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc0.d/K01tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc1.d/K01tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc2.d/S16tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc3.d/S16tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc4.d/S16tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc5.d/S16tomcat6 -> ../init.d/tomcat6
lrwxrwxrwx 1 root root 17 May 19 01:02 /etc/rc6.d/K01tomcat6 -> ../init.d/tomcat6
可以看到, 在level 2,3,4,5中是启动, 在leve0,1,6中是关闭
配置其不随开机启动
删除自启动服务用的命令是 update-rc.d -f tomcat6 remove
添加自启动服务用的命令是 update-rc.d tomcat6 defaults
自定义启动级别的命令是 update-rc.d tomcat6 start 20 2 3 4 5 . stop 80 0 1 6 , 会得到以下的结果:
Adding system startup for /etc/init.d/tomcat6 …
/etc/rc0.d/K80apache2 -> ../init.d/tomcat6
/etc/rc1.d/K80apache2 -> ../init.d/tomcat6
/etc/rc6.d/K80apache2 -> ../init.d/tomcat6
/etc/rc2.d/S20apache2 -> ../init.d/tomcat6
/etc/rc3.d/S20apache2 -> ../init.d/tomcat6
/etc/rc4.d/S20apache2 -> ../init.d/tomcat6
/etc/rc5.d/S20apache2 -> ../init.d/tomcat6