You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Vinu Vibhu Sobhana <vv...@gmail.com> on 2019/09/19 10:26:34 UTC

Configuring Tomcat Clustering Solution for Virtual-Hosts

Hai,

Iam having two Web Servers configured to run Tomcat8.5. My project
manager had assigned me to configure these Tomcat Web Servers in
cluster mode so that the sessions will be managed by the Tomcat
Cluster. The same had been done using tomcat references/documentation.
I have also configured a Hardware LB so that the VIP may balance the
request accessing the URL "http://<IP ADDRESS>/test".

But now he had asked to tweak the existing configuration so as to host
multiple application under domain-name basis. Upon verifying the
tomcat documentation, I understood that Host Manager feature of tomcat
can be used for such virtual hosting.

I had tried configuring Tomcat Cluster for Virtual-Hosts, but needs to
confirm whether my approach is correct. Please find my queries and
server.xml files listed below.

1. Do I need to configure Multiple Cluster class for each Virtual-Host
or a Single Cluster class is enough to manage all Virtual-Hosts.
2. While using the Hardware LB with "X-Forwarded-for" enabled, how can
I get the Client IPs listed in the log file using RemoteIpValve.
Should it also be configured Globally or per Virtual-Host basis.

My server.xml file for both the nodes are mentioned below for reference.

server.xml for node1
###################
<?xml version="1.0" encoding="UTF-8"?>
    <Server port="8105" shutdown="SHUTDOWN">
        <Listener
className="org.apache.catalina.startup.VersionLoggerListener" />
        <!-- <Listener
className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" /> -->
        <Listener
className="org.apache.catalina.core.JreMemoryLeakPreventionListener"
/>
        <Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
/>
        <Listener
className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"
/>
        <GlobalNamingResources>
            <Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database
that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
        </GlobalNamingResources>
        <Service name="Catalina">
            <Connector port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000" />
            <Connector port="8109" protocol="AJP/1.3" />
            <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm18">
                <Realm className="org.apache.catalina.realm.LockOutRealm">
                    <Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" /></Realm>
                <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
                    <Valve
className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t
&amp;quot;%r&amp;quot; %s %b" />
                </Host>
                <!-- ############################################
VIRTUAL HOST START
###############################################################################-->
                <Host name="newapps.com" appBase="app-dir"
unpackWARs="true" autoDeploy="true">
                    <Alias>www.newapps.com</Alias>

<!--################################################## TOMCAT
CLUSTERED  BEGIN ########################################### -->
                    <Cluster
className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8" channelStartOptions="3">
                        <Manager
className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false" notifyListenersOnReplication="true"
/>
                        <Channel
className="org.apache.catalina.tribes.group.GroupChannel">
                            <Receiver
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="node1" port="4000" autoBind="9" selectorTimeout="5000"
maxThreads="6" />
                            <Sender
className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                                <Transport
className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"
/>
                            </Sender>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
                                <Member
className="org.apache.catalina.tribes.membership.StaticMember"
port="4000" securePort="-1" host="node2" domain="app-dir"
uniqueId="{2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1}" />
                            </Interceptor>
                        </Channel>
                        <Valve
className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
                        <Valve
className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
                        <ClusterListener
className="org.apache.catalina.ha.session.ClusterSessionListener" />
                        <!--                        <Deployer
className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/usr/local/tomcat-cluster/tomcat1/temp/"
deployDir="/usr/local/tomcat-cluster/tomcat1/webapps/"
watchDir="/usr/local/tomcat-cluster/tomcat1/watchdir/"
watchEnabled="true" /> -->
                    </Cluster>

<!--################################################## TOMCAT
CLUSTERED END ########################################### -->
                    <!-- <Context path="" docBase="webapps" debug="0"
reloadable="true" /> -->
                    <Valve
className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="newapps.com_access_log" suffix=".txt" pattern="%h %l %u %t
&amp;quot;%r&amp;quot; %s %b" />
                </Host>
                <!-- ############################################
VIRTUAL HOST END
###############################################################################-->
            </Engine>
        </Service>
    </Server>
###################

server.xml for node2
###################
<?xml version="1.0" encoding="UTF-8"?>
    <Server port="8105" shutdown="SHUTDOWN">
        <Listener
className="org.apache.catalina.startup.VersionLoggerListener" />
        <!-- <Listener
className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" /> -->
        <Listener
className="org.apache.catalina.core.JreMemoryLeakPreventionListener"
/>
        <Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
/>
        <Listener
className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"
/>
        <GlobalNamingResources>
            <Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database
that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
        </GlobalNamingResources>
        <Service name="Catalina">
            <Connector port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000" />
            <Connector port="8109" protocol="AJP/1.3" />
            <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm19">
                <Realm className="org.apache.catalina.realm.LockOutRealm">
                    <Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" /></Realm>
                <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
                    <Valve
className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t
&amp;quot;%r&amp;quot; %s %b" />
                </Host>
                <!-- ############################################
VIRTUAL HOST START
###############################################################################-->
                <Host name="newapps.com" appBase="app-dir"
unpackWARs="true" autoDeploy="true">
                    <Alias>www.newapps.com</Alias>

<!--################################################## TOMCAT
CLUSTERED  BEGIN ########################################### -->
                    <Cluster
className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8" channelStartOptions="3">
                        <Manager
className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false" notifyListenersOnReplication="true"
/>
                        <Channel
className="org.apache.catalina.tribes.group.GroupChannel">
                            <Receiver
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="node2" port="4000" autoBind="9" selectorTimeout="5000"
maxThreads="6" />
                            <Sender
className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                                <Transport
className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"
/>
                            </Sender>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"
/>
                            <Interceptor
className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
                                <Member
className="org.apache.catalina.tribes.membership.StaticMember"
port="4000" securePort="-1" host="node1" domain="app-dir"
uniqueId="{2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1}" />
                            </Interceptor>
                        </Channel>
                        <Valve
className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
                        <Valve
className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
                        <ClusterListener
className="org.apache.catalina.ha.session.ClusterSessionListener" />
                        <!--                        <Deployer
className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/usr/local/tomcat-cluster/tomcat1/temp/"
deployDir="/usr/local/tomcat-cluster/tomcat1/webapps/"
watchDir="/usr/local/tomcat-cluster/tomcat1/watchdir/"
watchEnabled="true" /> -->
                    </Cluster>

<!--################################################## TOMCAT
CLUSTERED END ########################################### -->
                    <!-- <Context path="" docBase="webapps" debug="0"
reloadable="true" /> -->
                    <Valve
className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="newapps.com_access_log" suffix=".txt" pattern="%h %l %u %t
&amp;quot;%r&amp;quot; %s %b" />
                </Host>
                <!-- ############################################
VIRTUAL HOST END
###############################################################################-->
            </Engine>
        </Service>
    </Server>
###################

Thanks!
Vinu VS

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Configuring Tomcat Clustering Solution for Virtual-Hosts

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Vinu,

On 9/19/19 06:26, Vinu Vibhu Sobhana wrote:
> Hai,
>
> Iam having two Web Servers configured to run Tomcat8.5. My project
> manager had assigned me to configure these Tomcat Web Servers in
> cluster mode so that the sessions will be managed by the Tomcat
> Cluster. The same had been done using tomcat
> references/documentation. I have also configured a Hardware LB so
> that the VIP may balance the request accessing the URL "http://<IP
> ADDRESS>/test".
>
> But now he had asked to tweak the existing configuration so as to
> host multiple application under domain-name basis. Upon verifying
> the tomcat documentation, I understood that Host Manager feature of
> tomcat can be used for such virtual hosting.

You can configure virtual hosting merely by configuring several <Host>
entries in conf/server.xml. Ths host manager may not be necessary.

