设为首页 收藏本站
查看: 420|回复: 0

[经验分享] 使用jakarta-tomcat-connectors整合apache2和tomcat

[复制链接]

尚未签到

发表于 2017-1-20 06:48:09 | 显示全部楼层 |阅读模式
1 Installing Apache2

下载apache
wget -c http://apache.mirror.phpchina.com/httpd/httpd-2.2.4.tar.bz2
解压缩后进入目录进行配置

./configure --enable-module=so --enable-module=usertrack --enable-modules=fastcgi --enable-info --enable-suexec --with-mpm=worker --enable-expires --enable-headers --enable-deflate --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache

make && make install

Edit /usr/local/apache2/conf/httpd.conf and change(修改apache2配置文件):

加入
DirectoryIndex index.htm index.html index.php index.xhtml index.shtml

/usr/local/apache2/bin/apachects start
启动apache2

2 Installing JDK (Java Development Kit) or JRE(Java Runtime Environment)

http://java.sun.com
下载 jdk 或 jre

chmod +x jre-6u4-linux-i586.bin
Now execute the file:
./jre-6u4-linux-i586.bin
mv jre1.6.0_04 /usr/local/

Now we need to set the JAVA_HOME environment variable. Add the following at the end of /etc/profile just after export PATH.

vi /root/.bashrc
加入
JAVA_HOME=/usr/local/jre1.6.0_04
PATH=$JAVA_HOME:$JAVA_HOME/bin:$PATH
#CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH

重新登陆系统后
echo $JAVA_HOME
就会打印JAVA_HOME

3 Installing Tomcat
http://tomcat.apache.org
下载tomcat

执行
tar xvzf apache-tomcat-6.0.14.tar.gz

进入
TOMCAT_HOME/bin/

执行./startup.sh

启动 进入 http://localhost:8080/ 就表示成功

4 Installing and configuring mod_jk
(1) cd /usr/src

(2) 首先下载(wget http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz)
http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz

(3) tar xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz

(4) cd jakarta-tomcat-connectors-1.2.15-src/jk/native

(5) Now you are ready to create the custom configure file for your system. Execute the following:

    ./buildconf.sh
  
    如果提示失败,最好下载
    autoconf,automake,libtool
   
  
    This will create a configure file in the
    /usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native directory.

(6) Execute the following command in order to configure mod_jk for your system.
    Important note: You will need to have apxs2 (APache eXtension tool) installed and configured with Apache.
    If you do not have it, as was my case, you can download and install the apache2-threaded-dev package
    (which replaced the former apache-dev package) from www.debian.org.
    At the time of this writing, the Debian package archive at www.debian.org was down and
    they referred me to their temporary site until they resolved their issues pdo.debian.net.
    I found the apache2-threaded-dev package and was able to install it successfully.
    Be sure to include the correct location apxs2 on your system in the path of the command.


    ./configure --with-apxs=/usr/local/apache2/bin/apxs

(7) 执行make
  
    在执行make 时可能会出现
  
    libtool: compile: unable to infer tagged configuration
    libtool: compile: specify a tag with `--tag'
    make[1]: *** [jk_ajp12_worker.lo] Error 1
    make[1]: Leaving directory `/usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/common'
    make: *** [all-recursive] Error 1
  
    修改Makefile 和common/Makefile两个文件
  
    找到
    LIBTOOL = /usr/share/apr-1.0/build/libtool --silent
  
    改为
  
    LIBTOOL = /usr/share/apr-1.0/build/libtool --silent --tag CC


  
(8) make install 执行后应该在/usr/local/apache2/modules/可以看到mod_jk.so


5 Configuring Tomcat and Apache
Create the workers.properties file
  Important note: Be sure to make a backup copy of your config files before modifying.
  The workers.properties file contains the details about how each process is linked to Tomcat by defining workers that communicate through the ajpv13 protocol. Refer to the Workers HowTo for more detail.
1.First create the workers.properties file in your Apache2 root directory.
  touch /usr/local/apache2/conf/workers.properties


2.Next, open the workers.properties file and add the following.
You can find many other examples of the workers.properties file on the internet,
but this is the one that I created and it seems to work fine with the other portions
that have already been configured in this tutorial.

在workers.properties加入以下内容:
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/jre1.6.0_01
ps=/
worker.list=worker1

worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

3 保存并关闭文件

4. Now we need to open the /usr/local/apache2/conf/httpd.conf file and add the following lines at the bottom.
  (httpd.conf is just for backward compatibility)

  在最后加入 以下内容

LoadModule jk_module /usr/local/apache2/modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile /usr/local/apache2/conf/workers.properties

# Where to put jk logs
JkLogFile   /var/log/apache2/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"


JkMount /*.jsp worker1
JkMount /*.do worker1

保存修改

(5) 修改
    /usr/local/apache2/conf/extra/httpd-vhost.conf
       修改,指定到应用程序中
    DocumentRoot /var/www/test/
       <Directory /var/www/test/>
           Options FollowSymLinks MultiViews
           AllowOverride None
           Order allow,deny
           allow from all
    </Directory>

  并把 Options Indexes FollowSymLinks MultiViews
  改成 Options FollowSymLinks MultiViews

  保存修改

(6) 重启 tomcat

  然后 /usr/local/apache2/bin/apachectl restart
  这样apache就会把jsp请求交给tomcat来处理了

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-330795-1-1.html 上篇帖子: Tomcat源码学习(转) 下篇帖子: 设置tomcat为debug模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表