Successfully!

Error!

Tomcat Port Configuration

  • Author:ayuan0625
  • Recent Updates:ayuan0625 on 2020-12-14
  • I. Configure a port for Tomcat

    1. Usage scenarios

    Ports are endpoints for communication between applications and the outside world. On a server, each application needs an independent port to ensure normal communication. Ports are distinguished from each other by port numbers and port configuration is to assign a unique port number to an application.

    1) The default port number of Tomcat is 8080. On a server, if another application occupies port 8080, Tomcat will fail to be started normally, in which case you have to configure a new port for Tomcat.

    2) If a number of Tomcats run on a server, then you have to configure a separate port for each Tomcat.


    2. Configure a port when there is only one Tomcat on a server 

    To modify the port number of Tomcat, you just need to modify %tomcat_home%\conf\server.xml.

    For instance, to modify the port number to 8081, you can open server.xml with the text editor, find the label Connector and modify the port attribute value to “8081”:

    <Connector port="8081" 

    protocol="HTTP/1.1"

    connectionTimeout="20000"               

    redirectPort="8443" />

    If the port number is modified to 80, then the port number can be omitted when accessing Tomcat; in other words, directly input http://localhost in the browser to jump to the welcome screen of Tomcat.


    3. Configure ports when there are multiple Tomcats on a server 

    Suppose there are two Tomcats on a server and one of the Tomcats uses the default port number 8080. To allow the two Tomcats to run normally, you have to configure a new port for the second Tomcat.

    First of all, find the folder conf under the installation root of the second Tomcat, and then open server.xml in the folder with the text editor. The following should be modified:

    1) HTTP port, which is by default numbered 8080. Modify it to 8081:

    <Connector port="8081" protocol="HTTP/1.1"connectionTimeout="20000" redirectPort="8443" />

    2) Close the Tomcat server port, which is by default numbered 8005. Modify it to 8006:

    <Server port="8006" shutdown="SHUTDOWN">

    3) AJP port, which is by default numbered 8009. Modify it to 8010:

    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

    Save server.xml and restart the second Tomcat. The two Tomcats can work simultaneously.

    II. Modify Tomcat’s memory configuration

    1. Usage scenarios

    After FineReport is deployed into Tomcat, the report project has to execute calculation of reports when you preview reports or click Query, with intermediate data in such calculation stored temporarily in server memory, so the report project occupies server memory when it is running. If no memory is available, an out-of-memory error will occur: java.lang.OutOfMemoryError:Java heap space

    In making a report, if a large amount of data is called in the template or there is a lag in the preview of the template, you have to make more server memory available to the Tomcat where FineReport runs, which can be realized by modifying Tomcat’s memory configuration.

    To modify Tomcat’s memory configuration, you have to set two values: initial memory and maximum memory. The initial memory determines the memory available to Tomcat at the initial stage, while the maximum memory determines the maximum memory available to Tomcat when it is running. If the size of the data temporarily stored when the report project is running exceeds that of this maximum memory, an out-of-memory error will be triggered.

    This article will introduce how to modify Tomcat’s memory configuration in detail. There are two versions of Tomcat, namely the unzipped version and the installed version, which are slightly different in the way of modification.


    2. Adjust the memory size of unzipped Tomcat

    1) Start Tomcat via startup.bat or startup.sh

    2) Under Windows operating system, modify JAVA_OPTS (here we take Windows10+Tomcat8+JDK1.8.0 for example, and note that different versions may vary slightly). Locate %Tomcat_Home%/bin/catalina.bat and add the following script:

    set JAVA_OPTS= -Xms512M -Xmx2048M

    -Xms: java Heap initial memory, which is by default 1/64 of the physical memory.

    -Xmx: java heap maximum memory, which, for Tomcat, should be no more than 80% of the physical memory.

    Following the settings above, the initial memory is 512MB while the available maximum memory is 2048MB. The size must be in MB (if not, then the default unit in the system is KB). Specific settings are shown in the figure below:

    1.png

    Save the file after modification and restart Tomcat to effect these settings.

    3) When registering the Tomcat initiator as Windows services, the Xms and Xmx sizes of JVM should be modified:

    set JAVA_OPTS= -Xms512M -Xmx1024M

    4) On Linux (here we take Centos6.5+Tomcat8+JDK1.8.0 for example, and note that different versions may vary slightly), locate %Tomcat_Home%/bin/catalina.sh and add the following script:

    JAVA_OPTS="$JAVA_OPTS -Xms2048M -Xmx8196M"

    See the figure below:

    2.png

    After modification, restart Tomcat to effect these settings.


    3. Adjust the memory size of installed Tomcat 

    For the installed version, take Windows10+Tomcat8+JDK1.8.0 for example (please note that different versions vary slightly).

    Double-click the system tray of Tomcat at the lower-right corner of the screen, click the [Java] tab and modify [Initial Memory Pool] and [Maximum Memory Pool]. The former is the initial memory while the latter is the maximum memory, which should not exceed 80% of the physical memory. See the figure below:

    3.png

    After modification, restart Tomcat to for settings to take effect.

    Note

    • If the settings above do not take effect, please modify the content of Option in the registry after installing as services by reference to the case of unzipped Tomcat.


    4. Check Tomcat’s memory usage 

    Here we take the installed Tomcat and Windows10+Tomcat8.5+JDK1.8.0 for example (please note that different versions may vary slightly). 

    1) Add a user 

    Open the file %Tomcat_Home%/conf/tomcat-users.xml and add a new user to the label tomcat-users. The specific code is as follows:

    <role rolename="manager-gui"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>

    4.png

    2) Enter the graphical interface to modify memory configuration

    Access IP:port/manager/status, the example in this article is http://localhost:8080/manager/status, input the new username and password, here the example is tomcat/s3cret.

    After entering the Server Status page, the following parameters can be seen in the JVM form:

    Free memory: free memory at present;

    Total memory: the total memory at present;

    Max memory: the maximum memory available.

    See the figure below:

    5.png

    Note

    • If java.lang.OutOfMemoryError: PermGen space occurs, you can add a command statement -XX:MaxPermSize=256m wherever the memory is modified to limit the memory size.

    • All figures used in the adjustment of memory should be in line with the amount of data in a user’s system.

    III. Deploy the report project outside Tomcat 

    1. Use scenarios

    A common deployment operation is to place files in the report project into Tomcat. In order to easily manage files on the server, some users have to put the report project in a particular place.

    In fact, even if the report project is not located in Tomcat, you can still realize deployment as long as you configure Tomcat to enable it to read files in the report project.


    2. Preparations

    Place the report project outside Tomcat.

    The directory of the report project: D:\FineReport_10.0\webapps\webroot 

    The directory of Tomcat: D:\apache-tomcat-8.5.27 


    3. Configure the report project

    Create a new file FR.xml (FR is the application name of the report project as an application) under D:\apache-tomcat-8.5.27\conf\Catalina\localhost. Open FR.xml with the text editor, input the following in the file and then save the file:

    <Context path="/FR" reloadable="false" docBase="D:\FineReport_10.0\webapps\webroot" />

    6.png

    Note

    • The value of the path attribute must be the same as the file name.

    • If conf contains no folder named Catalina, just create a new folder so named.


      4. Check if the deployment is successful 

      Restart Tomcat, run the browser and input the following in the address bar:  http://ip:server port number/FR/decision 

      Where, FR is the report application name defined at deployment. If you can see the administrator setup page, then FineReport has been successfully deployed to Tomcat.

      7.png


      Attachment List


      Theme: Deployment and Integration
      Already the First
      Already the Last
      • Helpful
      • Not helpful
      • Only read

      Doc Feedback