最开始安装jre显示没有源。
Package sun-java6-jre is not available, but is referred to by another package.
于是添加了一个源。
root@xlu-desktop:/home/xlu # add-apt-repository "deb http://archive.canonical.com/ lucid partner"
root@xlu-desktop:/home/xlu # apt-get update
安装jre
root@xlu-desktop:/home/xlu # apt-get install sun-java6-jre sun-java6-plugin
安装jdk
root@xlu-desktop:/home/xlu # apt-get install sun-java6-jdk sun-java6-plugin
设为默认Java
sudo update-alternatives --config java
执行后会出现类似如下的画面:
代码: There are 2 alternatives which provide `java'.
Selection Alternative ----------------------------------------------- 1 /usr/bin/gij-wrapper-4.1 *+ 2 /usr/lib/jvm/java-6-sun/jre/bin/java
Press enter to keep the default[*], or type selection number:
输入 有包含 "sun" 的行的前面的数字。如上面显示,则输入2,然后回车确定。 注:如果你是新安装的8.04版本的ubuntu,那么会出现类似"系统只有一个java,不需要设置"的英文提示消息。如下所示: 代码: There is only 1 program which provides java (/usr/lib/jvm/java-6-sun/jre/bin/java). Nothing to configure.
配置JAVA环境变量:
代码: sudo gedit /etc/environment
在其中添加如下两行:
代码: CLASSPATH=.:/usr/lib/jvm/java-6-sun/lib#中间是以英文的冒号隔开,记得windows中是以英文的分号做为分隔的 JAVA_HOME=/usr/lib/jvm/java-6-sun
然后:
代码: sudo gedit /etc/jvm
将文件中的
代码: /usr/lib/jvm/java-6-sun(其实也就是JAVA_HOME)
这一行填入到配置块的顶部 关于具体的路径,安装java的时候都会给予提示和说明,请根据实际情况添加,且不可盲目照抄上面的
安装tomcat6x
到Tomcat主页http://tomcat.apache.org/ 选择你要使用的版本,选择Binary Distributions,下载以.tar.gz结尾的文件,解压后就可以直接使用了。
确保已经按照前面安装JAVA环境的步骤配置了JAVA环境变量在终端中进入解压后的bin目录下,./startup.sh启动tomcat,./shutdown.sh关闭tomcat。 当看到类似以下输出时,你已经成功启动tomcat了:
代码:
root@xlu-desktop:/usr/local/tomcat/bin # ./startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/lib/jvm/java-6-sun Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar omcat启动成功后,就可以访问http://localhost:8080 来检测tomcat是否成功启动了。 注:tomcat默认端口是8080,端口号可以在config目录的server.xml中进行更改,但要注意,在Linux中1000以内的端口号必须需要root权限,使用时要加sudo命令,1000以外的OK,所以想要在类似eclipse的IDE中用tomcat的话还是设置在1000以外为宜。
5 Apache 2与tomcat6的整合
下载和编译mod_jk.so 这个连接tomcat和apache.的连接文件。 照样也是在http://tomcat.apache.org 这个网站上下载的源代码安装包:tomcat-connectors-1.2.31-src.tar.gz
首先:
#mkdir /usr/source.bao #cp /media/tomcat-connectors-1.2.31-src.tar.gz /usr/source.bao #cd /usr/local/src #tar xvfz /usr/source.bao/tomcat-connectors-1.2.31-src.tar.gz #cd tomcat-connectors-1.2.31-src/ 注意里面有一个BUILD.txt 仔细阅读它 然后 cd native/ #vim BUILDING.txt 仔细阅读它 然后输入采用:
root@xlu-desktop:/usr/local/src/tomcat-connectors-1.2.31-src/native# ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-java-home=/usr/lib/jvm/java-6-sun #make #make isntall #cp apache-2.0/mod_jk.so /usr/local/apache2/modules/ 这一步很重要 第三步:在/usr/local/apache2/conf/下面建立两个配置文件mod_jk.conf和workers.properties。 gedit mod_jk.conf 添加以下代码: # 指出mod_jk模块工作所需要的工作文件workers.properties的位置 JkWorkersFile /usr/local/apache2/conf/workers.properties # Where to put jk logs JkLogFile /usr/local/apache2/logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" # 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理 JkMount /servlet/* ajp13_worker JkMount /*.jsp ajp13_worker gedit workers.properties 添加以下代码: # workers.properties - # # This file is a simplified version of the workers.properties supplied # with the upstream sources. The jni inprocess worker (not build in the # debian package) section and the ajp12 (deprecated) section are removed. # # As a general note, the characters $( and ) are used internally to define # macros. Do not use them in your own configuration!!! # # Whenever you see a set of lines such as: # x=value # y=$(x)/something # # the final value for y will be value/something # # Normaly all you will need to do is un-comment and modify the first three # properties, i.e. workers.tomcat_home, workers.java_home and ps. # Most of the configuration is derived from these. # # When you are done updating workers.tomcat_home, workers.java_home and ps # you should have 3 workers configured: # # - An ajp13 worker that connects to localhost:8009 # - A load balancer worker # # # OPTIONS ( very important for jni mode ) # # workers.tomcat_home should point to the location where you # installed tomcat. This is where you have your conf, webapps and lib # directories. # workers.tomcat_home=/usr/local/tomcat # # workers.java_home should point to your Java installation. Normally # you should have a bin and lib directories beneath it. # workers.java_home=/usr/lib/jvm/java-6-sun # # You should configure your environment slash... ps=/ on NT and / on UNIX # and maybe something different elsewhere. # ps=/ # #------ ADVANCED MODE ------------------------------------------------ #--------------------------------------------------------------------- # # #------ worker list ------------------------------------------ #--------------------------------------------------------------------- # # # The workers that your plugins should create and work with # worker.list=ajp13_worker # #------ ajp13_worker WORKER DEFINITION ------------------------------ #--------------------------------------------------------------------- # # # Defining a worker named ajp13_worker and of type ajp13 # Note that the name and the type do not have to match. # worker.ajp13_worker.port=8009 worker.ajp13_worker.host=localhost worker.ajp13_worker.type=ajp13 # # Specifies the load balance factor when used with # a load balancing worker. # Note: # ----> lbfactor must be > 0 # ----> Low lbfactor means less work done by the worker. worker.ajp13_worker.lbfactor=1 # # Specify the size of the open connection cache. #worker.ajp13_worker.cachesize # #------ DEFAULT LOAD BALANCER WORKER DEFINITION ---------------------- #--------------------------------------------------------------------- # # # The loadbalancer (type lb) workers perform wighted round-robin # load balancing with sticky sessions. # Note: # ----> If a worker dies, the load balancer will check its state # once in a while. Until then all work is redirected to peer # workers. worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=ajp13_worker 再配置httpd.conf,作以下修改: 将Listen 80 修改为 Listen 127.0.0.1:80 将 ServerName 修改为 ServerName LocalHost:80 我的网页放在/var/wwwroot下,所以要修改 DocumentRoot 添加代码: DocumentRoot "/var/wwwroot" <Directory "/var/wwwroot"> Options Includes FollowSymLinks AllowOverride None Order deny,allow Allow from all XBitHack on </Directory> <Directory "/var/wwwroot/WEB-INF"> Order deny,allow Deny from all </Directory> 增加关于加载mod_jk的语句: 添加代码: LoadModule jk_module modules/mod_jk.so Include /usr/local/apache2/conf/mod_jk.conf 最后编辑Tomcat的配置文件 server.xml,在HOST段中加入: <Context path="" docBase="/var/wwwroot" debug="0" reloadable="true" crossContext="true"/> 在/var /wwwroot下建立一个test.jsp,启动Apache和Tomcat,用浏览器访问http://localhost/,应该可以看到正确的页 面了。 test.jsp 的例子 Hello! The time is <%= new java.util.Date() %> 输入http://127.0.0.1/test.jsp 你会看到:Hello! The time is Sun May 22 14:30:23 CST 2011 OK!成功了。 最后apache和tomcat的整合网上主要有两个版本。一种是新建流。一种是没用流。 最终参考了很多网站才做出来。中间很多遗忘和重复。 有问题可以参考: http://kb.cnblogs.com/a/1628375/ http://www.91ds.com/index.php?load=read&id=72