Skip to content


Extending Swap on a LVM System

Lets say you currently have 128GB of hard drive space and you wish to allocate 16GB of space to swap but you do not have the available space.  Let’s take this step further and say this is a VM and 16GB has been allocated to this VM.  Here are the steps you would take.

Example:

[root@host]# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 257008+ 83 Linux
/dev/sda2 33 15665 125572072+ 8e Linux LVM

1.  Rescan the bus do fdisk will see the new drive space allocated:

#  sudo echo 1 > /sys/block/sdd/device/rescan

You will now see:

[root@host]# fdisk -l
Disk /dev/sda: 146.0 GB, 146028888064 bytes
255 heads, 63 sectors/track, 17753 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 257008+ 83 Linux
/dev/sda2 33 15665 125572072+ 8e Linux LVM

2.  You will now use fdisk to create a new partition using the free 16GB of space:

[root@host]# fdisk -l
Disk /dev/sda: 146.0 GB, 146028888064 bytes
255 heads, 63 sectors/track, 17753 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 257008+ 83 Linux
/dev/sda2 33 15665 125572072+ 8e Linux LVM
/dev/sda3 15666 17753 16771860 8e Linux LVM

3.  You will now use pvcreate to create the physical volume:

#  root@host]# pvcreate /dev/sda3
 Writing physical volume data to disk "/dev/sda3"
 Physical volume "/dev/sda3" successfully created

4.  You will now extend the volume group:

#  root@host]# vgextend vglocal20130501 /dev/sda3
 Volume group "vglocal20130501" successfully extended

5.  You will now turn swap off with the command:

#  swapoff -a

6.  You will now resize the logical volume:

#  [root@host]# lvresize -l +100%FREE /dev/vgname/swap00
 Extending logical volume swap00 to 17.97 GB
 Logical volume swap00 successfully resized

7.  You will now make swap:

#  [root@host]# mkswap /dev/vgname/swap00
Setting up swapspace version 1, size = 19293794 kB

8.  You will now turn on swap using:

#  swapon -a

9.  You can now see we have increased swap:

#  [root@host]# free -m
 total used free shared buffers cached
Mem: 7980 5140 2840 0 112 4743
-/+ buffers/cache: 284 7695
Swap: 18399 0 18399

 

 

Posted in Command Line.


Linux – Command Line – Finding out what processes are using swap

If you wish to know how much each process is using in regards to swap you can use the following command:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

Posted in Command Line.


php-APC Base config settings

Here is a good starting config for php-apc.  You will place this in /etc/php.d/apc.ini:

extension=apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 1024M
apc.num_files_hint = 1000000
apc.user_entries_hint = 1024
apc.ttl = 3600
apc.user_ttl = 7200
apc.gc_ttl = 3600
apc.cache_by_default = 1
apc.filters = "apc\.php$"
apc.mmap_file_mask = "/tmp/apc.XXXXXX"
apc.slam_defense = 0
apc.file_update_protection = 2
apc.enable_cli = 0
apc.max_file_size = 1M
apc.use_request_time = 1
apc.stat = 1
apc.write_lock = 1
apc.report_autofilter = 0
apc.include_once_override = 0
apc.localcache = 0
apc.localcache.size = 256M
apc.coredump_unmap = 0
apc.stat_ctime = 0
apc.canonicalize = 1
apc.lazy_functions = 0
apc.lazy_classes = 0

Posted in Apache, PHP.


MySQL – TimeZone

If you wish to find out if MySQL is using the system time you may verify with the following command:

#  mysql -e "SELECT @@global.time_zone;"

Find current time:

#  mysql -e "SELECT NOW();"

Posted in MySQL.


Plesk – ProFTPd – Slow login/response

If you find yourself having issues with Plesk and proftpd, such as a banner delay or user credential input delay, even when testing locally.  I recommend adding the following to /etc/proftpd.conf

UseIPv6 Off

and restarting xinit.d.

Posted in ProFTP.


Apache – DDOS Mitigation – SlowLoris

If your Apache web server is under a SlowLoris Attack you can mitigate it by installing the following module:

1.  #  cd /usr/local/src
2.  #  wget http://sourceforge.net/projects/mod-antiloris/files/mod_antiloris-0.4.tar.bz2 note: there may be a newer version.

3.  Make sure httpd-devel is installed if not install it.

4.  #  tar -xvjf mod_antiloris-0.4.tar.bz2
5.  #  cd mod_antiloris-*
6.  #  apxs -a -i -c mod_antiloris.c
7.  Restart Apache:
    #  service httpd restart
8.  Check to make sure it is loaded:
    #  httpd -M 2>&1 | grep antiloris

Posted in DDOS Mitigation.


Plesk – License Issues – Retrieve Keys

If you are logging into Plesk and receive a blank white page after you have clicked on the “Retrieve  keys”, check the following:

Make sure you can connect to the following host with telnet:

#  telnet ka.parallels.com 5224

If you can not connect make a connections make sure that iptables is disabled and try again.

I have come across the following issue that was displaying the same behavior.  Looking at the psa logs I notices the following error:

2012-11-30 11:40:23: (mod_fastcgi.c.2582) FastCGI-stderr: PHP Warning:  ExtendedServerInfo::require_once(modules/atism/ATISManager.php) [<a href='extendedserverinfo.require-once'>extendedserverinfo.require-once</a>]: failed to open stream: No such file or directory in /usr/local/psa/admin/plib/ExtendedServerInfo.php on line 1298
PHP Fatal error:  ExtendedServerInfo::require_once() [<a href='function.require'>function.require</a>]: Failed opening required ‘modules/atism/ATISManager.php’ (include_path=’/usr/local/psa/admin/plib:/usr/local/psa/admin/javascripts:/usr/local/psa/admin/plib/locales:/usr/local/psa/admin/auto_prepend:/usr/local/psa/admin/htdocs/domains/databases/phpMyAdmin:/usr/local/psa/admin/htdocs/domains/databases/phpPgAdmin:/usr/local/psa/admin/plib/sb/pear’) in /usr/local/psa/admin/plib/ExtendedServerInfo.php on line 1298

After investigation it seems to be an issue with a modules package called atism.  In order to resolve the issue I re-installed the package.

a)  Go to http://64.131.90.31/ and download the following package.  The example is for RHEL 5 64bit on Plesk 9.5.4:

#  wget http://64.131.90.31/PSA_9.5.4/dist-rpm-RedHat-el5-x86_64/opt/modules/atis/

b) Run the following command:

#  rpm -Uvh psa-atis-1.0-46.x86_64.rpm

Once this is done you can “Retrieve Keys” successfully.

Posted in Plesk.


Mail – Exim

View the exim mail queue:

exim -bp

Remove email message from the queue:

# exim -Mrm {message-id}

Remove all email in the queue:

# exim -bp | exiqgrep -i | xargs exim -Mrm

Remove email based on the FROM address:

#  exiqgrep -i -f user@domain.com | xargs exim -Mrm

Remove email based on the TO address:

#  exiqgrep -i -t user@domain.com | xargs exim -Mrm

Posted in Exim.


RHEL/CentOS – iptables – Error – restorecon: command not found

If you attempt to save the iptables rule set and receive the following error:

iptables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 268: restorecon: command not found

Go ahead and install the following:

#  yum install policycoreutils

Posted in IPtables.


Apache – mod_rewrite – redirecting non-ssl to ssl using X-Forward

If you wish to redirect non-ssl traffic to ssl traffic you may use the following rule.  I use the ‘X-Forwarded’ condition when dealing with software Load Balancers that are terminating ssl traffic on them.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://www.samplesource.com$1 [R=301,L]

Posted in Apache, mod_rewrite.