Inhaltsverzeichnis
Apache HTTP Server CentOS 7 - mod_jk - Apache Tomcat Kommunikation
Der Apache HTTP Server ist ein Open Source Webserver und der seit 1996 am meisten im Internet eingesetzte Webserver weltweit. Der freie und quell offenen Webserver wird von der Apache Software Foundation zur Verfügung gestellt und weiterentwickelt.
Um den Apache HTTP Server als z.B. Frontend-Server vor eines Apache Tomcat Server zu betreiben, kann als Kommunikationsprotokoll das AJP/1.3-Protokoll zum Einsatz kommen.
Hierbei gibt es zwei Module, die die Kommunikation zwischen dem Apache HTTP Server und dem Apache Tomcat Server über das AJP/1.3-Protokoll bewerkstelligen können:
mod_jk
- Federführung bei der Entwicklung Apache Tomcat Servermod_proxy_ajp
- Federführung bei der Entwicklung Apache HTTP Server- Siehe auch internen Link: Apache HTTP Server CentOS 7 - mod_proxy_ajp - Apache Tomcat Kommunikation
Nachfolgend soll der Einsatz des Moduls - mod_jk
beschrieben werden.
Ab hier werden root
-Rechte zur Ausführung der nachfolgenden Befehle benötigt. Um root
zu werden geben Sie bitte folgenden Befehl ein:
$ su - Password:
Herunterladen
Nachfolgend soll ein Drittanbieter-Repository, welches von dem mir sehr geschätzten Michael Nausch betrieben wird und eine sichere und verlässliche Quelle für rpm-Pakete darstellt, wie unter nachfolgendem internen Link dargestellt, eingebunden werden:
Installation
Nachdem das Drittanbieter-Repository
erfolgreich eingebunden wurde, kann mit nachfolgendem Befehl, das rpm
-Paket - httpd-mod_jk
installiert werden:
# yum install httpd-mod_jk Loaded plugins: changelog, priorities 122 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package httpd-mod_jk.x86_64 0:1.2.40-1.el7.centos will be installed --> Finished Dependency Resolution Changes in packages about to be updated: Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd-mod_jk x86_64 1.2.40-1.el7.centos mailserver.guru-os 161 k Transaction Summary ================================================================================ Install 1 Package Total download size: 161 k Installed size: 418 k Is this ok [y/d/N]: y httpd-mod_jk-1.2.40-1.el7.centos.x86_64.rpm | 161 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : httpd-mod_jk-1.2.40-1.el7.centos.x86_64 1/1 Verifying : httpd-mod_jk-1.2.40-1.el7.centos.x86_64 1/1 Installed: httpd-mod_jk.x86_64 0:1.2.40-1.el7.centos Complete!
Mit nachfolgendem Befehl kann überprüft werden, welche Inhalte mit den Paket httpd-mod_jk
installiert wurden.
# rpm -qil httpd-mod_jk Name : httpd-mod_jk Epoch : 0 Version : 1.2.40 Release : 1.el7.centos Architecture: x86_64 Install Date: Tue 12 May 2015 01:40:47 PM CEST Group : Development/Java Size : 427794 License : Apache License Signature : RSA/SHA1, Tue 05 May 2015 12:30:49 PM CEST, Key ID 60ecfb9e8195aea0 Source RPM : httpd-mod_jk-1.2.40-1.el7.centos.src.rpm Build Date : Tue 05 May 2015 12:30:35 PM CEST Build Host : vml000200.dmz.nausch.org Relocations : (not relocatable) URL : http://tomcat.apache.org/ Summary : Tomcat mod_jk connector for Apache Description : The mod_jk module add support for the Apache HTTP Server, to communicate as a front-end server for Apache Tomcat Server or any other AJP1.3-enabled application server, with optional load-balancing. /etc/httpd/conf.modules.d/10-mod_jk.conf /etc/httpd/modules/mod_jk.so /usr/share/doc/httpd-mod_jk-1.2.40 /usr/share/doc/httpd-mod_jk-1.2.40/BUILDING.txt /usr/share/doc/httpd-mod_jk-1.2.40/LICENSE /usr/share/doc/httpd-mod_jk-1.2.40/NOTICE /usr/share/doc/httpd-mod_jk-1.2.40/README.txt /usr/share/doc/httpd-mod_jk-1.2.40/STATUS.txt /usr/share/doc/httpd-mod_jk-1.2.40/TODO.txt /usr/share/doc/httpd-mod_jk-1.2.40/workers.properties.minimal
Konfiguration
/etc/httpd/conf.modules.d/10-mod_jk.conf
Die Konfigurationsdatei /etc/httpd/conf.modules.d/10-mod_jk.conf
ermöglicht das Laden von mod_jk
in den Apache HTTP Server.
HINWEIS - Hier werden aktuell KEINE Anpassungen vorgenommen, da nur das Laden des Apache HTTP Server-Moduls mod_jk
in dieser Konfigurationsdatei konfiguriert wird!
(komplette Konfigurationsdatei)
# This file configures the mod_jk module: LoadModule jk_module modules/mod_jk.so
/etc/httpd/conf.d/jk.conf
Nachfolgende Konfigurationsdatei in nachfolgendem Verzeichnis mit nachfolgendem Namen
/etc/httpd/conf.d/jk.conf
soll mit nachfolgendem Befehl neu angelegt werden und die Konfiguration des Moduls mod_jk
beinhalten:
# touch /etc/httpd/conf.d/jk.conf
Anschließend sollte nachfolgender Inhalt in die Konfigurationsdatei - /etc/httpd/conf.d/jk.conf
- eingefügt werden:
<IfModule jk_module> # Apache httpd and Apache Tomcat Connector Configuration. # JkRequestLogFormat: %r %q - not used, because form-field e.g. password # are shown. # JkShmSize size can now be determined automatically # JkShmSize 64k JkShmFile "/etc/httpd/run/mod_jk.shm" JkLogFile "/var/log/httpd/mod_jk.log" JkLogLevel error JkLogStampFormat "[%a, %d.%m.%Y %H:%M:%S] " JkRequestLogFormat "%w %R %V %v %s %b %B %U %p %T %H %m" JkWorkerProperty workers.tomcat_home="/usr/share/tomcat" JkWorkerProperty workers.java_home="/usr/lib/jvm/jre" JkWorkerProperty worker.list=worker1,jkstatus JkWorkerProperty worker.jkstatus.type=status JkWorkerProperty worker.worker1.type=ajp13 JkWorkerProperty worker.worker1.host=127.0.0.1 JkWorkerProperty worker.worker1.port=8099 </IfModule>
* Dies ist nur eine Beispielkonfiguration.
HINWEIS - Die Bedeutung der einzelnen Befehle kann in der Dokumentation The Apache Tomcat Connector - Reference Guide detailliert nachgelesen werden.
JkShmSize 64k
nur erforderlich für balancer- und status.worker - Zusätzlicher Cache-Speicher auf der Festplatte (Shared Memeory)
JkShmFile "/etc/httpd/run/mod_jk.shm"
nur erforderlich für balancer- und status.worker - Datei für den zusätzlichen Cache-Speicher auf der Festplatte (Shared Memeory)
JkLogFile "/var/log/httpd/mod_jk.log"
Log-Datei des Modules mod_jk
JkLogLevel error
Loglevel der Log-Datei des Modules mod_jk - Standard ist info
JkLogStampFormat "[%a, %d.%m.%Y %H:%M:%S] "
Format des verwendeten Zeitstempels - siehe auch The Apache Tomcat Connector - Reference Guide
JkRequestLogFormat "%w %R %V %v %s %b %B %U %p %T %H %m"
Format des Log-Eintrags - siehe auch The Apache Tomcat Connector - Reference Guide
JkWorkerProperty workers.tomcat_home="/usr/share/tomcat"
Heimatverzeichnis des Apache Tomcat
JkWorkerProperty workers.java_home="/usr/lib/jvm/jre"
Heimatverzeichnis der installierten Java-Version.
JkWorkerProperty worker.list=worker1,jkstatus
Definition der liste der worker
.
JkWorkerProperty worker.jkstatus.type=status
Definition des besonderen workers status
, über dessen Aufruf in einer URL eine Status-Anzeige erfolgt.
JkWorkerProperty worker.worker1.type=ajp13
Protokoll-Typ des AJP-Protokolls
JkWorkerProperty worker.worker1.host=127.0.0.1
IP-Adresse des Apache Tomcat-Servers
JkWorkerProperty worker.worker1.port=8099
AJP-Port des Apache Tomcat-Servers agbeändert !!!
/etc/httpd/conf.d/vhost.conf
Falls kein virtueller Host definiert ist, können folgende Konfigurationsangaben ebenfalls in der Datei /etc/httpd/conf/httpd.conf
definiert werden.
Nachfolgend ein Beispiel für einen virtuellen Host:
# # tomcat.tachtler.net (Apache Tomcat Applications) # <VirtualHost *:80> ServerAdmin webmaster@tachtler.net ServerName tomcat.tachtler.net ServerAlias www.tomcat.tachtler.net ServerPath / DocumentRoot "/usr/share/tomcat/webapps/ROOT" <Directory "/usr/share/tomcat/webapps/ROOT"> Options -Indexes +FollowSymLinks # Tachtler (enable for .htaccess file support) # AllowOverride AuthConfig AllowOverride None # Tachtler (enable for unlimited access) Require all granted </Directory> # Protect META-INF-Directory <Directory "/var/lib/tomcat/webapps/ROOT/META-INF"> AllowOverride None Require all denied </Directory> # Protect WEB-INF-Directory <Directory "/var/lib/tomcat/webapps/ROOT/WEB-INF"> AllowOverride None Require all denied </Directory> JkMount /*.action worker1 JkMount /*.jsp worker1 DirectoryIndex index.htm index.jsp ErrorLog logs/tomcat_error.log SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded CustomLog logs/tomcat_access.log combined env=!forwarded CustomLog logs/tomcat_access.log combined_proxypass env=forwarded </VirtualHost>
* Dies ist nur eine Beispielkonfiguration.
Die Bedeutung der einzelnen Befehle kann in der Dokumentation Apache Module mod_proxy detailliert nachgelesen werden.
JkMount /*.action worker1
JkMount /*.jsp worker1
Die erste Zeile, weist den Apache HTTP Webserver alle angeforderten Seiten mit der Endung .action
an den Apache Tomcat zur Erstellung weiterzuleiten. Die ist z.B. bei Nutzung des Apache Struts Frameworks der Fall.
Die zweite Zeile, weist den Apache HTTP Webserver alle angeforderten Seiten mit der Endung .jsp
an den Apache Tomcat zur Erstellung weiterzuleiten.
Beispiel
Falls nun folgende einfache *.jsp-Datei mit dem Namen - date.jsp
- in den hier angegebenen DocumentRoot
erstellt wird
/usr/share/tomcat/webapps/ROOT/date.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>JSP-Testseite</title> </head> <body> <font style="font-family: arial; font-size: 0.8em"><%=new java.util.Date()%></font> </body> </html>
und diese wie folgt wie hier z.B. aufgerufen wird
sollte das aktuelle Datum und die aktuelle Uhrzeit, wie nachfolgend gezeigt, erscheinen: