歡迎您光臨本站 註冊首頁

實戰 linux 下apache 和 tomcat的整合

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

我們這裡只講apache 和tomcat的整合,apache 和 tomcat都安裝成功 並測試正常

apache的安裝路徑為 /usr/local/httpd 文檔主目錄為 /data/webapps

tomcat的安裝路徑為 /usr/local/tomcat6 文檔主目錄為 /data/webapps/company (以公司網站為例)

有關apache 和 tomcat的安裝與配置請查看我的另兩篇文章:

《linux 下 mysql apache php gd 的安裝和配置》http://jedy82.blog.51cto.com/425872/310392

《linux 下JDK6 TOMCAT6 安裝與配置》http://jedy82.blog.51cto.com/425872/271984

一、安裝 jakarta

jakarta可從以下地址下載,要注意版本

http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/source/jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz

1,解壓縮連接器,並將文件夾移動至/opt下


# tar -zxvf jakarta-tomcat-connectors-jk2-2.0.4-src-current.tar.gz
# mv jakarta-tomcat-connectors-jk2-2.0.4-src /opt


2,進入安裝目錄


[root@localhost ]# cd /opt/jaka*
[root@localhost jakarta-tomcat-connectors-jk2-2.0.4-src]# cd jk/native2
[root@localhost native2]# ./buildconf.sh
[root@localhost native2]# ./configure –with-apxs2=/usr/local/apache2/bin/apxs #改成你的apache安裝目錄.


3,安裝,生成編譯配置文件.就可以看到mod_jk2.so文件已經在你的apache/modules/ 中了


[root@localhost native2]# make
[root@localhost native2]# cd ../build/jk2/apache2
[root@localhost native2]# /usr/local/apache2/bin/apxs -n jk2 -i mod_jk2.so (可省略)

[root@localhost native2]# cp ../build/jk2/apache2/mod_jk2.so /usr/local/apache/modules
4,編輯apache目錄的 /usr/local/apache2/conf/httpd.conf的文件.


在httpd.conf文件中添加LoadModule jk2_module modules/mod_jk2.so一行並保存(修改httpd.conf文件前最好作個備份)


找到" DirectoryIndex" ,在index .html後面再添加index.jsp

二、修改配置相關文件


1、在apache/conf/中新建文件workers2.properties,內容為下(注意其中目錄要改為你的目錄噢):

[root@localhost root] # more /usr/local/http/conf/workers2.properties

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

[logger.httpd]
file=/usr/local/httpd/logs/jk2.log

level=INFO
debug=1
[config]
file=/usr/local/httpd/conf/workers2.properties

level=INFO
debug=1

[channel.socket:127.0.0.1:8009]
host=127.0.0.1
port=8009
[shm]
file=/usr/local/httpd/logs/jk2.shm

#size=1048576
# define the worker
[ajp13:127.0.0.1:8009]
channel=channel.socket:127.0.0.1:8009
#[uri:/*]

