安装JDK1.7 获得JDK包 如何在shell下wget下载jdk请参见wget下载JDK 创建一个目录 shell~#mkdir /usr/java把下载的jdk-7u7-linux-x64.gz文件放进这个目录 解压 shell~#tar -zxvf jdk-7u7-linux-x64.gz解压后会在Java文件夹下产生一个jdk1.7.0_07目录 定义JAVA_HOME的环境变量目录 shell~#JAVA_HOME=/usr/java/jdk1.7.0_07 shell~#export JAVA_HOME shell~# PATH=$JAVA_HOME/bin:$PATH shell~#export PATH这样退出终端或者重启就没有了可以通过修改用户目录的.bashrc或者/etc/profile叫所有用户生效 修改以上文件添加以下几行 shell~#vi /etc/profile #set java environment JAVA_HOME=/usr/java/jdk1.7.0_07 CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOEM/lib/dt.jar PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME CLASSPATH PATH保存并执行 shell~#source /etc/profile检测一下是否生效 shell~#echo $JAVA_HOME #查看JAVA_HOME目录 /usr/java/jdk1.7.0_07 shell~#java -version #查看java版本 java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)JDK配置完成 配置Tomcat Tomcat获取地址:http://tomcat.apache.org/download-70.cgi 按照自己要求下载tomcat本文为apache-tomcat-7.0.30.tar.gz 本文部署到/usr/local 解压缩到/usr/local目录 我是直接下载到这个目录的所以直接解压了 shell~#tar -zxvf apache-tomcat-7.0.30.tar.gz 解压后会得到apache-tomcat-7.0.30目录 这里文件夹名字太长了我改了一下 shell~#mv /usr/local/apache-tomcat-7.0.30 /usr/local/apache-tomcat把tomcat加入服务当中,到tomcat的bin目录中把catalina.sh复制到/etc/init.d里并命名为tomcat shell~#cp /usr/local/apache-tomcat/bin/catalina.sh /etc/init.d/tomcat编辑此文件 shell~#vi tomcat在#!/bin/sh下加入 ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $remote_fs $network # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: The tomcat Java Application Server ### END INIT INFO在分割线下加入环境变量 JAVA_HOME=/usr/java/jdk1.7.0_07 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH CATALINA_HOME=/usr/local/apache-tomcat给这个脚本与权限 shell~#chmod 755 tomcat添加tomcat服务这里用chkconfig shell~#chkconfig --add tomcat如果这里出现提示 insserv: warning: script 'tomcat' missing LSB tags and overrides insserv: There is a loop between service nginx and tomcat if stopped insserv: loop involving service tomcat at depth 2 insserv: loop involving service nginx at depth 1 insserv: Stopping tomcat depends on nginx and therefore on system facility `$all' which can not be true! insserv: exiting now without changing boot order!则需要安装chkconfig安装方法 shell~#apt-get install chkconfig就可以如出现以下表示成功 tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off也可以在输入以下命令查看一下 shell~#chkconfig --list tomcat tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off如果345 为关闭状态。执行如下命令设置tomcat为开机自启动。 shell~# chkconfig tomcat on 启动一下看看 shell~# service tomcat start Using CATALINA_BASE: /usr/local/apache-tomcat Using CATALINA_HOME: /usr/local/apache-tomcat Using CATALINA_TMPDIR: /usr/local/apache-tomcat/temp Using JRE_HOME: /usr/java/jdk1.7.0_07 Using CLASSPATH: /usr/local/apache-tomcat/bin/bootstrap.jar:/usr/local/apache-tomcat/bin/tomcat-juli.jar启动,停止,重启 shell~# service tomcat start shell~# service tomcat stop shell~# service tomcat restart (责任编辑:IT) |