Configuration of open file limit in Apache Tomcat 8 on ubuntu 20.04 LTS

 

In Linux, there are limits characterized by the framework for whatever burns-through assets. For instance, there are limits on the number of contentions can be passed to a specific order, the number of strings can run simultaneously, and so forth.

 

In this post, We will configure or increase the open file limit for apache tomcat 8 on ubuntu 20.04 LTS 

 

Step 1:- Get Maximum System Capability

 

First sysAdmin need to check maximum capability of system, Use the following command for the same.
 

cat /proc/sys/fs/file-max


You should get output like this.


708444

 

Step 2:- Get Available Limit

 

Now need to verify available limit by using following commands, Use the following command for the same.

ulimit -n


You should get output like tihs.

1024


 

Step 3 :- Increase the Available Limit

 

To increase the available limit to say 200000 use the following commands.

sudo vim /etc/sysctl.conf


 

add the following line to it

fs.file-max = 200000


 

Step 4 :-Refresh the New Config

 

Need to  run this to refresh with new config, Use the following command for the same.

sudo sysctl -p


 

Step 5 :- Configure the limits.conf file

 

Now need to edit the following file, Use the following command.

sudo vim /etc/security/limits.conf


 

add following lines to it

# End of file
*               soft    nofile          120000
*               hard    nofile          120000
*               soft    nproc           120000
*               hard    nproc           120000

Save and exit
 

Step 6 :- Configure the pam.d/common-session config file

 

Now need to edit the following file sudo vim /etc/pam.d/common-session

sudo vim /etc/pam.d/common-session

# add this line to it

session required pam_limits.so

Step 7 :- Logout and Login

 

Now need to  logout and login and try the following command to get effects.

ulimit -n


You should get value like this 200000

After configure ulimit in system, We need to configure tomcat for open files limit by following the steps,

Step 8:- Get PID of Tomcat 

 

Need to check PID of tomcat by following the commands

sudo systemctl status tomcat.service

 

Now you should see like this output grep the tomcat service main process ID

Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-02-25 14:59:53 IST; 31min ago
  Process: 26977 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=0/SUCCESS)
  Process: 27041 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 27049 (java)
   CGroup: /system.slice/tomcat.service
           └─27049 /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin/java -Djava.util.logging.config.file=/opt/tomca

Feb 25 14:59:53 

Step 9:- Get Open File Limit

 

Now you need to see open files limits by tomcat process id like this :–

cat /proc/<processId>/limits

Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             47597                47597                processes
Max open files            8192                 8192                 files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       47597                47597                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        

Step 10:- Increase the Tomcat’s Open file limit

 

Now if you want to change open files limit of tomcat web server you need to edit the tomcat’s service file located in vim /etc/systemd/system/tomcat.service

sudo vim /etc/systemd/system/tomcat.service

Open and add lines after [Services] like this

[Service]
LimitNOFILE=8192

The completed example is given below:--
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
LimitNOFILE=10192
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh


User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Save and Exit
 

Step 12:- Restart the Tomcat Service


To get effects on tomcat services you need to restart the tomcat service but before that you must have to reload the daemons by using the given commands:–

sudo systemctl daemon-reload
sudo systemctl restart tomcat.service
sudo systemctl status tomcat.service


 

To  get again status of tomcat open files limit use the given commands with new tomcat PID 


cat /proc/8005/limits


Now you should get output like that :–

Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             47597                47597                processes
Max open files            100000               100000               files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       47597                47597                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us   



 

 

 

 

Configuration of open file limit in Apache Tomcat 8 on ubuntu 20.04 LTS

One thought on “Configuration of open file limit in Apache Tomcat 8 on ubuntu 20.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top