linux5.4+resin4.0.10+jdk1.6+JDBC篇.docx
Smle 版权所有 联系方式QQ317362607

以下内容都是本人亲身实践得来的经验,如果有误请联系我,加以改正,互相学习~

Smile
2010-9-24
 
承接上一篇:linux5.4+mysql5.1.50+Apache2.2.9篇.docx
Resin -4.0.10 专业版:  http://www.caucho.com/download/resin-pro-4.0.10.tar.gz
Jdk : jdk-6u13-linux-i586.zip 这个文件有点儿特殊性 在windows 解压缩就可以上传的是
jdk-6u13-linux-i586.bin  这个文件上传到 /usr/local/jdk1.6 文件夹下 这里有个小小的失败请大家看第一页标红部分可省去不少冗余的操作
http://esin.onlinedown.net/down/jdk-6u13-linux-i586.zip
JDBC :mysql-connector-java-5.1.7-CodePub.rar 这个文件也很特殊当然也在windows解压后上传 http://code1.codepub.com/wuse12/2009/4/8/mysql-connector-java-5.1.7-CodePub.rar
  JDBC 解压后的文件夹都上传到服务器 /usr/local/ 下
1、 先安装 JDK 安装步骤如下:
1:进入jdk1.6 目录 cd /usr/local/jdk1.6
 
首先看一下jdk-6u13-linux-i586.bin 该文件有没有执行权限,我的就没有只想权限。所以要设置可执行  : chmod 755 jdk-6u13-linux-i586.bin
 
授权以后,那么键入命令 ./jdk-1_5_0-linux-i586.bin 执行安装
2:提示信息会有如下显示
 
退出说明  ctl +c  如果你想看那么就 回车慢慢看吧~~~
 
退出说明以后会有如下提示:问你是否同意上面的协议。当然 :键入  yes 回车
 
等待就好了~~~~
 
当出现下面的一段的时候 回车
 
等 5-10秒左右就会有提示 Done  你已经安装成功了
查看一下安装好的目录就在 这个文件夹下  键入 : ls
 
因为先开始我忘记了jdk 安装的时候是自动安装在同一目录下的,所以简单方法是开始的时候就把  该文件放在local下,执行以上命令,并执行以下操作中把   重命名为 jdk1.6 的命令
所以一下属于冗余部分可以不用操作
 
这些冗余的操作其实就是为了把jdk的安装目录放在local下并改名为 jdk1.6 让配置路径的时候没有那么的麻烦
 
这就是最终要的结果
OK 继续…………
3:配置环境变量
这里就非常的重要啦~~~
配置所有用户的环境变量
vi /etc/profile
 
这个就是我的文件开头的部分
 
这一行明显就是系统环境变量文件的说明
OK 我们开始配置环境变量    注意,这些应该加在export PATH USER...之前
我们在文件的开始处添加  如下:
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$HOMR/bin
 
OK 保存退出;
在执行  source /etc/profile  让文件立即生效
测试:: java –version    或者  javac有如下信息那么说明你已经配置成功了
 
Well Done!!!  Continue~~~~
4:安装 resin
解压  完成后进入resin目录
 
为了以后更好的配置文件方便那么更改下我们的文件名
 
配置resin :非常简单的命令 就是结合 jdk apache 的安装命令:
./configure --with-java-home=/usr/local/jdk1.6 --with-apxs=/usr/local/apache/bin/apxs
 
我的没有报错,如果有错,查下原因,没有错误就继续。
make
make install

5:安装后 我先选择的是修改配置文件
首先看一下  apache httpd.conf的配置
vi /usr/local/apache/conf/httpd.conf
找到如下几行看看是否存在(一般在文件的末尾) 存在就修改成我的像样子就行了
   
OK!
进入 cd /etc/resin/   这个是4.0 安装后独有的放置配置文件的地方 并且和以前不同的是 老版本的httpd.conf  文件 等同于现在的 resin.xml ,但是修改的时候还是有不同的地方
 
