For example, you may need to do this when you feel it is time to upgrade the amount of RAM in your server, doing this will take you to upgrade you Swap Space as well since the Swap space need to be 2x times the amount of RAM installed on your server.
It might be advantageous to increase the amount of swap space to x2 of your RAM if you perform memory-intense operations or run applications that require a large amount of memory.
In this case a customer has upgraded his server RAM, hence we proceeded to upgrade his Swap Space as well.
In this example we are going to create a 8GB Swap file.
1) Make sure you have 8 GB laying around somewhere:
[root@box home]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.0G 2.5G 398M 87% /
/dev/sda2 226G 97G 119G 45% /home
/dev/shm 4.0G 0 4.0G 0% /dev/shm
2) /home since to be the best one to do this (Keep in mind that partition table schemes will differ from Server Companies to Server Companies, this is NOT the best partition table scheme we recommend for our customers.) so We’re going to make a swap file in /home by using dd to create a file 8GB file in size.
root@box home]# dd if=/dev/zero of=swapfile bs=1024 count=8290304
8290304+0 records in
8290304+0 records out
8489271296 bytes (8.5 GB) copied, 259.485 seconds, 32.7 MB/s
3) We setup some Permission restrictions for security reasons
[root@box home]# chmod 600 swapfile
4) Now we set up the swap area and enable it.
root@box home]# mkswap swapfile
Setting up swapspace version 1, size = 8489267 kB
[root@box home]# swapon swapfile
5) We should be set to go, Now we double check that our swap memory has increased,
[root@meyer home]# free -m
total used free shared buffers cached
Mem: 4104 3804 300 0 15 3012
-/+ buffers/cache: 793 7311
Swap: 8605 34 8591
6) You can edit /etc/fstab to enable your swap file automatically at boot time.
By adding an entry like this:
/home/swapfile swap swap defaults 0 0
No comments:
Post a Comment