> I had tried configuring Tomcat Cluster for Virtual-Hosts, but needs
> to confirm whether my approach is correct. Please find my queries
> and server.xml files listed below.
>
> 1. Do I need to configure Multiple Cluster class for each
> Virtual-Host or a Single Cluster class is enough to manage all
> Virtual-Hosts.

A single cluster can be configured in conf/server.xml that will cover
all virtual hosts in an <Engine> if you make sure to configure the
<Cluster> as a child of the <Engine> element. If you'd like separate
<Cluster> configurations for each virtual host, you may configure
sepearate <Cluster> elements as child elements of each <Host> element.

> 2. While using the Hardware LB with "X-Forwarded-for" enabled, how
> can I get the Client IPs listed in the log file using
> RemoteIpValve.

You will want to enable the RemoteIPValve. You can read about it here:
http://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Remote_IP_Valv
e

> Should it also be configured Globally or per Virtual-Host basis.

That's up to you. If you intend to use your LB for all virtual hosts
(which is usually a good idea for HA), then configure it globally.

> My server.xml file for both the nodes are mentioned below for
> reference.
>
> server.xml for node1 ################### <?xml version="1.0"
> encoding="UTF-8"?> <Server port="8105" shutdown="SHUTDOWN"> [snip]
> <Service name="Catalina"> <snip> <Engine name="Catalina"
> defaultHost="localhost" jvmRoute="jvm18"> <Host name="localhost"
> appBase="webapps" unpackWARs="true" autoDeploy="true"> [snip] <!--
> ############################################ VIRTUAL HOST START
> ######################################################################
#########-->

Note
>
that the first (default) <Host> is also a VirtualHost.

> <Host name="newapps.com" appBase="app-dir" unpackWARs="true"
> autoDeploy="true"> <Alias>www.newapps.com</Alias>
>
> <!--################################################## TOMCAT
> CLUSTERED  BEGIN ########################################### -->
> <Cluster

This will define a host-specific cluster. If you want the same cluster
to handle all virtual hosts, then define it one level higher, under
<Engine>.

You may want to consider using HTTPS internally on your network
instead of (plaintext) HTTP, and you may also want to consider
enabling the EncryptionInterceptor for your cluster. That way, none of
your internal communications are in the clear vulnerable to
interception or modification within your network.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl2I5QwACgkQHPApP6U8
pFirtw//S3kxxhokYuOEG/434ZMnsV9U3WiOhjt1l7eJoyIqloBeHwca62Irj2mA
Pq8FliTJBJYtwCnsK6BLZj9xrnaLJpEf4iVYhkV5ICq6M3ZLJrYzHnuPApn3KlaO
6/9M2+sSQb978Tao1Wy8KNdIFwqP6KRcA/HuPwEwZR987EtGSRgglh3limyFmif1
ZXiz/Vy0+FyjrUhMmhF/2oaWVQ5grKIJ3kvRewYbUxFvGFe0z5i9rlMQnW3rvG/H
mGWNYosXMTBdqzbT5mB182xRNU2Fwv2oxIAZCf0Ucnruap61BqxmdLx/DV2u+5rp
D+teQ78BvJUlWg0Zumo7wYQgFHV3RVoVI7q4for12FJo+VewSkCjBU/A21A5sQA9
z9HBKShZZCCNQoy7p4KKoI6NOAOK9+EZUSCrf/KpsmU3ujHt1Nj5W9ia49Xor1gC
4Gd9QBsg+M1MF7oPM69vjYJnwq6TWLK47bHPGd+B9FD1N8FBLUs1A6dzdXnE5gsa
XWsRianozQGBriZv9HuE7IidhZYYPQuXu6O/pq/w0uQwA9ivKcFi+stayd5MjeCq
vQLfgkSbj32vclU0YtUYy3TqLY6WZQQFP89UB1T9HH+KbFwRin+kPzRBZ+9pPmnN
P2NRCUMISdRqbItBaa9Jf5NQ2at+WXsZm/+STKlWhmSqyO2CEJY=
=Knre
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org