Tuesday 26 April 2011

Secure /var/tmp and Resize /tmp

It should be done because some applications use /var/tmp as the temporary folder, and anything that's accessible by all, needs to be secured.

Rename it and create a symbolic link to /tmp:
# mv /var/tmp /var/tmp1

# ln -s /tmp /var/tmp

Copy the old data back:
# cp /var/tmpold/* /tmp/


Resize /tmp from 512MB to 2GB

It’s quite common for a cPanel server to need a larger /tmp partition.

cPanel, by default, creates a loopback device that mounts to /tmp. The default size is only 512MB. This is quite small, especially for shared systems.

Reasons /tmp might become full:

* MySQL operation or Repair requiring temporary space. Keep in mind the /tmp partition must be big enough to support the largest table size on your system. (8GB table would require 8+GB /tmp space)
* PHP sessions consuming space in /tmp
* Rogue scripts living in /tmp

To resize follow these steps:

** Note that this will stop MySQL and will cause service interruption. These commands will resize /tmp to 2GB. If you wish to resize to a greater or smaller size simply change 2048000 to your desired size in bytes.

/etc/init.d/chkservd stop
/etc/init.d/mysql stop
umount /var/tmp
umount /tmp
sed -i -e 's/512000/2048000/g' /scripts/securetmp
rm /usr/tmpDSK
/scripts/securetmp --auto
cd /tmp
ln -s /var/lib/mysql/mysql.sock
/etc/init.d/mysql start
/etc/init.d/chkservd start

If you receive errors stating that /tmp could not be unmounted simply run the following command to identify the PID (Process ID) still using /tmp

lsof /tmp

Next, kill all processes using /tmp using “kill –9

No comments:

Post a Comment