[uri:/*.jsp]
[uri:company/*.jsp]

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

2、編輯httpd.conf,去除無關的行,完整內容見附件,內容為下(注意其中目錄要改為你的目錄噢) :
[root@localhost root] # more /usr/local/http/conf/httpd.conf

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

ServerRoot "/data/webapps/"

<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>

</IfModule>
</IfModule>

<IfModule !mpm_netware.c>
<IfModule !perchild.c>

</IfModule>
</IfModule>

<IfModule !mpm_netware.c>
PidFile logs/httpd.pid
</IfModule>

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10


MaxClients 150
MaxRequestsPerChild 0
</IfModule>

<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

<IfModule perchild.c>
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 0
</IfModule>

<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild 0
</IfModule>

<IfModule beos.c>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>

<IfModule mpm_netware.c>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 0
MaxMemFree 100
</IfModule>

<IfModule mpmt_os2.c>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
</IfModule>

Listen 80

LoadModule speling_module modules/mod_speling.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
LoadModule jk2_module modules/mod_jk2.so

<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>

User nobody
Group nobody
</IfModule>
</IfModule>

ServerAdmin ctian@digican-rfid.com

ServerName 127.0.0.1

UseCanonicalName Off

DocumentRoot "/data/webapps/"

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory "/data/webapps/htdocs">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny
Allow from all

</Directory>

UserDir public_html

DirectoryIndex index.html index.jsp index.php index.html.var

AccessFileName .htaccess

<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>

TypesConfig conf/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off

ErrorLog logs/error_log

LogLevel warn

LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
LogFormat "%{Referer}i -&gt; %U" referer
LogFormat "%{User-agent}i" agent

CustomLog logs/access_log common

ServerTokens Full

ServerSignature On

Alias /icons/ "/data/webapps/icons/"

<Directory "/data/webapps/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

AliasMatch ^/manual(?:/(?:de|en|es|fr|ja|ko|ru))?(/.*)?$ "/data/webapps/manual$1"

<Directory "/data/webapps/manual">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all

<Files *.html>
SetHandler type-map
</Files>

SetEnvIf Request_URI ^/manual/(de|en|es|fr|ja|ko|ru)/ prefer-language=$1


RedirectMatch 301 ^/manual(?:/(de|en|es|fr|ja|ko|ru)){2,}(/.*)?$ /manual/$1$2
</Directory>

ScriptAlias /cgi-bin/ "/data/webapps/cgi-bin/"

<IfModule mod_cgid.c>
</IfModule>

<Directory "/data/webapps/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

IndexOptions FancyIndexing VersionSort

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif

ReadmeName README.html
HeaderName HEADER.html

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en


AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

ForceLanguagePriority Prefer Fallback

AddCharset ISO-8859-1 .iso8859-1 .latin1
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddCharset ISO-8859-3 .iso8859-3 .latin3
AddCharset ISO-8859-4 .iso8859-4 .latin4
AddCharset ISO-8859-5 .iso8859-5 .latin5 .cyr .iso-ru
AddCharset ISO-8859-6 .iso8859-6 .latin6 .arb
AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk
AddCharset ISO-8859-8 .iso8859-8 .latin8 .heb
AddCharset ISO-8859-9 .iso8859-9 .latin9 .trk
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5 .Big5 .big5

AddCharset WINDOWS-1251 .cp-1251 .win-1251
AddCharset CP866 .cp866
AddCharset KOI8-r .koi8-r .koi8-ru
AddCharset KOI8-ru .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-8 .utf8

AddCharset GB2312 .gb2312 .gb
AddCharset utf-7 .utf7
AddCharset utf-8 .utf8
AddCharset big5 .big5 .b5
AddCharset EUC-TW .euc-tw
AddCharset EUC-JP .euc-jp
AddCharset EUC-KR .euc-kr


AddCharset shift_jis .sjis

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

AddHandler type-map var

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

<IfModule mod_ssl.c>
Include conf/ssl.conf
</IfModule>

NameVirtualHost *
<VirtualHost * >
DocumentRoot /data/webapps/company/
ServerName localhost
Alias /dotproject /data/webapps/dotproject
</VirtualHost>

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

3、編輯server.xml,完整內容見附件,內容為下(注意其中目錄要改為你的目錄噢) :
[root@localhost root] # more /usr/local/tomcat6/conf/server.xml

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

<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"


type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
&lt;Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
--&gt;
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
&lt;Connector executor="tomcatThreadPool"
port="80" protocol="HTTP/1.1"


connectionTimeout="20000"
redirectPort="8443" />
--&gt;
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
&lt;Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
--&gt;

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
&lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
--&gt;
<Engine name="Catalina" defaultHost="www.xxx.com">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
&lt;Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>


--&gt;

<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html -->
<!--
&lt;Valve className="org.apache.catalina.valves.RequestDumperValve"/>
--&gt;

<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="www.xxx.com" appBase="/data/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/data/webapps" reloadable="true" caseSensitive="false" debug="0"/>

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
&lt;Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--&gt;

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/data/logs"


prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

</Host>
</Engine>
</Service>
</Server>

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

三、重啟機器


[火星人 ] 實戰 linux 下apache 和 tomcat的整合已經有458次圍觀

http://coctec.com/docs/linux/show-post-50766.html