Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2580,"date":"2019-12-06T14:41:53","date_gmt":"2019-12-06T14:41:53","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2580"},"modified":"2019-12-06T23:45:58","modified_gmt":"2019-12-06T23:45:58","slug":"setup-swap-file-on-linux","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/setup-swap-file-on-linux\/","title":{"rendered":"Setup Swap File on Linux"},"content":{"rendered":"

There will be times where you need to increase the responsiveness of your server to prevent out of memory issues.\u00a0Out of memory issues happen when an application running on your server starts consuming a large amount of memory.<\/strong>\u00a0Swap is designed as\u00a0virtual memory<\/em>, which uses your harddrive to store data that cannot be held in RAM. This tutorial will show you how to create a swap file,\u00a0which should work under Ubuntu, CentOS, and Debian.<\/strong>\u00a0This tutorial is not meant for any Custom ISO, but it is possible to follow along.<\/p>\n

Step 1: Verify that swap does not exist<\/strong><\/h3>\n

To prevent any issues during this tutorial<\/strong>, you will need to run the following to verify that a swap space is currently not active:<\/p>\n

free -m\r\n<\/code><\/pre>\n

After\u00a0running that command<\/strong>\u00a0you should see something similar to this output:<\/p>\n

total              used       free     shared    buffers     cached\r\nMem:               1840       1614     226       15          36       1340\r\n-\/+ buffers\/cache:            238      1602\r\nSwap:              0          0        0\r\n<\/code><\/pre>\n

If you see a value of\u00a00<\/code>\u00a0in the\u00a0Swap<\/code>\u00a0section, then you can proceed to step 2.<\/p>\n

Alternatively, you can run the following command to see if there is a configured swap file:<\/p>\n

swapon -s\r\n<\/code><\/pre>\n

If you do not see any output from\u00a0swapon<\/code>, then proceed to step 2.<\/p>\n

Step 2: Create swap file<\/strong><\/h3>\n

You will need to choose a location for your file.\u00a0In this tutorial<\/strong>, it will be stored at the root of the server.\u00a0We will create a 2GB swap<\/strong>\u00a0file by running the following command:<\/p>\n

dd if=\/dev\/zero of=\/swapfile count=2048 bs=1M\r\n<\/code><\/pre>\n

The\u00a0dd<\/code>\u00a0command will produce output in a similar format to:<\/p>\n

2048+0 records in\r\n2048+0 records out\r\n2147483648 bytes (2.1 GB) copied, 10.5356 s, 204 MB\/s\r\n<\/code><\/pre>\n

Next, verify that the file is located at the root of your AKLWEB Host VPS by running:<\/strong><\/p>\n

ls \/ | grep swapfile\r\n<\/code><\/pre>\n

Proceed if you see the\u00a0swapfile<\/code>\u00a0file.<\/p>\n

Step 3: Activate the swap file<\/strong><\/h3>\n

Swap files are not recognized automatically.\u00a0We will need to tell the server how to format the file and enable<\/strong>\u00a0it so it can be used as a valid swap file. As a security measure, update the swapfile permissions to only\u00a0allow R\/W<\/strong>\u00a0for root and no other users. Run:<\/p>\n

chmod 600 \/swapfile\r\n<\/code><\/pre>\n

The permission change can be verified by running the following command:<\/strong><\/p>\n

ls -lh \/swapfile\r\n<\/code><\/pre>\n

You will see a file display:<\/strong><\/p>\n

-rw------- 1 root root 2.0G Oct  2 18:47 \/swapfile\r\n<\/code><\/pre>\n

Next, tell the server to setup the swap file by running:<\/strong><\/p>\n

mkswap \/swapfile\r\n<\/code><\/pre>\n

After running it, you will see the following output:<\/strong><\/p>\n

Setting up swapspace version 1, size = 2097148 KiB\r\nno label, UUID=ff3fc469-9c4b-4913-b653-ec53d6460d0e\r\n<\/code><\/pre>\n

If everything is shown as above, you are\u00a0now ready to move<\/strong>\u00a0on to the next step.<\/p>\n

Step 4: Turn swap on<\/strong><\/h3>\n

Once your file is\u00a0ready to be used as swap<\/strong>, you need to enable it by running:<\/p>\n

swapon \/swapfile\r\n<\/code><\/pre>\n

You can\u00a0verify that the swap file<\/strong>\u00a0is active by running the\u00a0free<\/code>\u00a0command again.<\/p>\n

free -m\r\n\r\ntotal       used       free     shared    buffers     cached\r\nMem:          1840       1754         86         16         23       1519\r\n-\/+ buffers\/cache:        210       1630\r\nSwap:         2047          0       2047\r\n<\/code><\/pre>\n

If\u00a0Swap<\/code>\u00a0shows something other than\u00a00<\/code>,\u00a0then you have successfully setup swap.<\/strong><\/p>\n

Step 5: Enable swap on reboot<\/strong><\/h3>\n

By default,<\/strong>\u00a0your server will not automatically enable this new swap file.\u00a0To enable it on boot, you can update the<\/strong>\u00a0\/etc\/fstab<\/code>\u00a0file. Any text editor will suffice. In this example, I will be using\u00a0nano<\/code>.<\/p>\n

nano \/etc\/fstab\r\n<\/code><\/pre>\n

Add the following line at the end of the file:<\/strong><\/p>\n

\/swapfile   none    swap    sw    0   0\r\n<\/code><\/pre>\n

Save and close when you are finished editing the file. We are all done!<\/strong><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[231,233,242,247],"manual_kb_tag":[359],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2580"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2580"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2580\/revisions"}],"predecessor-version":[{"id":2581,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2580\/revisions\/2581"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2580"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2580"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}