看下是否有这两个文件 我的是存在的
编辑 resin.xml    vi resin.xml

这里是我已经配置好的 4.0 resin.xml 我做更改的地方加红 后面跟注释
<!--
   - Resin 4.0 configuration file.
   -
   - See conf/full.xml for more sample configuration, including load
   - balancing and database configuration.
  -->
<resin xmlns=" http://caucho.com/ns/resin"
       xmlns:resin="urn:java:com.caucho.resin">
  <!--
     - Logging configuration for the JDK logging API.
    -->
  <log-handler name="" level="all" path="stdout:"
               timestamp="[%y-%m-%d %H:%M:%S.%s] {%{thread}} "/>
  <!--
     - level='info' for production
     - 'fine' or 'finer' for development and troubleshooting
    -->
  <logger name="com.caucho" level="info"/>
  <logger name="com.caucho.java" level="config"/>
  <logger name="com.caucho.loader" level="config"/>
  <!--
     - driver .jar files can be placed in ${resin.root}/ext-lib
     -->
  <class-loader>
    <tree-loader path="${resin.root}/ext-lib"/>
  </class-loader>
 
  <!--
     - Remote management requires at least one enabled admin user.
    -->
  <resin:AdminAuthenticator>
    <resin:import path="${__DIR__}/admin-users.xml" optional="true"/>
  </resin:AdminAuthenticator>
  <!--
     - For production sites, change dependency-check-interval to something
     - like 600s, so it only checks for updates every 10 minutes.
    -->
  <dependency-check-interval>2s</dependency-check-interval>
  <!-- Java system-properties -->
  <system-property mail.smtp.host="192.168.255.133"/>
  <system-property mail.smtp.port="25"/>
 
  <javac compiler="/usr/local/jdk1.6/bin/javac" args=""/>
  <!—这段是没有的添加上 使用 1.6 compiler –>
 
  <!--
     - default configuration applied to all clusters
    -->
  <cluster-default>
    <!-- standard servlet behavior, including .jsp, .php, and WEB-INF -->
    <resin:import path="${__DIR__}/app-default.xml"/>
    <!-- enables development error pages -->
    <development-mode-error-page/>
    <!--
       - Enables the proxy cache (available in Resin Professional)
      -->
    <resin:if test="${resin.professional}">
      <cache memory-size="64M">
       <!-- Vary header rewriting for IE -->
        <rewrite-vary-as-private/>
      </cache>
    </resin:if>
   
    <!--
       - Admin services
      -->
    <resin:DeployService/>
   
    <resin:if test="${resin.professional}">
      <resin:JmxService/>
      <resin:LogService/>
      <resin:StatService/>
      <resin:XaLogService/>
    </resin:if>
    <!--
       - Default host configuration applied to all virtual hosts.
      -->
    <host-default>
      <access-log path="log/access.log"
                format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
                rollover-period="1W"/>
      <!-- creates the webapps directory for .war expansion -->
      <web-app-deploy path="webapps"/>
      <!--
         - Defaults applied to each web-app.
        -->
      <web-app-default>
        <prologue>
          <allow-servlet-el/>
        </prologue>
        <!-- enable persistent sessions -->
        <session-config>
          <use-persistent-store/>
        </session-config>
    
        <!--
           - Sets max-age for cacheable pages, e.g. static pages.
          -->
        <resin:if test="${resin.professional}">
          <cache-mapping url-pattern="/" max-age="5s"/>
          <cache-mapping url-pattern="*.gif" max-age="60s"/>
          <cache-mapping url-pattern="*.jpg" max-age="60s"/>
          <cache-mapping url-pattern="*.png" max-age="60s"/>
          <cache-mapping url-pattern="*.css" max-age="60s"/>
          <cache-mapping url-pattern="*.js" max-age="60s"/>
         </resin:if>
      </web-app-default>
    </host-default>
  </cluster-default>
  <!--
     - Configures the main appliction cluster.  Load-balancing configurations
     - will also have a load-balance-tier cluster.
    -->
 <!--
       - The local cluster, used for load balancing and distributed
       - backup.
      -->
  <cluster id="app-tier">
    <!-- sets the content root for the cluster, relative to resin.root -->
    <root-directory>.</root-directory>
    <!-- defaults for each server, i.e. JVM -->
    <server-default>
      <!-- The http port -->
      <http address="192.168.255.133" port="8080"/>
     <!—这里修改下ip -->

      <!-- SSL port configuration: -->
      <!--
      <http address="*" port="8443">
        <jsse-ssl self-signed-certificate-name=" resin@localhost"/>
      </http>
      -->
      <!--
         - <jvm-arg>-Xmx512m</jvm-arg>
         - <jvm-arg>-agentlib:resin</jvm-arg>
        -->
      <!--
         - If starting Resin as root on Unix, specify the user name
         - and group name for the web server user.web-data
        -->
