rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 应用技术 » Web服务器

apache tomcat 整合

第一大步:先安装 openssl
因为要apache与SSL整合,而apache安装之前要用OpenSSL的路径作参数:所以要先装openssl(下载不说,我的版本:openssl0.9.8)
1: tar zvxf openssl-0.9.8.tar.gz
2: cd openssl-0.9.8
3: ./Configure   (这一步是我最恨的地方了,32位的机器用这个命令没有问题,如果你的机器是64位,请用: ./config --prefix=安装目录)
4: make    (这一步很慢啊,如果你的一下就完成,80%你的没装好。)
5: make install (这是安装的最后一步,默认的安装目录: /usr/local/ssl,
          如果有,就说明安装成功,如果你不想让他安装在这个目录,你必须在第三步 ./Configure 后面加参数指点安装目录,参数名称就你用 ./Configure --help 看看吧。)

第二大步:安装apache
1: tar -zvxf httpd-2.2.9.tar.gz (这一步执行完成以后是解压了apache压缩包,现在的问题是:在安装apache之前要先安装apr 和apr-util.这二个东西在apache 的安装包里面了。APR(Apache portable Run-time libraries,Apache可移植运行库))
分支一:APR的安装:
   1: cd httpd-2.2.9
   2: cd srclib
   3: cd apr
   4: ./configure --prefix=/usr/httpd/apr (安装APR的目录)
   5: make
   6: make install (执行完这一步以后就在/usr/httpd下面有一个apr的目录,表示安装成功!) 分支二:APR-UTIL的安装
   1:cd httpd-2.2.9
   2: cd srclib
   3: cd apr-util
   4: ./configure --prefix=/usr/httpd/apr-util --with-apr=/usr/httpd/apr (--with-apr 后面的参数就是你前面安装apr的路径)
   5: make (如果你的--with-apr参数写错,在执行这一步的时候出错:下面是错误信息
         linux-web:/tool/httpd-2.2.9/srclib/apr-util # make
         make: *** No targets specified and no makefile found. Stop.    6: make install (这一步执行完成以后,在/usr/httpd/目录下面就有一个apr-util的文件夹。下面是正式开始安装apache了) 2: cd httpd-2.2.9
3: (这一步是正式安装apache目录了 configurer后面跟的安装参数,也是我花费时间比较长的一步:简单说明
   --prefix            :安装路径
   --enable-so          :指明编译动态加载模块(DSO)支持到httpd二进制文件(如果你不明白什么意思,我可以集大体的说一下,就是apache有许多的模块,例如:SSL,mdjk,他有二种加载,动态和静态,这一句应该 就是让动态加载,我个人是这么认为的。)
   --enable-module        :加载所有模块
   --with-apr          :你安装apr的目录
   --with-apr-util        :你安装apr-util的目录
   --enable-ssl         :static (加载ssl模块 需要其他模块就查看帮助: ./configure --help)
   --with-ssl          :openssl的安装目录
   --sysconfdir         :httpd.conf的放置目录(这个参很很重,只要记得他 --prefix的值一样就可以了) ./configure --prefix=/usr/httpd/apache2
     --sysconfdir=/usr/httpd/apache2/conf
     --with-ssl=/usr/local/ssl
     --enable-so
     --enable-modules=all
     --with-apr=/usr/httpd/apr
     --with-apr-util=/usr/httpd/apr-util

/*
./configure --prefix=/usr/httpd/apache2
     --sysconfdir=/usr/httpd/apache2/conf
     --with-ssl=/usr/local/ssl
     --enable-so
     --enable-ssl
     --with-apr=/usr/httpd/apr
     --with-apr-util=/usr/httpd/apr-util         ./configure --prefix=/usr/httpd/apache2 --enable-modules="rewrite expires cache file-cache disk-cache mem-cache proxy proxy-connect.proxy-ftp proxy-http proxy-ajp proxy-balancer" --enable-ssl --with-apr=/usr/httpd/apr --with-ssl=/usr/local/ssl --with-mpm=worker --with-apr-util=/usr/httpd/apr-util --sysconfdir=/usr/httpd/apache2/conf --enable-so

        

4:make
5:make install (这步执行完成以后就可以到 /usr/httpd/apache2/bin 的目录下面)
6:./apachectl start   (如果回车以后马什么也没有提示,表示你的apache HTTP Server已经启动:在IE中输入: 地址 ,页面如果出现:It works! 表示apache启动成功!)

第三步:apache 与 SSL的整合 :我们下面就要配置 apache的 httpd.conf文件了.
1: cd .../apache2/conf/
2: vi httpd.conf  
     A:(修改:DocumentRoot 为你的项目所在路径 我的为 DocumentRoot "/www/ROOT")
     B:(修改: <Directory "/usr/httpd/apache2/htdocs"> 改为<Directory "/www/ROOT">)
     C:(找到 Include conf/extra/httpd-ssl.conf 去掉前面的 #号 到了这一步,保存修改,我们就要用到我们第一大步开始装的openssl了。下面是对 openssl生成证书的操作:具体步骤我不说了,网上一大堆:)
        C1:cd /usr/local/ssl/bin 在这个目录下面生成二个文件:一个密钥(server.key),一个认证文件 (server.crt)
        C2: 将这二个文件放到 ..../apache2/conf下面
        C3: 找到:#Include conf/extra/httpd-ssl.conf ,去掉前面的#号
        C3: ./openssl genrsa -des3 -out server.key 2048
        C5: ./openssl req -new -key server.key -out server.crs -config /etc/ssl/openssl.cnf
        C4: openssl ca -in server.crs -out server.crt -cert server.crt -keyfile server.key -config /etc/ssl/config.cnf
        C5:
     D:修改 (apache目录/conf/extra/httpd-ssl.conf)如下:
        SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt
        指定服务器证书key位置
        SSLCertificateKeyFile /usr/local/apache/conf/ssl.crt/server.key      
第三步: 安装tomcat,我用的apache-tomcat-6.0.16.tar.gz.
1: tar -zvxf apache-tomcat-t.0.16.tar.gz
2: mv apache-tomcat-6.0.16 /usr/httpd/tomcat1
3: tar -zvxf apache-tomcat-t.0.16.tar.gz
4: mv apache-tomcat-6.0.16 /usr/httpd/tomcat2

第四步: tomcat 和apache集群:(个人理解:apache接受客户端请求,对后台操作的请求分发给各个集群的tomcat)
1: cd /usr/httpd/tomcat1/conf
2: vi server.xml
    (找到:<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">,去掉上下的注释,改jvm1为tomcat1,找到:<Service name="Catalina">,修改
     Catalina为tomcat1,找到:<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 修改8009为8010,8443为8410 找到:Connector port="8080",修改:8080为8800,注释掉这一行:<Engine name="Catalina" defaultHost="localhost">);
3: cd /usr/httpd/tomcat2/conf   
     (找到:<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">,去掉上下的注释,改jvm1为tomcat2,找到:<Service name="Catalina">,修改
     Catalina为tomcat1,找到:<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 修改8009为8011,8443为8411 找到:Connector port="8080",修改:8080为8801,,注释掉这一行:<Engine name="Catalina" defaultHost="localhost">
     找到:<Server port="8005" shutdown="SHUTDOWN">,修改8005为8006);
4: cd /usr/httpd/apache2/conf
5: vi workers.properties (创建新文件,内容如下)
    worker.list=loadbalancer     worker.tomcat1.port=8010   #这里是tomcat1的ajp端口
    worker.tomcat1.host=localhost
    worker.tomcat1.type=ajp13
    worker.tomcat1.lbfactor=1       worker.tomcat2.port=8011   #这里是tomcat2的ajp端口
    worker.tomcat2.host=localhost
    worker.tomcat2.type=ajp13
    worker.tomcat2.lbfactor=1     worker.loadbalancer.type=lb
    worker.loadbalancer.balance_workers=tomcat1,tomcat2
    worker.loadbalancer.sticky_session=1   (我测试,这里的值为1是session共享,0为非session共享)


6: cd /usr/httpd/apache2/conf/extra/
7: vi /usr/httpd/apache2/conf/extra/mod-jk.conf
    mod-jk.conf 信息如下:
    <IfModule mod_jk.c>
     JkWorkersFile /usr/httpd/apache2/conf/workers.properties #(集群配置信息)
     JkLogFile /usr/httpd/apache2/logs/mod_jk.log    #(日志信息)
     JkLogLevel warning                      #(日志等级)
    </IfModule>     <IfModule mod_jk.c>                      
    JkMount /*.jsp loadbalancer                  #apache接收到请求转发给tomcat的类型(我定义的是jsp和action)
    JkMount /*.action loadbalancer                
    #JkMount /* loadbalancer
    </IfModule>     DirectoryIndex index.jsp    8: 安装mod_jk模块
     A:下载tomcat-connectors-1.2.26-src.tar.gz,执行:
       A1: tar zvxf tomcat-connectors-1.2.26-src.tar.gz
       A2: cd tomcat-connectors-1.2.26-src/native
       A3: ./configure --with-apxs=/usr/httpd/apache2/bin/apxs
       A4: make
       A5: cp ./apache-2.0/mod_jk.so /usr/httpd/apache2/modules/ 到这一步就可以用apache和tomcat集群了,用是https访问的时候jsp和action的请求还不能转给tomcat. 9: vi /usr/httpd/apache2/conf/extra/httpd-ssl.conf   加 TransferLog "/usr/httpd/apache2/logs/access_log" 下面二行代码:      JkMount /*.jsp loadbalancer
     JkMount /*.action loadbalancer

                 1:启动apache 碰到下面问题:Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration,到apache2的bin 目录下面执行 ./httpd -l 看看有没有mode_ssl.c,这个错误说明ssl模块安装没有成功!    --enable-proxy         :安装apache proxy 模块
   --enable-proxy-ajp       :安装apache proxy ajp模块
   --enable-proxy-balancer    :安装apache proxy balancer 模块
   --enable-MODULE=shared     :MMODULE编译为DSO(可用于所有模块)
   --enable-MODULE=static    将MODULE静态连接进核心(仅用于扩展和实验模块)

顶一下
(0)
踩一下
(0)