How To Install htop on CentOS 8

  1. Install and enable the EPEL Repository
    # yum install epel-release
    CentOS-8 - AppStream                            1.9 kB/s | 4.3 kB     00:02
    CentOS-8 - AppStream                            1.6 MB/s | 6.0 MB     00:03
    CentOS-8 - Base                                 1.7 kB/s | 3.9 kB     00:02
    CentOS-8 - Base                                 2.0 MB/s | 7.9 MB     00:03
    CentOS-8 - Extras                               678  B/s | 1.5 kB     00:02
    CentOS-8 - PowerTools                           1.8 kB/s | 4.3 kB     00:02
    CentOS-8 - PowerTools                           518 kB/s | 1.8 MB     00:03
    Dependencies resolved.
     Package               Arch            Version            Repository       Size
     epel-release          noarch          8-5.el8            extras           22 k
    Transaction Summary
    Install  1 Package
    Total download size: 22 k
    Installed size: 30 k
    Is this ok [y/N]: y
    Downloading Packages:
    epel-release-8-5.el8.noarch.rpm                  20 kB/s |  22 kB     00:01
    Total                                           9.5 kB/s |  22 kB     00:02
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                        1/1
      Installing       : epel-release-8-5.el8.noarch                            1/1
      Running scriptlet: epel-release-8-5.el8.noarch                            1/1
      Verifying        : epel-release-8-5.el8.noarch                            1/1
  2. Read more How To Install htop on CentOS 8

MySQL/MariaDB Database Backup Script for Linux

Update the setup variables in the script below and create in root’s home folder with permissions set to 700 (e.g. /root/.scripts/mysql_backup)

# MySQL Server Setup
DATENUM=`date +%u`
# Get all database names
DBNAME="$(mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBNAME
  if [ ! -d $MPATH/$db ]; then
    mkdir -p $MPATH/$db
  mysqldump -c -u $MUSER -p$MPASS -h $MHOST --databases $db --single-transaction | gzip -9 > $MPATH/$db/$db.$DATENUM.sql.gz

Read more MySQL/MariaDB Database Backup Script for Linux

Rebuild Corrupt Yum RPM Database

When installing packages via yum and the database is corrupt, the following message is displayed:

rpmdb: Thread/process 13903/140194607871904 failed: Thread died in Berkeley DB library
error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 -  (-30974)
error: cannot open Packages database in /var/lib/rpm

Commands such as “yum clean all” also fail with this message.  To correct, move the RPM DB files to a temporary folder and rebuild the database with these 3 commands: Read more Rebuild Corrupt Yum RPM Database

Mount Windows/Samba Shares with Autofs in CentOS 6/7/8

Samba and Windows that are used on-demand should be mounted with autofs.  The system will mount or remount the share automatically as needed.

  1. Create /etc/smbpasswd to store the credentials for the user accessing the share

    Read more Mount Windows/Samba Shares with Autofs in CentOS 6/7/8

How To Install and Enable EPEL Repo on CentOS 8

You can easily install various packages by configuring a CentOS 8.x system to use Fedora EPEL repos and third party packages. This quick tutorial explains how to configure a CentOS Linux version 8.x to use the Fedora Extra Packages for Enterprise Linux (EPEL) repository.

Run the following command:

# yum search epel
epel-release.noarch : Extra Packages for Enterprise Linux repository configuration

# yum -y install epel-release

Enable the PowerTools repo since EPEL package may depend on packages from it:

# yum config-manager --set-enabled PowerTools

To get more info about the package, run:

# yum info epel-release

Protect SSH on CentOS 8 with Fail2Ban

Install Fail2Ban

  1. Enable and install the EPEL repository
    # yum -y install epel-release
  2. Install Fail2Ban
    # yum -y install fail2ban
  3. Configure Fail2Ban (See Below)
  4. Enable and start Fail2Ban
    # systemctl enable fail2ban && systemctl start fail2ban

Configure Fail2Ban

  1. Edit /etc/fail2ban/jail.local
    # vim /etc/fail2ban/jail.local
  2. Update/append as follows
    # Ban IP/hosts for 24 hour ( 24h*3600s = 86400s):
    bantime = 86400
    # An ip address/host is banned if it has generated "maxretry" during the last "findtime" seconds.
    findtime = 600
    maxretry = 3
    # "ignoreip" can be a list of IP addresses, CIDR masks or DNS hosts. Fail2ban
    # will not ban a host which matches an address in this list. Several addresses
    # can be defined using space (and/or comma) separator. For example, add your 
    # static IP address that you always use for login such as
    #ignoreip = ::1
    # Call iptables to ban IP address
    banaction = iptables-multiport
    # Enable sshd protection
    enabled = true

View Fail2Ban Status

Run the following commands to view banned IPs

# fail2ban-client status
# fail2ban-client status sshd

Extend XenServer Linux Guest LVM Drive

  1. Create a snapshot of the VM to revert back if needed
  2. Shut down the VM
  3. In XenCenter, select the VM and click the Storage tab
  4. Select the disk and click Properties
  5. Enter the new size under Size and Location
  6. Power on the VM
  7. Verify the additional storage is available
    # fdisk -l
  8. Edit the expanded drive with fdisk
    # fdisk /dev/xvda
  9. View the existing partitions by typing ‘p’
  10. Create a new partition by typing ‘n’
  11. If there are less than 4 partitions, select primary.  Otherwise, select extended.
  12. Press Enter twice to use all of the free space
  13. Type ‘p’ to view the new table
  14. Type ‘t’ to change the partition type of the new partition to type ‘8e’
  15. Once the partition table looks correct, type ‘w’ to save and quit
  16. Reboot the VM
  17. Create a new LVM physical volume on the new partition
    # pvcreate /dev/xvda4
  18. Extend the volume group to include the new PV
    # vgextend vg_system /dev/xvda4
  19. Extend the logical volume to include the remaining free space in the VG
    # lvextend -l+100%FREE /dev/mapper/vg_system-lv_root
  20. Resize the filesystem to fill the free space in the LV
    # resize2fs /dev/mapper/vg_system-lv_root
  21. Verify the additional space is available
    # df -h

Swap File Creation

This page explains how to create and use a file-based swap in Linux.  This will generally be used in VMware and Xen images to simplify the images.

  1. Type the following command to create a 512MB swap file (1024*512 = 524288 block size – multiply to generate a bigger swap file)
    $ sudo dd if=/dev/zero of=/swap.file bs=1024 count=524288
  2. Set up a linux swap area
    $ sudo mkswap /swap.file
  3. Activate the swap space immediately
    $ sudo swapon /swap.file
  4. To active the swap space after a system reboot, and an entry to /etc/fstab.  Open this file using a text editor such as vim.
    $ sudo vim /etc/fstab
  5. Append the following line
    /swap.file              swap                    swap    defaults        0 0
  6. Verify swap is activated
    $ free -m