<!—这个地方有点儿特殊,在3.0版本里面都没有添加这个用户设置的存在要改成root 和 root 组 才可以正常启动-->
      <resin:if test="${resin.userName == 'root'}">
        <user-name>root</user-name>
        <group-name>root</group-name>
      </resin:if>
    </server-default>
    <!-- define the servers in the cluster 6800 -->
    <server id="" address="localhost" port="6800">
    </server>
    <!-- the default host, matching any host name -->
    <host id="" root-directory=".">
      <!--
         - configures an explicit root web-app matching the
         - webapp's ROOT
        -->
      <web-app id="/" root-directory="/var/www"/>
      <!—这里修改成你要放置java网站的地方-->
      <!--
         - Administration application /resin-admin
        -->
      <web-app id="/resin-admin" root-directory="${resin.root}/doc/admin">
        <prologue>
          <resin:set var="resin_admin_external" value="false"/>
          <resin:set var="resin_admin_insecure" value="true"/>
        </prologue>
      </web-app>
      <!--
  - Resin documentation - remove for a live site
 -->
      <web-app id="/resin-doc" root-directory="${resin.root}/doc/resin-doc"/>
      <!--
  - <resin:LoadBalance regexp="^/load" cluster="backend-tier"/>
  - <resin:HttpProxy regexp="^/http" address="localhost:9000"/>
  - <resin:FastCgiProxy regexp="^/fcgi" address="localhost:9001"/>
 -->
    </host>
  </cluster>
</resin>
以上是我配置的 resin.xml 配置文件
OK!重启 apache  重启 resin
/usr/local/apache/bin/apachectl restart
/etc/init.d/resin restart
新建测试文档
vi /var/www/index.jsp
1+1=<%=1+1%>
保存退出
测试:如果能看到以下结果那么就成功了
 
下面链接数据库 JDBC 配置开始!
6:mysql   JDBC
vi /etc/profile
之前配置JDK环境变量的时候并没有设置mysql  JDBC 的配置下面就添加上去
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/dt.jar:$JDBC/mysql-connector-java-5.1.7-bin.jar:$CLASSPATH
 
OK!现在已近添加了 JDBC 的配置

保存退出
执行:source /etc/profile 及时生效
7:测试 mysql JDBC 的链接
   重启 apache  重启 resin 确保 mysql 服务启动OK
   vi /var/www/testmysql.jsp
  
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
   <%
    Connection odbcconn=null;         //数据库的连接对象
   %>
   <%
    try {
       Class.forName("com.mysql.jdbc.Driver").newInstance();
       out.println("驱动程序加载成功.<br>");
    }
    catch(Exception e) {
       out.println("加载驱动程序出错:"+e);
    }
    try {
       odbcconn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=root&password=123456");
       out.println("已经建立到MySQL数据库的连接.<br>");
       odbcconn.close();
    }
    catch(Exception e) {
       out.println("连接数据库出错:"+e);
    }
   %>
</body>
</html>
如果出现如下 证明一切OK!
 
Java 篇到这里也结束了   下一篇 PHP 篇!

