Quota and Swap
Quota
(If you have chosen a different partitioning scheme than I did, you must adjust this chapter so that quota applies to the partitions where you need it.)
To install quota, we run this command:
yum -y install quota
Now we check if quota is already enabled for the filesystem where the website (/var/www) and maildir data (var/vmail) is stored. In this example setup, I have one big root partition, so I search for ' / ':
mount | grep ' / '
[root@web ~]# mount | grep ' / '
/dev/vda1 on / type xfs (rw,relatime,attr2,inode64,noquota)
If you have a separate /var partition, then use:
mount | grep ' /var '
instead. If the line contains the word "noquota", then proceed with the following steps to enable quota.
Enabling quota on the / (root) partition
Normally you would enable quota in the /etc/fstab file, but if the filesystem is the root filesystem "/", then quota has to be enabled by a boot parameter of the Linux Kernel.
Edit the grub configuration file:
nano /etc/default/grub
search fole the line that starts with GRUB_CMDLINE_LINUX and add rootflags=uquota,gquota to the commandline parameters so that the resulting line looks like this:
GRUB_CMDLINE_LINUX="vconsole.keymap=us selinux=0 net.ifnames=0 biosdevname=0 crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet rootflags=uquota,gq$
GRUB_DISABLE_RECOVERY="true"
and apply the changes by running the following command.
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg_bak
grub2-mkconfig -o /boot/grub2/grub.cfg
and reboot the server.
reboot
Now check if quota is enabled:
mount | grep ' / '
When quota is active, we can see "usrquota,grpquota" in the mount option list.
Swap
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory. Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files. Note that Btrfs does not support swap space.
Recommended System Swap Space
Amount of RAM in the system | Recommended swap space | Recommended swap space if allowing for hibernation |
---|---|---|
⩽ 2 GB | 2 times the amount of RAM | 3 times the amount of RAM |
> 2 GB – 8 GB | Equal to the amount of RAM | 2 times the amount of RAM |
> 8 GB – 64 GB | At least 4 GB | 1.5 times the amount of RAM |
> 64 GB | At least 4 GB | Hibernation not recommended |
yum install lvm2*
lvmdiskscan
You have three options:
create a new swap partition |
create a new swap file |
extend swap on an existing LVM2 logical volume |
It is recommended that you extend an existing logical volume.
Creating a Swap File
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 3GB swap file is 3145728KB
- Create an empty file:
#
dd if=/dev/zero of=/swapfile bs=1024 count=3145728
Replace count with the value equal to the desired block size. - Set up the swap file with the command:
#
mkswap /swapfile
- Change the security of the swap file so it is not world readable.
#
chmod 0600 /swapfile
- To enable the swap file at boot time, edit
/etc/fstab
as root to include the following entry:/swapfile swap swap defaults 0 0
The next time the system boots, it activates the new swap file. - Regenerate mount units so that your system registers the new
/etc/fstab
configuration:#
systemctl daemon-reload
- To activate the swap file immediately:
#
swapon /swapfile
- To test if the new swap file was successfully created and activated, inspect active swap space:
$
cat /proc/swaps
$free -h
__--Deleting SWAP--__
- destroying swap_logic: swapoff /swapfile either swapoff -a
- nano /etc/fstab
#/swapfile swap swap defaults 0 0
- check settings: free -h
- execute following steps: systemctl daemon-reload(1) + reboot(2)
- verify a setting: free
- rm /swapfile
Tuning Virtual Memory
swappiness
- A value from 0 to 100 which controls the degree to which the system favors anonymous memory or the page cache. A high value improves file-system performance, while aggressively swapping less active processes out of physical memory. A low value avoids swapping processes out of memory, which usually decreases latency, at the cost of I/O performance. The default value is 30.
nano /etc/sysctl.conf
vm.swappiness = 10
vm.vfs_cache_pressure = 50cat /proc/sys/vm/vfs_cache_pressure
cat /proc/sys/vm/swappiness
Additional setting
yum install psmisc
fuser: command not found
df -hP
fdisk -l
lvmdiskscan
-
lsblk pvdisplay
- pvscan
- dd if=/dev/zero of=/dev/vdb bs=512 count=1
- pvcreate /dev/vdb
- lvmdiskscan
- pvdisplay
- pvscan
- pvchange -x n /dev/vdb
- pvchange -xy /dev/vdb
- vgcreate volgroup /dev/vdb
- vgs
- vgdisplay volgroup
- vgscan
- lvcreate -L 10G volgroup
- mkfs.xfs -b size=4k /dev/volgroup/lvol0
- mkdir /lvm_mount
- mount /dev/volgroup/lvol0 /lvm_mount
- /etc/fstab -----> UUID=50709e56-3823-4516-82b8-7cfa933e257f /lvm_mount xfs defaults 1 2
/dev/volgroup/lvol1
UUID=55ed27b6-f77e-4233-a22e-637cf699907f - pvscan
- lvcreate volgroup -n lvol1 -L 2.9G
- mkswap /dev/volgroup/lvol1
- nano /etc/fstab
/dev/volgroup/lvol1 swap swap defaults 0 0
- systemctl daemon-reload
- swapon -v /dev/volgroup/lvol1
- cat /proc/swaps
- free -h
Sources:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html-single/storage_administration_guide/#ch-fscache
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html-single/logical_volume_manager_administration/#logical_volumes
sudo yum install cloud-utils-growpart
2) sudo growpart /dev/sda 2
3) sudo mount /dev/sda2 /mnt
4) sudo xfs_growfs -d /mnt
yum install xfsdump
parted /dev/vda
(parted) print
(parted) resizepart 1 86%