Getting Apache2 and Tomcat5 to work
Installing
First of all we need to install apache and tomcat.
$emerge apache
$emerge tomcat
I have installed apache with the berkdb doc gdbm threads options turned on.
For tomcat only the doc option was turned on.
Starting
$/etc/init.d/apache2 start
$/etc/init.d/tomcat5 start
You can test to see if your servers are started correctly by surfing to http://localhost for apache and to http://localhost:8080 for tomcat.
If you can see a notification of both servers they are started successfully
JK2 Connector
Getting+Installing
Instaling connector via portage:
Code: instaling JK2 connector |
emerge mod_jk2 |
Or you can download the JK2 connector from apache's website (http://www.apache.org/dist/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz).
Code: Downloading and untarring source |
$wget http://www.apache.org/dist/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz |
Before we config and compile, lets get the config vars in an accepable place.
Code: |
$# Works for me without these 3 lines |
What you just built and copied were the mod_jk2.so and libjkjni.so files.
Setting up the jk2 connector
First of all lets stop apache and tomcat, so that nothing crashes.
Code: |
$/etc/init.d/apache2 stop |
Lets touch the socket
Code: |
$touch /opt/tomcat5/work/jk2.socket |
Configuring everything to work together
/etc/tomcat5/jk2.properties
Make sure everything in this file is commented out.
Default values are good enough.
/etc/apache2/conf/workers2.properties
Mine looks like this:
File: workers2.properties |
[shm] file=/opt/tomcat5/logs/shm.file size=1048576 # Example socket channel, override port and host. [channel.socket:localhost:8009] port=8009 host=127.0.0.1 # define the worker [ajp13:localhost:8009] channel=channel.socket:localhost:8009 # Uri mapping [uri:/*.jsp] [uri:/~*/*.jsp] [uri:/jsp-examples] worker=ajp13:localhost:8009 |
/etc/apache2/conf/apache2.conf
Just add these lines to get jsp working in every user directory + documentroot:
File: apache2.conf |
### Load the jk2 module LoadModule jk2_module /usr/lib/apache2/mod_jk2.so ### Set the config file for jk2 JkSet config.file /etc/apache2/conf/workers2.properties ### Forward all jsp files to the worker <Location "/*.jsp"> JkUriSet worker ajp13:localhost:8009 </Location> ### Every user a website UserDir public_html UserDir disabled root ### Automaticly load index DirectoryIndex index.html index.htm index.jsp index.txt |
/etc/tomcat5/server.xml
Search for the host specification where <host name=localhost ... is located and replace it by these files
NOTE: Remember to remove the matching </Host> tag located towards the end of the file.
File: server.xml |
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" |
Take care that all host tags are closed and none are left open.
I gave 2 hostnames as you can see. The first is only accessible from localhost:8080 and the second is accessible from the internet by surfing to your servername.
The first is the default start screen of tomcat but it can be very handy to manage or test some files.
Restarting servers
Code: Starting Services |
$/etc/init.d/apache2 start |
Testing
I wrote a small file called test.jsp to see if your apache forwards jsp files to tomcat.
File: test.jsp |
<HTML> <BODY> Hello! The time is now <%= new java.util.Date() %> </BODY> </HTML> |
Test it:
http://YOUR_SERVERNAME/test.jsp.
If your /var/log/apache2/error_log log says
[Wed Nov 17 15:10:54 2004] [error] shm.create(): error creating shm 70014 End of file found [Wed Nov 17 15:10:54 2004] [error] shm.create(): error creating shm /opt/tomcat5/logs/shm.file
then remove the [shm] section from /etc/apache2/conf/workers2.properties. This is a workaround to use TCP instead of shared memory (faster on localhost) for communication.
Thanks
Special thanks to barcct (http://forums.gentoo.org/viewtopic.php?t=195834&highlight=apache2+tomcat5) and d2r (http://www.dynamicobjects.com/d2r/archives/002574.html)
Greetz Matata
Categories: HOWTO | Java
'StoreHouse > Server' 카테고리의 다른 글
국내,국외 네트웍 사용기관 정보조회 (0) | 2005.01.19 |
---|---|
스팸릴레이 유무 확인사이트 (0) | 2005.01.11 |
resin-2.0.5 + iis 5.0 설치방법 & 버츄얼 호스팅 (0) | 2004.12.10 |
Mysql 자동백업 스크립트 2003/07/11 (0) | 2004.12.10 |
Gentoo APM emerge (0) | 2004.12.10 |