Fixing “Too many open files” error

Often we get “org.apache.tomcat.jni.Error: 24: Too many open files” errors on Apache Tomcat. If this happened then the process will wait for 3 minutes in open state and will fail after that. It can be fixed by increasing the Open file limits on OS limits. By default CentOS is set with 1024 limit.

1. Edit the file /etc/security/limits.conf and add the following lines

*       soft    nofile  8192
*       hard    nofile  65535

2. Edit the file /etc/pam.d/login and add the following lines

session required /lib/security/

3. Check the limit again by logoff and login

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 119859
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 8192
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 119859
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Here we can see the open files is set to 8192 which should be enough but it is best practice to check the open file with lsof and adjust as per requirements.

Hard Disk Performance Testing

To check read speed you can use the following command

hdparm -Tt /dev/sda1

 Timing cached reads:   25292 MB in  2.00 seconds = 12664.26 MB/sec
 Timing buffered disk reads: 432 MB in  3.01 seconds = 143.56 MB/sec

Here 12664.26 MB/sec & 143.56 MB/sec are the read speeds.

DD command will give the write speed of hard drives

dd if=/dev/zero of=/tmp/output bs=1024 count=4096k conv=fdatasync; rm -f /tmp/output
4194304+0 records in
4194304+0 records out
4294967296 bytes (4.3 GB) copied, 165.193 s, 26.0 MB/s

Here 26.0 MB/s is the write speed.

Hope this helps!

Ubuntu Passwordless and Public Key Authentication

1. Need to generate a local public key file from client machine

# ssh-keygen -t dsa 

( from client machine)

2. Copy the file to the server

# scp ~/.ssh/

3. Login to the server and add the key to authorized_keys file

# cat >> .ssh/authorized_keys

4. Delete the original file you copied

# rm -r

All done, now just ssh to the server. It will login without the password.

Note : Passwordless authentication is a big security risk.

Tomcat Native Library (APR)– Installation on CentOS

Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies.

You will see this info often on catalina.out if you dont have the tomcat native library not installed on servers.

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_23/jre/lib/amd64/server:/usr/local/jdk1.6.0_23/jre/lib/amd64:/usr/local/jdk1.6.0_23/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

to get rid of this we need to install apr utilities and tomcat native library. Lets see how to install on CentOS 5.4-X86_64

yum install apr.x86_64 apr-devel.x86_64 -y

We installed apr utilities, now we need to install tomcat native libraries Continue reading Tomcat Native Library (APR)– Installation on CentOS

Setting up internal Bind DNS for Zimbra mail server on Amazon EC2 CentOS & RHEL Servers

Zimbra Collaboration server needs to resolve MX records of a domain while installing. Amazon EC2 instances are behind NAT so we need to have an working internal DNS server to do the MX resolution.

1. Install Bind

yum install bind9 -y

2. Add required changes on bind configuration file. Need to change forwarder and add zone for the domain.

vi /etc/named.conf

Find and replace the forwarders with the below (it is a google DNS servers we are using)

forwarders {; };

Add zone information in named.conf (replace with your domain) Continue reading Setting up internal Bind DNS for Zimbra mail server on Amazon EC2 CentOS & RHEL Servers

Add swap on CentOS and Ubuntu Linux

1. Create a swap file.

dd if=/dev/zero of=/mnt/swapfile bs=1024 count=4096k

This will create a 4GB of swap file which can be used for 8GB server.

2. Change the file to swap partition.

mkswap /mnt/swapfile

3. Enable swap

swapon /mnt/swapfile

4. Verify swap partition.

swapon -s

NOTE: All the above operations need to be done with a sudo user or by root.

Zimbra & Sendgrid SMTP Setup

All the operations need to be done as a Zimbra user.

1. Point a domain to an SMTP server

zmprov ms zimbraMtaRelayHost

2. Add SMTP authentication for smtp relay server

echo username:password > /opt/zimbra/conf/relay_password

3. Export it to postfix

postmap hash:/opt/zimbra/conf/relay_password

4. Check the credentials are saved properly

postmap -q /opt/zimbra/conf/relay_password

5. Setup SASL to use smtp relay authentication Continue reading Zimbra & Sendgrid SMTP Setup

PHP Compilation for Litespeed Webserver

Litespeed web server doesn’t come with all PHP modules, we need to compile PHP from source to add any new (or) third-party modules to PHP.

When the Litespeed installation is done, we can compile php and add the new php as a module.

1. Download the desired php version we need from Here we are picking latest stable 5.3.20 version.

tar -zxf php-5.3.20.tar.gz

2. Change the directory to sapi

cd php-5.3.20/sapi

3. We need to download latest litespeed module for php. (PHP 5.3.x comes with litespeed 4.x module but we are picking latest module from here )

rm -rf litespeed
tar -zxf php-litespeed-6.1.tgz

Continue reading PHP Compilation for Litespeed Webserver

Installing Microsoft Core fonts on CentOS 6

Microsoft fonts installation requires chkfontpath binary. It can be installed with all the dependencies by using atrpms.

1. Install atrpms repository

rpm -ivh

2. Install chkfontpath

yum install chkfontpath -y

3. Download bundled font rpm file
Continue reading Installing Microsoft Core fonts on CentOS 6