vendredi 24 octobre 2008

AJP13 avec apache

Pour router votre serveur apache vers le serveur tomcat, il faut utiliser un proxy, apache délègue sa requête au serveur tomcat. Ce mode de fonctionnement permet surtout de faire du load balancing et, lorsqu'il s'agit de servir des fichiers, utiliser la code natif plus performant de apache.

Après avoir installé et déclarés le module proxy_ajp_module dans le fichiers httpd.conf :

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so



Ajouter dans le fichier httpd.conf les lignes suivantes

Include conf/vhosts.d/*.conf
<Location /wiki >
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apachepasswd
Require user wiki
ProxyPass ajp://localhost:8009/JSPWiki
ProxyPassReverse ajp://localhost:8009/JSPWiki
allow from all
</Location>
<Location /gestion >
ProxyPass ajp://localhost:8009/gestion
ProxyPassReverse ajp://localhost:8009/
allow from all
</Location>



Autrement, il est aussi possible de créer un fichier worker.properties
# worker "worker1" will talk to Tomcat listening on machine www.x.com at port 8007 using 2 lb factor
worker.list=worker1
worker.worker1.host=myhost
worker.worker1.port=9009
worker.worker1.lbfactor=2





# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/httpd/conf/worker.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/httpd/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /ft-jobs/* worker1


Changer l'URL


Pour configurer de manière centralisée les applications, il est possible d'utiliser un apache frontal et de repartir les adresses vers des serveurs mandatataires, apache agit donc comme un proxy et il suffit d'ajouter la ligne suivante dans le fichier httpd.conf
Par exemple si la machine vm04 est le frontal et que le serveur hudson est sur la vm04, il suffit d'ajouter la ligne suivante au fichier httpd.conf


ProxyPass /hudson/ http://vm04:8080/hudson/


On accedera à hudson par l'url http://vm01/hudson/



Faire du load balancing


Solution n°1


<Location /jonas>
ProxyPass balancer://mycluster/
ProxyPassReverse balancer://mycluster/
Allow From All
</Location>


<Proxy balancer://mycluster>
BalancerMember ajp://localhost:9009/myapp
BalancerMember ajp://localhost:8009/myapp
</Proxy>


Solution n°2




ProxyPass http://localhost/myapp/
ProxyPassReverse /myapp/
Allow From All


JkWorkersFile /etc/httpd/conf/worker.properties
JkShmFile /var/log/httpd/mod_jk.shm
access_log)
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount /myapp/* worker1

Aucun commentaire: