| genie:/home/sargue# mv j2sdk1.4.2_04
/usr/local genie:/home/sargue# chown -R root.root /usr/local/j2sdk1.4.2_04/ |
| genie:/etc# cat profile # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/j2sdk1.4.2_04/bin" if [ "$PS1" ]; then if [ "$BASH" ]; then PS1='\u@\h:\w\$ ' else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi JAVA_HOME="/usr/local/j2sdk1.4.2_04" export PATH JAVA_HOME umask 022 |
| sargue@genie:~$ java -version java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode) |
Sustituimos el server.xml bajo el directorio conf por el
server-minimal.xml.
Ejecutaremos Tomcat como un usuario no privilegiado (no root), para
ello creamos una cuenta del sistema tomcat5 , copiamos la
distribución a ese fichero y cambiamos los permisos para que
sean los del nuevo usuario.
| genie:/home/sargue# adduser --system
tomcat5 Adding system user `tomcat5'... Adding new user `tomcat5' (103) with group `nogroup'. Creating home directory `/home/tomcat5'. genie:/home/sargue# mv jakarta-tomcat-5.0.27 /usr/local/tomcat5 genie:/home/sargue# cd /usr/local genie:/usr/local# ls -l total 36 drwxrwsr-x 2 root staff 4096 Jun 6 23:09 bin drwxrwsr-x 2 root staff 4096 Jun 6 23:09 games drwxrwsr-x 2 root staff 4096 Jun 6 23:09 include drwxrwxr-x 9 root root 4096 Jun 28 14:54 j2sdk1.4.2_04 drwxrwsr-x 2 root staff 4096 Jun 6 23:09 lib lrwxrwxrwx 1 root staff 9 Jun 6 23:09 man -> share/man drwxrwsr-x 2 root staff 4096 Jun 6 23:09 sbin drwxrwsr-x 3 root staff 4096 Jun 6 23:09 share drwxrwsr-x 2 root staff 4096 Jun 6 23:09 src drwxr-xr-x 11 sargue sargue 4096 Oct 4 16:52 tomcat5 genie:/usr/local# chown -R tomcat5.nogroup tomcat5/ |
Ahora necesitamos preparar el script init.d para la ejecución
y parada automática del servicio. Usaremos un script localizado
en el blog
de Alvaro Sánchez-Mariscal.
El script basado en la plantilla y modificado según los
parámetros y decisiones de arquitectura para nuestro caso:
| #! /bin/sh # # Starts and stops Tomcat as a system service # Alvaro Sanchez-Mariscal (mariscal@javahispano.org) PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/tomcat5/bin/catalina.sh NAME=tomcat5 USER=$NAME DESC="JSP/Servlets container" export JAVA_OPTS=-Djava.awt.headless=true test -x $DAEMON || exit 0 set -e case "$1" in start) echo "Starting $DESC: $NAME" start-stop-daemon --chuid $USER --user $USER --start --quiet --exec $DAEMON -- start echo "Done" ;; stop) echo "Stopping $DESC: $NAME " start-stop-daemon --start --user $USER --quiet --exec $DAEMON -- stop echo "Done" ;; restart) echo "Restarting $DESC: $NAME" start-stop-daemon --start --user $USER --quiet --exec $DAEMON -- stop sleep 1 start-stop-daemon --chuid $USER --user $USER --start --quiet --exec $DAEMON -- start echo "Done" ;; *) N=/etc/init.d/$NAME # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 echo "Usage: $N {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 |
Guardamos este fichero como /etc/init.d/tomcat5
con permisos 755 (chmod 755
tomcat5).
Utilizaremos la herramienta sudo para permitir a ciertos usuarios
poder actuar sobre el servicio sin haber de otorgar privilegios
generales de root.
| genie:/etc/init.d# apt-get install sudo Reading Package Lists... Done Building Dependency Tree... Done The following NEW packages will be installed: sudo 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 147kB of archives. After unpacking 369kB of additional disk space will be used. Get:1 http://jane.uab.es testing/main sudo 1.6.7p5-2 [147kB] Fetched 147kB in 9s (15.4kB/s) Selecting previously deselected package sudo. (Reading database ... 17107 files and directories currently installed.) Unpacking sudo (from .../sudo_1.6.7p5-2_i386.deb) ... Setting up sudo (1.6.7p5-2) ... No /etc/sudoers found... creating one for you. |
Añadimos una entrada para permitir la ejecución de /etc/init.d/tomcat5 al
usuario/s. Para editar el fichero de permisos de sudo se utiliza el
comando visudo:
| # /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # See the man page for details on how to write a sudoers file. # # Host alias specification # User alias specification # Cmnd alias specification Cmnd_Alias TOMCAT5 = /etc/init.d/tomcat5, /usr/bin/vi /usr/local/tomcat5/conf/*,\ /bin/chown -R tomcat5.nogroup /usr/local/tomcat5 # User privilege specification root ALL=(ALL) ALL sargue ALL= TOMCAT5 |
Dado que ya tenemos Apache como servidor web para páginas
estaticas, recursos CGI, páginas PHP y accesos SSL, conectaremos
Apache con Tomcat para servir sólo ciertos recursos
(páginas con JSP/servlets).
Instalamos el módulo JK para Apache:
| genie:/usr/local/tomcat5/conf# apt-get
install libapache-mod-jk Reading Package Lists... Done Building Dependency Tree... Done Suggested packages: tomcat4 The following NEW packages will be installed: libapache-mod-jk 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 180kB of archives. After unpacking 889kB of additional disk space will be used. Get:1 http://jane.uab.es testing/main libapache-mod-jk 1:1.2.5-2 [180kB] Fetched 180kB in 7s (23.2kB/s) Selecting previously deselected package libapache-mod-jk. (Reading database ... 17130 files and directories currently installed.) Unpacking libapache-mod-jk (from .../libapache-mod-jk_1%3a1.2.5-2_i386.deb) ... Setting up libapache-mod-jk (1.2.5-2) ... Replacing config file /etc/apache/modules.conf with new version |
Creamos el fichero de configuración del módulo
mínimo (/etc/apache/workers.properties)
y el fichero de configuración del Apache para conectar a Tomcat (/etc/apache/conf.d/tomcat),
siguiente la guía
oficial:
| genie:/etc/apache# cat
workers.properties # Define 1 real worker using ajp13 worker.list=worker1 # Set properties for worker1 (ajp13) worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.socket_timeout=300 genie:/etc/apache# cat conf.d/tomcat JkWorkersFile workers.properties JkLogFile /var/log/apache/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" JkMount /tomcat-docs/* worker1 |
Con esta configuración si accedemos a /tomcat-docs/ en el
servidor conectaremos con Tomcat.
Para la gestión de las aplicaciones web (instalar,
desinstalar, actualizar, etc.) usaremos el Tomcat Webapp Manager. Para
ello, hemos de modificar ligeramente la configuración del Tomcat
y del Apache asociado.
|
<Host name="localhost" appBase="webapps"> <Context path="/manager" debug="0" privileged="true" docBase="server/webapps/manager"> </Context> </Host> |