How to Upgrade from CentOS 7 to AlmaLinux 8 or 9 on Your VPS or Dedicated Server

With CentOS 7 reaching its end of life, upgrading to a modern and supported OS like AlmaLinux 8 or 9 is crucial for continued stability, security, and performance. AlmaLinux offers a seamless and reliable transition path as it’s built to be a 1:1 RHEL binary compatible fork, making it an excellent choice for CentOS users.

Prerequisites

  • A VPS or dedicated server running CentOS 7.
  • Root access to the server.
  • A recent backup of your server’s data and configurations.
  • Ensure your system is fully updated.

Step-by-Step Guide to Upgrading from CentOS 7 to AlmaLinux 8/9

Step 1: Update and Prepare Your System

  1. Log in to your CentOS 7 server via SSH as the root user or a user with sudo privileges.
  2. Update all system packages:
   sudo yum update -y
  1. Reboot your server to ensure all updates are applied:
   sudo reboot
  1. Verify your CentOS version:
   cat /etc/centos-release

You should see output similar to CentOS Linux release 7.x.x (Core).

Step 2: Install the ELevate Tool

The ELevate tool is used to migrate from CentOS 7 to AlmaLinux 8 or 9.

  1. Add the ELevate repository:
   sudo yum install -y https://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm
  1. Install the leapp package:
   sudo yum install -y leapp

Step 3: Check for Upgrade Compatibility

  1. Run a pre-upgrade check:
   sudo leapp preupgrade
  1. Review the pre-upgrade report:
    The report is located at /var/log/leapp/leapp-report.txt. It will detail any issues that need to be resolved before proceeding.
  2. Address any issues raised in the report. Common issues may include unsupported packages, custom configurations, or third-party repositories.

Step 4: Begin the Upgrade Process

  1. Start the upgrade process:
   sudo leapp upgrade

This process may take some time as it involves downloading and installing new packages, migrating configurations, and updating the kernel.

  1. Reboot your server:
   sudo reboot

The system will boot into a special initramfs environment and complete the upgrade.

Step 5: Verify the Upgrade

  1. Log back into your server after the upgrade process completes.
  2. Check the new OS version:
   cat /etc/redhat-release

You should see output indicating that you are now running AlmaLinux 8 or 9, depending on your chosen target version.

Step 6: Post-Upgrade Tasks

  1. Reinstall third-party repositories or packages if necessary.
  2. Test critical services and applications to ensure they are functioning correctly.
  3. Clean up old packages and files:
   sudo yum autoremove

Troubleshooting Tips

  • Check the leapp logs if you encounter issues:
  • /var/log/leapp/leapp-upgrade.log
  • /var/log/leapp/leapp-report.txt
  • Ensure your system has enough free disk space for the upgrade process.
  • Disable any custom or third-party repositories that may cause conflicts and re-enable them after verifying compatibility with AlmaLinux.

Conclusion

Upgrading from CentOS 7 to AlmaLinux 8 or 9 ensures continued support, security, and compatibility for your server. With the ELevate tool, the migration process is straightforward, allowing you to maintain your existing setup with minimal downtime and effort.

How to enable iptables in CentOS 7

Just use the following commands to disable firewalld and enable the good old iptables in any CentOS 7 based VPS or server:

[root@test2 ~]# systemctl stop firewalld

[root@test2 ~]# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.

[root@test2 ~]# yum install -y iptables iptables-services
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.centos.org
* extras: mirror.centos.org
* updates: mirror.centos.org
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Package iptables-1.4.21-24.1.el7_5.x86_64 already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package iptables-services.x86_64 0:1.4.21-24.1.el7_5 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================
Installing:
iptables-services x86_64 1.4.21-24.1.el7_5 updates 51 k

Transaction Summary
=========================================================================================================================================
Install 1 Package

Total download size: 51 k
Installed size: 25 k
Downloading packages:
iptables-services-1.4.21-24.1.el7_5.x86_64.rpm | 51 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : iptables-services-1.4.21-24.1.el7_5.x86_64 1/1
Verifying : iptables-services-1.4.21-24.1.el7_5.x86_64 1/1

Installed:
iptables-services.x86_64 0:1.4.21-24.1.el7_5

Complete!
[root@test2 ~]#

[root@test2 ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@test2 ~]#
[root@test2 ~]# systemctl start iptables

How to update SSH Port in CentOS 7

Update SSH Port in CentOS 7

Here are few simple steps on how to update SSH Port in CentOS 7 VPS or Dedicated Server

Edit the SSHD configuration file :

nano -w /etc/ssh/sshd_config

(if nano is not installed use any other text editor or install it with yum -y install nano)

and change the Port number from 22 to any custom port you choose :

e.g. Port 18989

Make sure to even remove the # mark before Port

Save the config file

SELinux is enabled by default in CentOS 7 so you need to even inform SELinux to change the SSH Port else it won’t allow you to restart SSHD with new Port.

To run semanage for updating SSHD Port you nee to first install policycoreutils, install it with :

yum -y install policycoreutils-python

now update SeLinux policy to allow new port for SSH service. to do this, run below :

semanage port -a -t ssh_port_t -p tcp 18989

now you need to update Firewall policy to allow new SSH Port, to do this run below :

firewall-cmd –permanent –zone=public –add-port=18989/tcp
firewall-cmd –reload
systemctl restart sshd.service

SSHD Port is now updated, you can now connect to your new SSH Port: 18989