• apache+tomcat整合(动静分离) 大风起


    1. 官网下载Apache源码包:http://httpd.apache.org/download.cgi
    2. 下载apr &apr-util :http://apache.osuosl.org/apr/
    3. 下载pcre :http://ftp.pcre.org/pub/pcre/
    4. expat:https://sourceforge.net/projects/expat/files/expat/2.0.1/expat-2.0.1.tar.gz/download

    源码编译Apache:

    安装apr

    # tar xzvf apr-1.6.3.tar.gz # cd apr-1.6.3 # ./configure --prefix=/usr/local/apr # sudo make # sudo make install

    安装Expat

    # tar xzvf expat-2.0.1.tar.gz # cd expat-2.0.1 # ./configure # sudo make # sudo make install

    安装apr-util

    # tar xzvf apr-util-1.6.1.tar.gz

    # cd apr-util-1.6.1

    # ./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr

    # sudo make

    # sudo make install

    安装pcre-8.10.zip

    #unzip pcre-8.10.zip #cd pcre-8.10 #./configure --prefix=/usr/local/pcre #sudo make #sudo make install

    apr目录,apr-util目录复制到httpd下的srclib/,例如:

    # cd /usr/local/src/

    # cp -r apr-1.5.2 /usr/local/src/httpd-2.4.7/srclib/apr

    # cp -r apr-util-1.5.4 /usr/local/src/httpd-2.4.7/srclib/apr-util

    最后安装apahce:(安装httpd服务需要指定apr apr-util pcre这三个目录才能正常安装)

    ./configure --with-included-apr --prefix=/usr/local/apache2  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre/  --enable-rewrite --enable-so  --enable-mods-shared=most

    httpd服务安装完成

    二、启动Apache并访问验证

    默认的web根目录为:htddocs

    # ./apachectl –k start|stop|restart 分别为启动 停止 重启

    打开浏览器 输入 http://IP地址:端口(避免冲突,最好修改默认端口)

    指定ServerName

    配置rc.local文件将Apache的服务加入到开机自动启动
    # echo'/usr/local/apache2/bin/apachectl -k start'  >>  /etc/rc.d/rc.local

    假设Tomcat已经安装完毕

    开始编译mod_jk

    下载tomcat-connectors-*

    http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz

    解压后,进入native文件夹

    # cd tomcat-connectors-1.2.43-src/native # ./configure --with-apxs=/usr/local/apache/bin/apxs (此处可根据apxs实际地址修改) # make

    完成编译后,在/usr/local/tomcat-connectors-1.2.43-src/native/apache-2.0文件夹下可以找到mod_jk.so文件

    # cp ./apache-2.0/mod_jk.so /usr/local/apache/modules/

    开始整合APACHE && TOMCAT:

    1、创建配置文件
    ./apache/conf/下面建立两个配置文件mod_jk.conf和workers.properties

    创建mod_jk.conf内容如下:

    JkWorkersFile     /usr/local/apache2/conf/workers.properties  

    # Where to put jk logs  

    JkLogFile     /var/log/httpd/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 /*/servlet/*  worker1  

    JkMount /*.jsp worker1  

    JkMount /application/* worker1  

    JkMount /*.do worker1  

    JkMount /*.class worker1  

    JkMount /*.jar worker1

    其中,前两个参数(JkWorkersFile和JkLogFile)具体的值会因为apache安装路径的不同而不同,此处需写入自己的apache服务器的路径。

    workers.properties内容如下

     # Defining a worker named worker1 and of type ajp13  

    worker.list=worker1  

     # Set properties for worker1  

    worker.worker1.type=ajp13 (对应Tomcat的AJP)   

    worker.worker1.host=localhost   (Tomcat服务的ip)

    worker.worker1.port=8009  (此处是tomcat的AJP端口)

    worker.worker1.lbfactor=50    

    worker.worker1.cachesize=10    

    worker.worker1.cache_timeout=600    

    worker.worker1.socket_keepalive=1    

    worker.worker1.socket_timeout=300

    ###########################################################################

    接着是对/conf文件夹下自带的httpd.conf文件尾部加入如下内容:

    LoadModule jk_module modules/mod_jk.so
    Include /etc/httpd/conf/mod_jk.conf
    <VirtualHost *:80>
    DocumentRoot "/usr/local/apache-tomcat-7.0.81/webapps/test" (此处为tomcat新建测试test项目目录,根据实际情况修改)

    JkUnMount /*.html worker1
    JkUnMount /*.htm worker1
    JkUnMount /*.shtml worker1
    JkUnMount /*.js worker1
    JkUnMount /*.css worker1
    JkUnMount /*.gif worker1
    JkUnMount /*.jpg worker1
    JkUnMount /*.png worker1
    JkUnMount /*.bmp worker1
    JkUnMount /*.mov worker1
    JkUnMount /*.mov worker1
    JkUnMount /*.midi worker1
    JkUnMount /*.mid worker1
    JkUnMount /*.rm worker1
    JkUnMount /*.ram worker1
    JkUnMount /*.au worker1
    JkUnMount /*.wav worker1
    JkUnMount /*.mpga worker1
    JkUnMount /*.avi worker1
    JkUnMount /*.mp3 worker1
    JkUnMount /*.mp4 worker1
    JkUnMount /*.mpg worker1
    JkUnMount /*.swf worker1
    JkUnMount /*.mpeg worker1
    JkUnMount /*.ppt worker1
    JkUnMount /*.pptx worker1
    JkUnMount /*.doc worker1
    JkUnMount /*.docx worker1
    JkUnMount /*.xls worker1
    JkUnMount /*.xlsx worker1
    JkMount /* worker1

    </VirtualHost>
    保存之后重启Apache和Tomcat。

    新建index.jsp页面放于tomcat目录webapps/test/index.jsp

    访问http://ip:8088/test/index.jsp

     

    假设是一种超能力
  • 相关阅读:
    CSS躬行记(9)——网格布局
    CSS躬行记(8)——裁剪和遮罩
    CSS躬行记(7)——合成
    CentOS 系统目录解析
    Linux 命令快捷键
    秒的精确度
    Oracle和mysql中装逼dual表的用途介绍
    mysql 的mgr集群
    ansible笔记
    cygwin
  • 原文地址:https://www.cnblogs.com/Haihong72H/p/11039668.html
Copyright © 2020-2023  润新知