DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel
Explore NY Stream

How to get started with CentOS

— ny_wk

How to get started with CentOS
🛒 Recommended gear on Amazon

Disclosure: some links above are affiliate links — if you buy through them I may earn a small commission at no extra cost to you. Thanks for supporting the channel!

Getting started with CentOS can feel like a big step into the world of enterprise-grade Linux, but it’s an incredibly rewarding journey for any aspiring DevOps engineer or system administrator. This guide will walk you through the essentials of CentOS, from understanding its core benefits and why it's the preferred platform for robust server installations, to mastering its installation process and configuring its graphical user interface (GUI) or command-line targets with ease.

CentOS, short for Community Enterprise OS, is a free, open-source distribution based on Red Hat Enterprise Linux (RHEL). Think of it as getting all the rock-solid stability, security, and enterprise features of RHEL without the associated support subscription cost. This makes CentOS an immensely attractive option for development, testing, and even production environments where direct vendor support isn't a strict requirement. If you’re looking to build a stable, secure, and long-lasting server infrastructure, knowing how to get started with CentOS is absolutely crucial, yaar.

Understanding CentOS: The Backbone of Enterprise Linux

Dekho, when we talk about server operating systems, CentOS often comes up as a top choice for a reason. It’s not just another Linux distribution; it’s a direct descendant of RHEL, which is a gold standard in the enterprise world. This lineage means CentOS inherits a lot of powerful characteristics that make it exceptionally reliable and secure.

The RHEL Connection: Stability, Security, and Compatibility

The primary reason for CentOS's popularity lies in its direct relationship with RHEL. RHEL is known for its rigorous testing, long-term stability, and robust security features, making it the choice for mission-critical enterprise systems. CentOS essentially takes the RHEL source code, removes the Red Hat branding and proprietary components, and recompiles it, providing a practically identical binary-compatible operating system. This means that if an application or package works on RHEL, it will, for all practical purposes, work seamlessly on CentOS.

  • Binary Compatibility Out-of-the-Box: This is a massive advantage. Any software, driver, or update designed for RHEL will function perfectly on CentOS. This compatibility significantly broadens the ecosystem of tools and applications available to CentOS users.
  • Enterprise-Grade Stability: RHEL’s development cycle focuses on stability over bleeding-edge features. This philosophy extends to CentOS, resulting in an OS that is incredibly dependable for long-term deployments. You won't find yourself dealing with unexpected breakage due to frequent, untested updates.
  • Robust Security: CentOS benefits from the same security updates and patches as RHEL. This includes features like SELinux (Security-Enhanced Linux), a powerful mandatory access control system that adds an extra layer of security, making it extremely resilient against various threats.
  • Cost-Effectiveness: While RHEL requires a paid subscription for support and updates, CentOS offers the same robust platform entirely for free. This is a game-changer for startups, small businesses, and anyone running a large number of servers without a dedicated budget for enterprise OS licensing.

The Power of Longevity: Extended Support Cycles

One of the most valuable aspects of CentOS, especially in a professional setting, is its incredibly long support cycle. Unlike some other distributions, like Fedora, which might offer support for around 13 months per release, CentOS releases are typically supported for up to seven years. Imagine that! This lengthy support period is a huge benefit for enterprises and individuals alike:

  • Reduced Upgrade Fatigue: For server environments, frequent OS upgrades can be disruptive and resource-intensive. A 7-year support cycle means you can deploy a CentOS server and not worry about a major OS upgrade for a significant period, allowing you to focus on your applications and services.
  • Long-Term Planning: This predictability helps in long-term infrastructure planning and budgeting. You know you have a stable platform for years to come.
  • Dependability and Reliability: The commitment to long-term support underscores the reliability of CentOS as a platform for critical operations.

Beyond traditional server installations, the CentOS community project is actively expanding its availability across a large array of platforms. You can find CentOS images readily available on major cloud providers like Google Cloud Platform, Amazon AWS, and others, often as generic cloud-init enabled images, making deployment in virtual environments super straightforward.

Getting Started with CentOS Installation: Your First Step into Enterprise Linux

