/etc/profile
配置环境变量:
echo -e "# jdk_liuhang\nexport JAVA_HOME=/data/jdk1.8.0_151\nexport JRE_HOME=$JAVA_HOME/jre\nexport PATH=$PATH:$JAVA_HOME/bin\nexport CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib" >> /etc/profile
配置文件生效:source /etc/profile
自动安装脚本:
#!/bin/sh
bao_path="/data"
ins_path="/usr/local"
jdk_tar_bao="jdk-8u151-linux-x64.tar.gz"
jdk_bao="jdk1.8.0_151"
tar_bao="apache-tomcat-7.0.93.tar.gz"
bao="apache-tomcat-7.0.93"
tar -zxvf $bao_path/$jdk_tar_bao -C $ins_path
echo -e "# jdk_liuhang\nexport JAVA_HOME=$ins_path/$jdk_bao\n"'export JRE_HOME=$JAVA_HOME/jre\nexport PATH=$PATH:$JAVA_HOME/bin\nexport CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' >> /etc/profile
source /etc/profile
java -version
tar -zxvf $bao_path/$tar_bao -C $ins_path
cd $ins_path
mv $bao tomcat
cd /etc/init.d/
echo '#!/bin/bash' >> tomcat
echo '# chkconfig:2345 96 14' >> tomcat
echo 'JAVA_OPTS="-Xms256m -Xmx512m"' >> tomcat
echo "JAVA_HOME=$ins_path/$jdk_bao" >> tomcat
echo "CATALINA_HOME=$ins_path/tomcat" >> tomcat
echo '$CATALINA_HOME/bin/catalina.sh $*' >> tomcat
sed -i "23i\export JAVA_HOME=$ins_path/$jdk_bao" $ins_path/tomcat/bin/setclasspath.sh
sed -i "24i\export JRE_HOME=$ins_path/$jdk_bao/jre" $ins_path/tomcat/bin/setclasspath.sh
chmod +x /etc/init.d/tomcat
service tomcat start
netstat -lntp | grep 8080