CD part IV: Create multiple tomcat instances

Johan Tuitel

  • 02/12/2016
  • 5 minuten leestijd
Johan Tuitel

CD part IV: Create multiple tomcat instances

tomcat is the application server i have used for this blog, but you can use other application servers. In this part i will describe the steps i have done to create multiple instances to create 4 servers!

source: https://www.youtube.com/watch?v=eJjzD8tCwFI

  1. we need to download tomcat
  2. go to: https://tomcat.apache.org/download-70.cgi
  3. navigate to the core section
  4. click on the 64-bit Windows zip to download
  5. copy the apache-tomcat-7.0.68-windows-x64.zip file to c:\tools folder
  6. extract the zip-file to C:\tools\apache-maven-3.3.9
  7. you probably have the next folder structure: C:\tools\apache-tomcat-7.0.68\apache-tomcat-7.0.68
  8. we want to create the next structure: C:\tools\apache-tomcat-7.0.68

tomcat configuration

  1. open Configurationscreen > System > Advanced System Settings > Environment Variables
  2. create a variable under the Systemvariables called CATALINA_HOME
  3. name: CATALINA_HOME
  4. value: C:\tools\apache-maven-3.3.9
  5. new we have to adjust the path variable
  6. add %CATALINA_HOME%\bin; in the beginning of the variable value

delete tomcat folders

  1. delete the work folder
  2. delete all files in the webapps folder, except the manager folder
  3. delete all files in the temp folder

create multiple instances

  1. copy: conf, temp and webapps folders
  2. create a tomcatwebserviced folder under the c:\tools map
  3. paste the copied folders into this folder.
  4. create a test folder in the webapps folder
  5. create an index.html file in the test map
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>tomcat instance 1</title>
        </head>
        <body>
            <h1>Hello from tomcat 1</h1>
        </body>
    </html>
  1. copy tomcatwebserviced and paste and call it tomcatwebservicet
  2. edit the index.html and make it: tomcat 2
  3. copy tomcatwebserviced and paste and call it tomcatwebappd
  4. edit the index.html and make it: tomcat 3
  5. copy tomcatwebappd and paste and call it tomcatwebappt
  6. edit the index.html and make it: tomcat 4
  7. copy tomcatwebappd and paste and call it tomcat_jenkins
  8. edit the index.html and make it: tomcat 4
  9. now we are going to change the server.xml
  10. go to the conf folder and edit the server.xml file
  11. tomcatwebserviced
    1. server port: 8006
    2. connector port: 8071
    3. AJP connector: 8010
  12. tomcatwebservicet
    1. server port: 8007
    2. connector port: 8072
    3. AJP connector: 8011
  13. tomcatwebappd
    1. server port: 8008
    2. connector port: 8073
    3. AJP connector: 8012
  14. tomcatwebappt
    1. server port: 8009
    2. connector port: 8074
    3. AJP connector: 8013
  15. tomcat_jenkins
    1. server port: 8010
    2. connector port: 8075
    3. AJP connector: 8014
  16. after the configuration of the server.xml, we are going to config the users per server.
  17. Open the tomcat-users.xml in the C:\tools\tomcatwebserviced\conf folder and edit the content
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="johan" password="troposphere" roles="manager-gui,manager-script"/>
    </tomcat-users>
  1. Open the tomcat-users.xml in the C:\tools\tomcatwebservicet\conf folder and edit the content
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="david" password="oriental" roles="manager-gui,manager-script"/>
    </tomcat-users>
  1. Open the tomcat-users.xml in the C:\tools\tomcatwebappd\conf folder and edit the content
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="max" password="voyager" roles="manager-gui,manager-script"/>
    </tomcat-users>
  1. Open the tomcat-users.xml in the C:\tools\tomcatwebappt\conf folder and edit the content
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="elliot" password="feedom" roles="manager-gui,manager-script"/>
    </tomcat-users>
  1. Open the tomcat-users.xml in the C:\tools\tomcat_jenkins\conf folder and edit the content
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="elliot" password="feedom" roles="manager-gui,manager-script"/>
    </tomcat-users>
  1. finally we are creating the start en stop scripts of the tomcat instances
  2. create a folder tomcat-scripts, which get the structure: C:\tools\tomcat-scripts
  3. create a file tomcat 1 - start.cmd
    @echo off
    SET CATALINA_BASE=C:\tools\tomcat_webservice_d
    cd "%CATALINA_HOME%\bin"
    SET TITLE=Tomcat 01
    CALL startup.bat %TITLE%
  1. create a file tomcat 1 - shutdown.cmd
    @echo off
    SET CATALINA_BASE=C:\tools\tomcat_webservice_d
    cd "%CATALINA_HOME%\bin"
    CALL shutdown.bat %TITLE%
  1. repeat step 26 and 27 for tomcatwebservicet, tomcatwebappd, tomcatwebappt and tomcat_jenkins
  2. set the context files open context.xml-file in the conf folder and set the context:
  3. you could test it by double click the start.cmd files and shutdown.cmd files

tomcat scripts

add servers to the maven configurations

  1. configure settings.xml
  2. navigate to C:\tools\apache-maven-3.3.9\conf and open settings.xml
  3. added the next to the server settings
    <servers>
    <!-- Development environment Tomcat instance for the webservices -->
        <server>
            <id>WebServiceDevelop</id>
            <username>johan</username>
            <password>troposphere</password>
        </server>
        <!-- Test environment Tomcat instance for the webservices -->
        <server>
            <id>WebServiceTest</id>
            <username>david</username>
            <password>oriental</password>
        </server>
        <!-- Development environment Tomcat instance for the webapplication -->
        <server>
            <id>WebAppDevelop</id>
            <username>max</username>
            <password>voyager</password>
        </server>
        <!-- Test environment Tomcat instance for the webapplication -->
        <server>
            <id>WebAppTest</id>
            <username>elliot</username>
            <password>feedom</password>
        </server>
    </servers>

Web Application Development

Web Application Test

Web Services Development

Web Services Test