实用脚本 --- Linux下Jdk和Tomcat自动安装shell脚本总结
系统环境为:ubuntu 14.04
一、JDK 自动安装脚本
jdk自动安装bash shell脚本,截止今天(2014/10/15)亲测可用:
sudo su #切换到root权限 mkdir /usr/local/java cd /usr/local/java #download jdk 1.7.67 wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz #extract jdk tar -xvf jdk-7u67-linux-x64.tar.gz #set environment export JAVA_HOME="/usr/local/java/jdk1.7.0_67" if ! grep "JAVA_HOME=/usr/local/java/jdk1.7.0_67" /etc/environment then echo "JAVA_HOME=/usr/local/java/jdk1.7.0_67" | sudo tee -a /etc/environment echo "export JAVA_HOME" | sudo tee -a /etc/environment echo "PATH=$PATH:$JAVA_HOME/bin" | sudo tee -a /etc/environment echo "export PATH" | sudo tee -a /etc/environment echo "CLASSPATH=.:$JAVA_HOME/lib" | sudo tee -a /etc/environment echo "export CLASSPATH" | sudo tee -a /etc/environment fi #update environment source /etc/environment ehco "jdk is installed !"
简单解释一下:用wget直接下载jdk和tar.gz包,然后解压,然后再修改系统环境变量,并更新。
输入javac 或java -version即可进行验证。
JAVA_HOME=/usr/jdk1.7.0_67
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
CLASSPATH=.:$JAVA_HOME/lib
export CLASSPATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME=/usr/local/java/jdk1.7.0_67
二、Tomcat 自动安装脚本
#install tomcat sduo su mkdir /usr/local/tomcat cd /usr/local/tomcat wget http://apache.fayea.com/apache-mirror/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar.gz tar -xvf apache-tomcat-7.0.56.tar.gz #change port 8080 to 80 sed -i 's/8080/80/' apache-tomcat-7.0.56/conf/server.xml #startup nohup ./apache-tomcat-7.0.56/bin/startup.sh
注:同样是使用wget进行下载Tomcat tar.gz包,然后解压,解压完成以后使用sed命令更改默认端口号8080为80,然后使用nohup命令进行后台服务启动!
附windows环境下安装jdk配置:
jdk官方下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
windows: 1)在系统变量里新建JAVA_HOME变量,变量值为:C:\Java\jdk1.7.0_67(根据自己的安装路径填写) 2)新建classpath变量,变量值为:.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar 3)在path变量(已存在不用新建)添加变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin(注意变量值之间用“;”隔开)
参考:
1、how-to-automate-download-and-installation-of-java-jdk-on-linux
2、linux shell 脚本攻略学习19--sed命令详解