Alright, so you’re convinced CentOS is the way to go. Superb! Now, let’s talk about CentOS installation. The process is quite user-friendly, thanks to an installation utility called Anaconda. This powerful installer can cater to both beginners and advanced users, offering a graphical interface for easy setup, or command-line and automated options for complex deployments. To learn more about CentOS, you can always visit the CentOS Project here.

Preparing for Installation

Before you even fire up Anaconda, you’ll need a few things:

  1. Download CentOS ISO: Head over to the official CentOS website to download the appropriate ISO file. For production servers, CentOS Linux 7 or 8 (if you're still on the traditional CentOS Linux path) are common choices. Always go for a stable release.
  2. Create Bootable Media: You'll need to create a bootable USB drive or DVD from the ISO. Tools like Rufus (for Windows), Etcher (cross-platform), or the `dd` command (for Linux/macOS) work great for USBs.
  3. System Requirements: Ensure your hardware meets the minimum requirements (CPU, RAM, disk space). For a basic minimal server, a couple of GBs of RAM and 20-40GB of disk space are usually sufficient.

The Anaconda Installer: A Guided Journey

Anaconda is a unique installer. Unlike many others that follow a strict linear path (language, then networking, then disk, etc.), Anaconda presents you with a central screen where you can configure most aspects of the installation in any order you like. This parallel nature means you can often configure unrelated options while waiting for a background task, like disk detection, to complete.

Interactive Graphical Installation for Beginners

Most users, especially those new to Linux, will find the graphical interface in Anaconda extremely intuitive. Here's a general flow:

  1. Language and Locale: The very first screen will ask you to select your language and locale. This is one of the few linear steps.
  2. Installation Summary: Once selected, you'll land on the main "Installation Summary" screen. This dashboard-like interface is where the magic happens. Here, you'll see various categories, some of which might have an exclamation mark, indicating they require your attention.
  3. KEY Sections to Configure:
    • NETWORK & HOSTNAME: Configure your network interfaces (IP address, DNS, gateway) and set your server's hostname. This is crucial if you're installing from a network location or plan for immediate network access.
    • INSTALLATION DESTINATION: This is where you configure your hard drives. You can opt for automatic partitioning (simplest) or manual partitioning. For servers, often custom partitioning using LVM (Logical Volume Management) is preferred for flexibility.
    • SOFTWARE SELECTION: This is an important choice.
      • "Minimal Install" is ideal for headless servers (no GUI) to save resources.
      • "Server with GUI" includes the GNOME desktop environment and common server tools. This is what the source video is dealing with, and it’s a good starting point for juniors learning the ropes.
      • Other options like "Workstation," "KDE Plasma Workspaces," etc., are available if you intend to use CentOS as a desktop OS.
    • DATE & TIME: Set your timezone.
    • SECURITY POLICY (Optional): If your organization requires it, you can apply specific security profiles.
  4. User Settings:
    • ROOT PASSWORD: Set a strong password for the root user. This is your administrative super-user, so choose wisely.
    • USER CREATION: Create at least one regular user account. It's generally good practice to operate as a regular user and use `sudo` for administrative tasks, rather than logging in as root directly.
  5. Begin Installation: Once all required sections are configured (no more exclamation marks!), you can click "Begin Installation." Anaconda will then proceed to install CentOS.
  6. Reboot: After installation completes, reboot your system, and you'll boot into your freshly installed CentOS environment.

Advanced Installation: Kickstart and Remote Access

For large-scale deployments or consistent, unattended installations, Anaconda supports:

  • Kickstart Files: A Kickstart file is an automated configuration file that Anaconda can read to perform an installation without any human interaction. It specifies everything from partitioning schemes and package selections to network settings and user accounts. This is invaluable for deploying hundreds of servers with identical configurations.
  • Remote Installation: On systems without a local monitor or keyboard, installation can be accessed entirely remotely using VNC or SSH, allowing for headless server setup from anywhere.

Mastering the CentOS GUI: Switching Targets with `systemctl`

By default, a full installation of CentOS 7 (or later versions with a "Server with GUI" option) will often boot directly into the graphical user interface. However, it’s entirely possible that your system has been configured for a minimal install or to not boot into the GUI by default. This is common for servers, where resources are better spent on serving applications rather than rendering a desktop environment. But what if you need that GUI temporarily, or want it to start every time? This is where `systemctl` and systemd targets come into play, yaar.

systemd is the system and service manager in modern Linux distributions, including CentOS. It replaced the older `SysVinit` system and introduced the concept of "targets" instead of "runlevels." Think of targets as groups of services that define a specific system state. The two main targets we're concerned with here are:

  • multi-user.target: This is akin to the well-known runlevel 3. It means a console-only environment with networking enabled. Ideal for headless servers.
  • graphical.target: This is similar to runlevel 5. It includes all services from `multi-user.target` but also starts the graphical user interface.

1. Checking Your Current Default Target

First, let’s see what your CentOS system is currently configured to boot into by default. Open your terminal (if you're in GUI) or just log in (if you're in TTY/console) and run this command:

[root@centos7 ~]# systemctl get-default

If your system is configured for a headless boot, you will likely see an output similar to this:

multi-user.target

This confirms your system is set to boot into the command-line interface, which is perfectly normal for a server environment. But agar tumhein GUI chahiye, then read on!

2. Temporarily Starting the GUI

Suppose you just need the GUI for a quick task, but you don't want it to start automatically every time you boot. You can start the graphical environment right now without changing the default boot target:

[root@centos7 ~]# systemctl isolate graphical.target

This command will switch your system to the `graphical.target`, effectively starting the GUI. You'll see your desktop environment (most likely GNOME, if installed) appear. However, this change is only temporary. If you reboot your system, it will revert to booting into `multi-user.target` because that's still the default.

3. Permanently Setting GUI as Default

If you want your CentOS system to *always* boot into the GUI, you need to change the default target. This is particularly useful if you're using CentOS as a workstation or a server where you frequently need a graphical interface:

[root@centos7 ~]# systemctl set-default graphical.target

Upon executing this command, you'll see a message indicating a symlink has been removed and a new one created:

Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.

What just happened? The `default.target` symlink, which points to the system's default boot target, has been updated to point to `graphical.target`. Now, if you reboot your system, it will automatically boot into the GUI, whichever version you may have installed.

When to Use a GUI vs. Headless Server

It's important to understand *why* you'd choose one over the other:

  • GUI (Graphical User Interface):
    • Pros: Easier for beginners, provides visual tools for configuration, good for desktop use, required for some specific applications that demand a graphical environment (e.g., certain developer IDEs).
    • Cons: Consumes more system resources (RAM, CPU), can be a security risk if not properly secured, generally not preferred for production servers where every bit of resource counts.
  • Headless (Command Line Interface - CLI):
    • Pros: Minimal resource consumption, highly efficient, extremely secure (fewer attack vectors), ideal for remote management via SSH, standard for production servers and virtual machines.
    • Cons: Steeper learning curve for beginners, requires familiarity with command-line tools.

Most experienced DevOps engineers prefer headless servers for production deployments due to efficiency and security. However, for a learning environment or a personal workstation, a GUI is often more comfortable to start with. And hey, if you’re interested in changing things up, you can always check out posts on installing different GUIs in CentOS, like KDE Plasma or XFCE, if GNOME isn't your cup of chai!

Beyond Installation: Essential Post-Setup for Your CentOS Server

Installation is just the first hurdle, bhai. Once CentOS is up and running, there are a few essential post-installation steps you should always take to ensure your server is secure, updated, and ready for action.

  1. Update Your System: This is non-negotiable. Always update your system immediately after installation to get the latest security patches and bug fixes. For CentOS 7, you'd use yum, and for CentOS 8 and later, it's dnf:
    sudo dnf update -y  # For CentOS 8+
    sudo yum update -y  # For CentOS 7

    After a kernel update, a reboot might be necessary.

  2. Configure Networking: While Anaconda usually handles basic networking, you might need to set up a static IP address, configure DNS, or set up bonding/teaming for redundancy. Network configuration files are typically found in /etc/sysconfig/network-scripts/. For example, to edit an Ethernet interface:

    sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

    After making changes, restart the network service:

    sudo systemctl restart network
  3. Set Up Firewall (firewalld): CentOS uses `firewalld` as its default firewall management solution. It's critical to configure it to allow only necessary traffic. For example, to allow SSH and HTTP traffic:

    sudo firewall-cmd --permanent --add-service=ssh
    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --reload

    Always verify your firewall rules carefully.

  4. Enable and Secure SSH: For remote administration, SSH is indispensable. Ensure the `sshd` service is running and enabled at boot:

    sudo systemctl enable sshd
    sudo systemctl start sshd

    For security, consider disabling root login via SSH, using key-based authentication instead of passwords, and changing the default SSH port (22) in /etc/ssh/sshd_config.

  5. Configure SELinux: Security-Enhanced Linux (SELinux) is a powerful security feature that often trips up newcomers. It's designed to restrict programs to only the resources they need. While it can be complex, it's a vital part of CentOS security. You can check its status with sestatus. For most servers, keeping it in "enforcing" mode is recommended, but you might temporarily switch to "permissive" while troubleshooting certain application issues.
  6. Install EPEL Repository: The Extra Packages for Enterprise Linux (EPEL) repository provides a large set of additional, high-quality packages that are not available in the official CentOS repositories but are compatible with RHEL/CentOS. It's a must-have for many server setups:
    sudo dnf install epel-release # For CentOS 8+
    sudo yum install epel-release # For CentOS 7

These initial steps lay a solid foundation for your CentOS server, ensuring it's secure, accessible, and ready for you to deploy your applications. Remember, practice makes perfect, so don't hesitate to experiment in a non-production environment.

Key Takeaways

  • CentOS is RHEL-compatible and free: It offers enterprise-grade stability, security, and binary compatibility with Red Hat Enterprise Linux without the subscription cost, making it ideal for servers.
  • Long-term support is a major advantage: CentOS releases provide up to 7 years of support, ensuring dependability and reducing the need for frequent, disruptive upgrades.
  • Anaconda simplifies installation: The graphical Anaconda installer guides users through setup, offering interactive options for beginners and advanced features like Kickstart for automation.
  • `systemctl` manages GUI targets: Use systemctl get-default to check the boot target, systemctl isolate graphical.target for a temporary GUI, and systemctl set-default graphical.target for permanent GUI boot.
  • Post-installation essentials are crucial: Always update the system, configure networking and firewall, secure SSH, and consider adding the EPEL repository for a robust server environment.

Frequently Asked Questions

What is CentOS and why is it popular for server installations?

CentOS (Community Enterprise OS) is a free, open-source Linux distribution that is binary-compatible with Red Hat Enterprise Linux (RHEL). It's popular for server installations due to its inherited stability, security, and robust performance from RHEL, coupled with a long support lifecycle (up to 7 years) and no licensing fees. This makes it a reliable and cost-effective choice for production environments, cloud deployments, and learning.

How is CentOS different from RHEL?

The primary difference between CentOS and RHEL is the support model and branding. CentOS is essentially a recompiled version of RHEL's source code, making it binary-compatible. However, RHEL is a commercial product backed by Red Hat's paid support, certifications, and proprietary tools, while CentOS is community-supported and completely free. For most practical purposes, especially concerning functionality and package compatibility, they are nearly identical, with CentOS providing an "unbranded" RHEL experience.

Can I install a GUI on a minimal CentOS server, and how?

Yes, you can absolutely install a GUI on a minimal CentOS server that was initially installed without one. You'd typically use the `dnf` (CentOS 8+) or `yum` (CentOS 7) package manager to install a desktop environment group, such as "Server with GUI" or "GNOME Desktop". For example: sudo dnf groupinstall "Server with GUI". After installation, you can temporarily start the GUI with systemctl isolate graphical.target or set it as default with systemctl set-default graphical.target.

What is Kickstart in CentOS?

Kickstart is an automated installation method for CentOS (and RHEL) that allows system administrators to create a configuration file containing all the necessary information for an unattended installation. This file defines everything from disk partitioning and package selection to network settings and user accounts. Kickstart is invaluable for deploying multiple servers quickly and consistently, eliminating manual intervention and ensuring uniformity across numerous systems.

So, there you have it, an in-depth look at getting started with CentOS. Whether you’re setting up a personal server, exploring cloud environments, or preparing for a DevOps career, CentOS provides a robust and reliable foundation. To see some of these concepts in action and get a visual guide, make sure to watch the full video on this topic. Don’t forget to subscribe to @explorenystream for more insightful DevOps content!