Что-то нигде не могу найти документации на русском, да и на английском не очень густо..
Я с апачем да томкатом не знаком можно скзать, как я понимаю связка апача и томкачата через mod_proxy_ajp настраивается так же как и через mod_jk или есть различия?
Дистр - SLES10SP1, апач (2.2.3) на одном сервере, томкат (5.5) на другом сервере.
Apache + Tomcat через mod_proxy_ajp (Натолкените на путь истинный..)
Модераторы: SLEDopit, Модераторы разделов
-
izen.fire
- Сообщения: 268
- ОС: Windows XP
Re: Apache + Tomcat через mod_proxy_ajp
Что вы хотите получить в итоге?
Tomcat это полноценный Web-сервер, который может обойтись без Apache.
Ротор поля наподобие дивергенции градуирует себя вдоль спина и там внутре ево неонка.
-
Atheist
- Сообщения: 63
Re: Apache + Tomcat через mod_proxy_ajp
Хочу получить вот такую схему:
сервер s1 - apache (Load Balancing)
сервера s2, s3, s4 - три сервера с томкатом в кластере (Clustering/Session Replication)
s5 - сервер БД
Кластер из трех томкатов (в тестовом варианте) сделал - судя по логам они друг друга видят, но не проверял еще.
А вот как зацепить апач к томкату да как настроить балансировку (как я понимаю это 2 разные задачи) пока не знаю.
Вроде как mod_proxy_balancer нужен для балансировки..
У вас нет необходимых прав для просмотра вложений в этом сообщении.
-
Atheist
- Сообщения: 63
Re: Apache + Tomcat через mod_proxy_ajp
Что-то с ответами тут не густо 
Разобрался как зацепить апач к томкату через mod_proxy_ajp:
/etc/apache2/conf.d/proxy_ajp.conf
Все, теперь набираем в браузере http://s1.mydomain.ru и попадаем на томкатовую страничку, расположенную по адресу http://s2.mydomain.ru:8080
Теперь осталось прикрутить к апачу балансировку нагрузки, чтобы запросы шли поочередно на s2-s3-s4 (если я верно понимаю) и проверить работатет ли кластер из томкатов.Никто не подскажет как?
Разобрался как зацепить апач к томкату через mod_proxy_ajp:
/etc/apache2/conf.d/proxy_ajp.conf
Код: Выделить всё
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://s2.mydomain.ru:8009/Все, теперь набираем в браузере http://s1.mydomain.ru и попадаем на томкатовую страничку, расположенную по адресу http://s2.mydomain.ru:8080
Теперь осталось прикрутить к апачу балансировку нагрузки, чтобы запросы шли поочередно на s2-s3-s4 (если я верно понимаю) и проверить работатет ли кластер из томкатов.Никто не подскажет как?
-
izen.fire
- Сообщения: 268
- ОС: Windows XP
Re: Apache + Tomcat через mod_proxy_ajp
The Apache Tomcat 5.5 Servlet/JSP Container
Load Balancer HOW-TO: http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html
The Apache Tomcat 5.5 Servlet/JSP Container
Clustering/Session Replication HOW-TO: http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
Load Balancer HOW-TO: http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html
The Apache Tomcat 5.5 Servlet/JSP Container
Clustering/Session Replication HOW-TO: http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
Ротор поля наподобие дивергенции градуирует себя вдоль спина и там внутре ево неонка.
-
Atheist
- Сообщения: 63
Re: Apache + Tomcat через mod_proxy_ajp
По ссылке что ты дал:
Только вот это:
Using Apache HTTP Server 2.x with mod_proxy
Please refer to the mod_proxy documentation for Apache HTTP Server 2.2. This supports either HTTP or AJP load balancing. This new version of mod_proxy is also useable with Apache HTTP Server 2.0, but mod_proxy will have to be compiled separately using the code from Apache HTTP Server 2.2.
Вот что есть в документации по mod_proxy:
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
По всем ссылкам одна теория, по конфигурирование ваще ниче нет..
Вместе с моит томкатом в СЛЕС10 идет документация, в ней написано:
Using Apache 2 with mod_proxy and mod_rewrite
It is possible to use Apache 2, with mod_proxy and mod_rewrite, to load balance requests to a set of Tomcat servers, using the HTTP protocol rather than AJP. Although it does not have any advanced load balancing or failover strategies, it is very easy to setup.
Configuring Tomcat
Edit $CATALINA_HOME/conf/server.xml, and find the Engine element and add an attribute called jvmRoute. Set its value to LB1.
Do the same for each server in the group, giving each a different ID: LB2, LB3, ...
Apache 2 configuration
First we must create a rewrite map (for mod_rewrite) (balancing.conf):
This means each worker is associated with a specific server and port. The name associated with each node must match the one used for the jvmRoute attribute specified on the Engine element of each node's server.xml.
In httpd.conf:
The first entry means that we want to load the server map which we created. The "ALL" entry in the server map will affect those users who do not yet have a session ID. Meaning the session cookie which Tomcat creates will have the LBx id in it, the other entries will govern which host we're directed to.
The rewrite rules govern those users with a cookie. Apache will rewrite the URL and point you to one of the instances of Tomcat. This is vodoo but it should work.
Соответственно переписывю под себя:
/srv/www/tomcat5/base/conf/server.xml
Ну и на втором и третьем сервер с томкатом соответственно пишу LB2 LB3
/etc/apache2/servers.list
/etc/apache2/conf.d/balancing_rewrite.conf
В итоге как тока я выдергиваю хвост у s2.mydomain.ru апач мне показывает вот что:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Additionally, a 503 Service Temporarily Unavailable error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.3 (Linux/SUSE) Server at s1.mydomain.ru Port 80
Как я понимаю это из-за того что 1 - я не понимаю как работатет mod_rewrite 2 - в строке ProxyPass / ajp://s2.mydomain.ru:8009/ жестко задан сервер на который надо перебрасывать запрос.
The Apache Tomcat 5.5 Servlet/JSP Container
Load Balancer HOW-TO: http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html
Только вот это:
Using Apache HTTP Server 2.x with mod_proxy
Please refer to the mod_proxy documentation for Apache HTTP Server 2.2. This supports either HTTP or AJP load balancing. This new version of mod_proxy is also useable with Apache HTTP Server 2.0, but mod_proxy will have to be compiled separately using the code from Apache HTTP Server 2.2.
Вот что есть в документации по mod_proxy:
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
По всем ссылкам одна теория, по конфигурирование ваще ниче нет..
Вместе с моит томкатом в СЛЕС10 идет документация, в ней написано:
Using Apache 2 with mod_proxy and mod_rewrite
It is possible to use Apache 2, with mod_proxy and mod_rewrite, to load balance requests to a set of Tomcat servers, using the HTTP protocol rather than AJP. Although it does not have any advanced load balancing or failover strategies, it is very easy to setup.
Configuring Tomcat
Edit $CATALINA_HOME/conf/server.xml, and find the Engine element and add an attribute called jvmRoute. Set its value to LB1.
Код: Выделить всё
<Engine name="MainEngine" defaultHost="localhost" jvmRoute="LB1">Do the same for each server in the group, giving each a different ID: LB2, LB3, ...
Apache 2 configuration
First we must create a rewrite map (for mod_rewrite) (balancing.conf):
Код: Выделить всё
LB1 tomcat1.foo.com:8080
LB2 tomcat2.foo.com:8080
LB3 tomcat3.foo.com:8888
ALL tomcat1.foo.com:8080|tomcat2.foo.com:8080|tomcat3.foo.com:8888This means each worker is associated with a specific server and port. The name associated with each node must match the one used for the jvmRoute attribute specified on the Engine element of each node's server.xml.
In httpd.conf:
Код: Выделить всё
RewriteMap SERVERS rnd:/usr/local/httpd/conf/servers.conf
<Location /webapp>
RewriteEngine On
RewriteCond "%{HTTP_COOKIE}" "(^|;\s*)jsessionid=\w*\.(\w+)($|;)"
RewriteRule "(.*)" "http://${SERVERS:%2}%{REQUEST_URI}" [P,L]
RewriteRule "^.*;jsessionid=\w*\.(\w+)($|;)" "http://${SERVERS:$1}%{REQUEST_URI}" [P,L]
RewriteRule "(.*)" "http://${SERVERS:ALL}%{REQUEST_URI}" [P,L]
</Location>The first entry means that we want to load the server map which we created. The "ALL" entry in the server map will affect those users who do not yet have a session ID. Meaning the session cookie which Tomcat creates will have the LBx id in it, the other entries will govern which host we're directed to.
The rewrite rules govern those users with a cookie. Apache will rewrite the URL and point you to one of the instances of Tomcat. This is vodoo but it should work.
Соответственно переписывю под себя:
/srv/www/tomcat5/base/conf/server.xml
Код: Выделить всё
<Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="LB1">Ну и на втором и третьем сервер с томкатом соответственно пишу LB2 LB3
/etc/apache2/servers.list
Код: Выделить всё
LB1 s2.mydomain.ru:8080
LB2 s3.mydomain.ru:8080
LB3 s4.mydomain.ru:8080
ALL s2.mydomain.ru:8080|s3.mydomain.ru:8080|s4.mydomain.ru:8080s1/etc/apache2/conf.d/balancing_rewrite.conf
Код: Выделить всё
RewriteMap SERVERS rnd:/etc/apache2/servers.list
/etc/apache2/conf.d/balancing_rewrite.conf
<Location /webapp>
RewriteEngine On
RewriteCond "%{HTTP_COOKIE}" "(^|;\s*)jsessionid=\w*\.(\w+)($|;)"
RewriteRule "(.*)" "http://${SERVERS:%2}%{REQUEST_URI}" [P,L]
RewriteRule "^.*;jsessionid=\w*\.(\w+)($|;)" "http://${SERVERS:$1}%{REQUEST_URI}" [P,L]
RewriteRule "(.*)" "http://${SERVERS:ALL}%{REQUEST_URI}" [P,L]
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>В итоге как тока я выдергиваю хвост у s2.mydomain.ru апач мне показывает вот что:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Additionally, a 503 Service Temporarily Unavailable error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.3 (Linux/SUSE) Server at s1.mydomain.ru Port 80
Как я понимаю это из-за того что 1 - я не понимаю как работатет mod_rewrite 2 - в строке ProxyPass / ajp://s2.mydomain.ru:8009/ жестко задан сервер на который надо перебрасывать запрос.
-
Atheist
- Сообщения: 63
Re: Apache + Tomcat через mod_proxy_ajp
Почитал еще доки и вот что получается:
Удаляем все что я до этого делал и пишем в /etc/apache2/conf.d/tomcatbinding.conf
Вроде работает, осталось еще подкрутить разные опции...
Удаляем все что я до этого делал и пишем в /etc/apache2/conf.d/tomcatbinding.conf
Код: Выделить всё
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / balancer://tomcatcluster/ stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://tomcatcluster>
BalancerMember ajp://s2.mydomain.ru:8009
BalancerMember ajp://s3.mydomain.ru:8009
BalancerMember ajp://s4.mydomain.ru:8009
</Proxy>Вроде работает, осталось еще подкрутить разные опции...