小知识点::
Chmod  命令 详解
指令名称 : chmod
使用权限 : 所有使用者
使用方式 : chmod [-cfvR] [--help] [--version] mode file...
说明 : Linux/Unix 的档案存取权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所存取。
 
mode : 权限设定字串,格式如下 : [ugoa...][[+-=][rwxX]...][,...],其中u 表示该档案的拥有者,g表示与该档案的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。
 
+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限。
 
r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。
 
-c : 若该档案权限确实已经更改,才显示其更改动作
 
-f : 若该档案权限无法被更改也不要显示错误讯息
 
-v : 显示权限变更的详细资料
 
-R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更)
 
--help : 显示辅助说明
 
--version : 显示版本
 
范例 :将档案 file1.txt 设为所有人皆可读取 :
 
chmod ugo+r file1.txt
 
将档案 file1.txt 设为所有人皆可读取 :
 
chmod a+r file1.txt
 
将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 :
 
chmod ug+w,o-w file1.txt file2.txt
 
将 ex1.py 设定为只有该档案拥有者可以执行 :
chmod u+x ex1.py
 
将目前目录下的所有档案与子目录皆设为任何人可读取 :
 
chmod -R a+r *
 
此外chmod也可以用数字来表示权限如 chmod 777 file
 
语法为:chmod abc file
 
其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。
 
r=4,w=2,x=1
 
若要rwx属性则4+2+1=7;
 
若要rw-属性则4+2=6;
 
若要r-x属性则4+1=7。
 
范例:
 
chmod a=rwx file 和 chmod 777 file 效果相同
 
chmod ug=rwx,o=x file 和 chmod 771 file 效果相同
 
若用chmod 4755 filename可使此程式具有root的权限
 
指令名称 : chown
 
使用权限 : root
 
使用方式 : chmod [-cfhvR] [--help] [--version] user[:group] file...
 
说明 : Linux/Unix 是多用户操作系统,所有的档案皆有拥有者。利用 chown 可以将档案的拥有者加以改变。一般来说,这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样的权限。
 
user : 新的档案拥有者的使用者 IDgroup : 新的档案拥有者的使用者群体(group)-c : 若该档案拥有者确实已经更改,才显示其更改动作-f : 若该档案拥有者无法被更改也不要显示错误讯息-h :
 
只对于连结(link)进行变更,而非该 link 真正指向的档案-v : 显示拥有者变更的详细资料-R : 对目前目录下的所有档案与子目录进行相同的拥有者变更(即以递回的方式逐个变更)--help : 显示辅助
 
说明--version : 显示版本
 
范例 :
 
将档案 file1.txt 的拥有者设为 users 群体的使用者 jessie :
 
chown jessie:users file1.txt
 
将目前目录下的所有档案与子目录的拥有者皆设为 users 群体的使用者 lamport :
 
chmod -R lamport:users *
 
-rw------- (600) -- 只有属主有读写权限。
 
-rw-r--r-- (644) -- 只有属主有读写权限;而属组用户和其他用户只有读权限。
 
-rwx------ (700) -- 只有属主有读、写、执行权限。
 
-rwxr-xr-x (755) -- 属主有读、写、执行权限;而属组用户和其他用户只有读、执行权限。
 
-rwx--x--x (711) -- 属主有读、写、执行权限;而属组用户和其他用户只有执行权限。
 
-rw-rw-rw- (666) -- 所有用户都有文件读、写权限。这种做法不可取。
 
-rwxrwxrwx (777) -- 所有用户都有读、写、执行权限。更不可取的做法。
 
以下是对目录的两个普通设定:
 
drwx------ (700) - 只有属主可在目录中读、写。
 
drwxr-xr-x (755) - 所有用户可读该目录,但只有属主才能改变目录中的内容
 
suid的代表数字是4,比如4755的结果是-rwsr-xr-x
 
sgid的代表数字是2,比如6755的结果是-rwsr-sr-x
 
sticky位代表数字是1,比如7755的结果是-rwsr-sr-t