環(huán)境準備:
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環(huán)境
(所有的軟件均放置在/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)添加為系統(tǒng)環(huán)境變量
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
解決:
修改執(zhí)行文件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
創(chuàng)建測試文件
#在tomcat服務器下創(chuàng)建html文件
vi /usr/local/tomcat/webapps/test/test.html
#輸入如下內容
This is tomcat’s html page
#在tomcat服務器下創(chuàng)建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服務器下創(chuàng)建html文件
vi /usr/local/apache2/htdocs/test/test.html
#輸入如下內容
This is apache’s html page
#在apache服務器下創(chuàng)建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