CentOS (Community Enterprise Operating System) is a free, enterprise-grade Linux distribution derived from Red Hat Enterprise Linux (RHEL) source code.
Updating your CentOS server is crucial for maintaining security and performance. The primary tool for managing updates is yum
.
# Check for available updates
yum check-update
# Update all packages
yum update
# Update a specific package, e.g., httpd
yum update httpd
# Security-only updates
yum --security update
Setting up automatic updates can help maintain your server's security. Here's how to use dnf-automatic
:
# Install dnf-automatic
yum install dnf-automatic
# Enable automatic updates
systemctl enable --now dnf-automatic.timer
# Configure dnf-automatic (edit /etc/dnf/automatic.conf)
# Set apply_updates = yes for automatic security updates
CVE (Common Vulnerabilities and Exposures) is a standardized list of publicly disclosed cybersecurity vulnerabilities.
# Backup using rsync
rsync -a /path/to/data /path/to/backup
# Check for updates
yum check-update
# Update all packages
yum update
# Reboot the server
reboot
# Verify the update
yum list updates --security
Use cron to schedule automatic updates:
# Edit the crontab
crontab -e
# Add the following line to schedule daily updates at 2 AM
0 2 * * * /usr/bin/yum -y update >> /var/log/yum_update.log 2>&1
Setting up a local repository can speed up updates and reduce bandwidth usage:
# Install necessary packages
yum install createrepo httpd
# Create a directory for the repository
mkdir -p /var/www/html/repo
# Sync packages from CentOS mirrors
rsync -avz rsync://mirror.centos.org/centos/7/os/x86_64/ /var/www/html/repo
# Create the repository metadata
createrepo /var/www/html/repo
# Configure Apache to serve the repository
systemctl enable --now httpd
# Add the local repository to the yum configuration
echo '[local-repo]
name=Local Repository
baseurl=http://your-server-ip/repo
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
Regular patching of your CentOS server is crucial for maintaining security, stability, and performance. By following best practices, using automation tools, and staying informed about vulnerabilities, you can ensure a secure and reliable server environment.