apache+tomcat
-----------------------------------------------------------------------------------
1.首先配置jdk环境
[root@localhost ~]# cp /var/ftp/pub/jdk-6u20-linux-i586.bin /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ./jdk-6u20-linux-i586.bin
按照提示输入“yes”回车确认,等待1~2分钟左右即可完成安装。
-------------------------------------------------------------------------------------
2.为jdk的安装目录及执行程序创建链接文件,以方便使用
[root@localhost ~]# alternatives --install /usr/bin/java java /usr/local/jdk1.6.0_20/bin/java 1
[root@localhost ~]# alternatives --install /usr/bin/javac javac /usr/local/jdk1.6.0_20/bin/javac 1
[root@localhost ~]# alternatives --config java
[root@localhost ~]# alternatives --config java
共有 3 个程序提供“java”。
选择 命令
-------------------------------------------------------------------------------------
1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
3 /usr/local/jdk1.6.0_20/bin/java
按 Enter 来保存当前选择[+],或键入选择号码:3
[root@localhost ~]# alternatives --config javac
共有 3 个程序提供“javac”。
选择 命令
-------------------------------------------------------------------------------------
1 /usr/lib/jvm/java-1.4.2-gcj/bin/javac
*+ 2 /usr/lib/jvm/java-1.6.0-openjdk/bin/javac
3 /usr/local/jdk1.6.0_20/bin/javac
按 Enter 来保存当前选择[+],或键入选择号码:
-------------------------------------------------------------------------------------
3.修改/etc/profile文件,添加Java开发环境需要的变量设置。
[root@localhost ~]# vi /etc/profile
…… //省略部分内容
JAVA_HOME=/usr/local/jdk1.6.0_20
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
[root@localhost ~]# source /etc/profile
-------------------------------------------------------------------------------------
4.测试
[root@localhost ~]# java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
-----------------------------------------------------------------------------------
5.编写java程序
[root@localhost ~]# vi HelloWorld.java
public class HelloWorld {
public static void main(String args[]) {
System.out.println("HelloWorld!!");
}
}
[root@localhost ~]# javac HelloWorld.java //编译程序
[root@localhost ~]# java HelloWorld //运行HelloWorld.class程序
HelloWorld!!
-------------------------------------------------------------------------------------
6.tomcat安装
[root@localhost ~]# tar zxf apache-tomcat-7.0.23.tar.gz
[root@localhost ~]# mv apache-tomcat-7.0.23 /usr/local/tomcat
[root@localhost ~]# ln-s /usr/local/tomcat/bin/startup.sh /usr/local/sbin/tomcat-up
[root@localhost ~]# ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/sbin/tomcat-down
-----------------------------------------------------------------------------------
7.设置Tomcat服务需要使用的变量CACTLINA_HOME。
[root@localhost ~]# vi /etc/profile //修订原有的JDK环境
…… //省略部分内容
JAVA_HOME=/usr/local/jdk1.6.0_20
CATALINA_HOME=/usr/local/tomcat
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CATALINA_HOME CLASSPATH PATH
[root@localhost ~]# source /etc/profile
8.添加管理员benet
[root@localhost ~]# vi /usr/local/tomcat/conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<user username="benet" password="pwd123" roles="manager-gui"/>
</tomcat-users>
[root@localhost ~]# netstat -anpt | grep java
tcp 0 0 :::8009 :::* LISTEN 2591/java
tcp 0 0 :::8080 :::* LISTEN 2591/java
----------------------------------------------------------------------------------
访问http://your_server_ip:8080/ ,可以看到tomcat的Web首页