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.

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

To add 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

  1. 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.
  2. Set up the swap file with the command:
    # mkswap /swapfile
  3. Change the security of the swap file so it is not world readable.
    # chmod 0600 /swapfile
  4. 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.
  5. Regenerate mount units so that your system registers the new /etc/fstab configuration:
    # systemctl daemon-reload
  6. To activate the swap file immediately:
    # swapon /swapfile
  7. To test if the new swap file was successfully created and activated, inspect active swap space:
    $ cat /proc/swaps
    $ free -h

__--Deleting SWAP--__

  1. destroying swap_logic: swapoff /swapfile either swapoff -a
  2. nano /etc/fstab
    #/swapfile          swap            swap    defaults        0 0
  3. check settings: free -h
  4. execute following steps: systemctl daemon-reload(1) + reboot(2)
  5. verify a setting: free
  6. rm /swapfile

 


Tuning Virtual Memory

Virtual memory is typically consumed by processes, file system caches, and the kernel. Virtual memory utilization depends on a number of factors, which can be affected by the following parameters.
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 = 50

cat /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

  1. lsblk 
    pvdisplay
    
  2.    pvscan
  3.    dd if=/dev/zero of=/dev/vdb bs=512 count=1
  4.  pvcreate /dev/vdb
  5.   lvmdiskscan
  6.   pvdisplay
  7.   pvscan
  8.    pvchange -x n /dev/vdb
  9.  pvchange -xy /dev/vdb
  10.  vgcreate volgroup /dev/vdb
  11.    vgs
  12.   vgdisplay volgroup
  13.    vgscan
  14.    lvcreate -L 10G volgroup
  15.  mkfs.xfs -b size=4k /dev/volgroup/lvol0
  16. mkdir /lvm_mount
  17. mount /dev/volgroup/lvol0 /lvm_mount
  18. /etc/fstab -----> UUID=50709e56-3823-4516-82b8-7cfa933e257f /lvm_mount xfs     defaults        1 2
    /dev/volgroup/lvol1
    UUID=55ed27b6-f77e-4233-a22e-637cf699907f
  19. pvscan
  20. lvcreate volgroup -n lvol1 -L 2.9G
  21. mkswap /dev/volgroup/lvol1
  22. nano /etc/fstab
    /dev/volgroup/lvol1   swap     swap    defaults     0 0
  23.  systemctl daemon-reload
  24. swapon -v /dev/volgroup/lvol1
  25. cat /proc/swaps
  26. free -h


  27. 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%