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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to