Apache+tomcat 动静分离
环境准备: Centos7 需要软件 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