|
Q: I am a novice Ubuntu 14.04 LTS version. I need an extra swap file to improve the performance of my Ubuntu server. How can I connect via SSH using the related commands for my Ubuntu 14.04 LTS increase a swap partition.
Swap files in addition to being a disk storage system in order to improve Ubuntu internal efficiency of pure accident, nothing in this tutorial, you will learn how to create and use up the Swap file system in Ubuntu.
In the desktop version of Ubuntu Server Edition, or, what is the Swap File?
As a system administrator is necessary in the system after the installation is complete to add an additional swap files, and swap file also allows Ubuntu to use the hard disk to increase virtual memory.
Virtual Memory = RAM + Swap space / file
Virtual Memory (1GB) = Actual RAM (512MB) + Swap space / file (512MB)
When Ubuntu server is running out of memory, swap it for some RAM (such as foo free program) to the hard disk (swap space) to release another program memory. Then when you need the program (such as foo again), the kernel will swap Foo program, it will change in the position by the RAM in a program.
In step Ubuntu add swap partition
Open a Terminal application or use SSH client remotely connect to the server via the sudo command as root user login
# Sudo -s
Create a swap partition Command
Enter the following command on Ubuntu created 2GB swap partition
# Dd if = / dev / zero of = / swapfile bs = 1G count = 2
Back to Results
records in
2 + 0 records out
2147483648 bytes (2.1 GB) copied, 20.2256 s, 106 MB / s
Validation partition on the server to create the
# Ls -lh / swapfile
Back to Results
-rw-r - r-- 1 root root 2.0G Oct 29 14:07 / swapfile
Create a swap partition with the command fallocate
In addition to the dd command can also be faster fallocate command to create a swap partition. as follows:
# Fallocate -l 1G / swapfile-1
# Ls -lh / swapfile-1
Back to Results
-rw-r - r-- 1 root root 1.0G Oct 29 14:11 / swapfile-1
Protection swap partition
In a safe angle, enter the following command chmod and chown protection and set the correct file permissions
# Chown root: root / swapfile
# Chmod 0600 / swapfile
# Ls -lh / swapfile
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID = 10231c61-6e55-4dd3-8324-9e2a892e7137
Back to Results
-rw ------- 1 root root 2.0G Oct 29 14:07 / swapfile
A world readable swap partition is a major local vulnerability. The above command ensures that only the root user has read and write permissions.
Start swap partition
# Mkswap / swapfile
Back to Results
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID = 10231c61-6e55-4dd3-8324-9e2a892e7137
Final activate swap partition
# Swapon / swapfile
Verify and set on Ubuntu
Enter the following command
# Swapon -s
Back to Results
Filename Type Size Used Priority
/ Dev / sda5 partition 3998716 704 -1
/ Swapfile file 2097148 0 -2
You can also run the following command to create a swap partition and verify its usage
How to disable swap partitions on Ubuntu?
You can use the following command
# Swapoff / swapfile
# Swapon -s
Update / etc / fstab file
You need to reboot the server to ensure the swap partition line is enabled, edit / etc / fstab file. enter:
# Vi / etc / fstab
Add a line, as follows:
/ Swapfile none swap sw 0 0
Save and Exit
Adjust the swap partition, adjust virtual partition
You can adjust the following two options
Virtual memory on the control (swappiness)
The minimum release number (min_free_kbytes) bytes
Virtual file cache pressure (vfs_cache_pressure)
How to set swapiness on Ubuntu
The syntax is as follows:
# Sysctl vm.swappiness = VALUE
# Sysctl vm.swappiness = 20
Or face
# Echo VALUE> / proc / sys / vm / swappiness
# Echo 30> / proc / sys / vm / swappiness
In / proc / sys / vm / value swapiness how the kernel controls the forced swap memory space, higher value corresponds to the increase in mandatory strength, contrary lower value corresponds to the intensity decreases mandatory. The default value is 60. For permanent file add a line in /etc/sysctl.conf command, as follows:
echo 'vm.swappiness = 30' >> /etc/sysctl.conf |
|
|
|