前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Apache+Tomcat 动静分离

Apache+Tomcat 动静分离

作者头像
星哥玩云
发布2022-07-27 20:52:08
4770
发布2022-07-27 20:52:08
举报
文章被收录于专栏:开源部署

环境准备:

CentOS 7

需要软件

  • jdk-8u45-linux-x64.tar.gz
  • apache-tomcat-8.5.40.tar.gz
  • apr-1.6.5.tar.gz
  • apr-util-1.6.1.tar.gz
  • pcre-8.40.tar.gz
  • httpd-2.4.39.tar.gz
  • tomcat-connectors-1.2.46-src.tar.gz

安装jdk环境

(所有的软件均放置在/usr/local/src/下面)

(1)解压jdk并放置在/usr/local/目录下 cd /usr/local/src/ tar xzf jdk-8u45-linux-x64.tar.gz mv jdk1.8.0_45 /usr/local/jdk1.8 (2)添加为系统环境变量 vim /etc/profile

安装tomcat

tar xfz apache-tomcat-8.5.40.tar.gz mv apache-tomcat-8.5.40 /usr/local/tomcat

安装apr

cd /usr/local/src/ tar xfz apr-1.6.5.tar.gz yum -y install gcc-c++ cd /usr/local/src/apr-1.6.5 ./configure --prefix=/usr/local/apr make make install

Apr安装报错: rm: cannot remove 'libtoolT': No such file or directory 解决: 修改执行文件configure第30392行

安装apr-util

cd /usr/local/src/ tar xfz apr-util-1.6.1.tar.gz ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install

Apr-util安装报错: xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory 解决: 安装yum -y install expat-devel

安装pcre

cd /usr/local/src/ tar xfz pcre-8.40.tar.gz ./configure --prefix=/usr/local/pcre && make && make install

编译安装httpd

cd /usr/local/src/ tar xfz httpd-2.4.39.tar.gz cd httpd-2.4.39 ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre make make install

编译安装报错: make[2]: *** [htpasswd] Error 1 make[2]: Leaving directory `/usr/local/httpd-2.4.33/support' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/usr/local/httpd-2.4.33/support' make: *** [all-recursive] Error 1 解决: 解决方法: 把解压好的apr和apr-util (这里是刚解压出来的源码文件夹)复制到 /httpd-2.4.33/srclib/ 中去 cp -r apr-1.6.1 /usr/local/src/httpd-2.4.33/srclib/apr cp -r apr-util-1.6.2 /usr/local/src/httpd-2.4.33/srclib/apr-util 重新编译: ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-included-apr && make && make install

安装编译模块

yum -y install wget cd /usr/local/src/ tar xfz tomcat-connectors-1.2.46-src.tar.gz cd tomcat-connectors-1.2.46-src/native ./configure --with-apxs=/usr/local/apache/bin/apxs make

如果make成功的话,在当前目录的apache-2下应该会生成一个mod_jk.so,把它复制到你apache的modules下。

cp mod_jk.so /usr/local/apache/modules/

编辑apache配置文件

vi /etc/httpd/httpd.conf #增加下面内容 Include /etc/httpd/conf/mod_jk.conf

新建 mod_jk.conf和workers.properties文件

mkdir /etc/httpd/conf #在/etc/httpd/conf目录下新建 mod_jk.conf和workers.properties文件 #mod_jk.conf的内容是jk的配置文件,包括装载模块和日志信息以及指定解析的工作器和目录。 

LoadModule jk_module /usr/local/apache/modules/mod_jk.so JkWorkersFile /etc/httpd/conf/workers.properties #JkLogFile /var/log/httpd/mod_jk.log JkLogLevel info #JkshmFile /var/log/httpd/mod_jk.shm JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkRequestLogFormat "%w %V %T" JkMount /servlet/* ajp13  #此处的ajp13是workers.properties文件中的worker.list配置的值,一定要写的一样,否则会报错 JkMount /*.jsp ajp13 JkMount /*.do ajp13 JkAutoAlias /usr/local/apache/htdocs

#workers.properties是Tomcat wokers的配置文件。内容如下: worker.ajp13.port= 8009 worker.ajp13.host= 127.0.0.1 worker.ajp13.type= ajp13 worker.ajp13.lbfactor= 1

启动tomcat和apache服务,检查是否能正常启动

/usr/local/tomcat/bin/startup.sh  #启动tomcat

/usr/local/apache/bin/apachectl start #启动apache

创建测试文件

#在tomcat服务器下创建html文件 vi /usr/local/tomcat/webapps/test/test.html #输入如下内容 This is tomcat's html page #在tomcat服务器下创建jsp文件 vi /usr/local/tomcat/webapps/test/showtime.jsp #输入如下内容 <%@page language="Java" import="java.util.*"%> ::this is tomcat's jsp page Now,the time&date is : <%out.println(new Date());%>

#在apche服务器下创建html文件  vi /usr/local/apache2/htdocs/test/test.html #输入如下内容 This is apache's html page  #在apache服务器下创建jsp文件  vi /usr/local/apache2/htdocs/test/showtime.jsp #输入如下内容 <%@page language="java" import="java.util.*"%> ::this is apache's jsp page Now,the time&date is : <%out.println(new Date());%>

在IE浏览器测试

#在IE浏览器地址栏输入 http://localhost/test/showtime.jsp #输出内容如下,使用的是tomcat下的jsp文件,没有使用apahce下的jsp文件 ::this is tomcat's jsp page Now,the time&date is : Wed Mar 22 05:50:22 CST 2017 #在IE浏览器地址栏输入 http://localhost/test/test.html #输出内容如下,使用的apahce下html文件,没有使用tomcat下的 This is apache's test html page

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档