Support > About cloud server > Cloud Server Regular Maintenance Guide: Clean up logs and update security patches
Cloud Server Regular Maintenance Guide: Clean up logs and update security patches
Time : 2025-11-13 10:53:33
Edit : Jtti

  After a cloud server has been running for a period of time, system logs, application logs, access logs, and error logs will accumulate, causing disk space to be occupied and even affecting system performance. Especially in high-traffic production environments, log files can grow to several gigabytes in just a few days. To avoid service interruption due to disk fullness, logs should be cleaned up regularly or an automatic cleanup policy should be set up.

  In Linux systems, you can use the following command to check disk usage:

df -h

  This command can quickly display the usage rate of each mount point. If you find that the /var/log directory is taking up too much space, you can use the du command to analyze the specific log files:

du -sh /var/log/*

  If you confirm that some logs are too large and no longer needed, you can directly clean them up or compress them:

# Clear the specified log file
> /var/log/nginx/access.log  

# Compress old logs
gzip /var/log/nginx/error.log

  Additionally, the logrotate tool can be used to automatically rotate and delete logs. The configuration file is typically located in the `/etc/logrotate.conf` or `/etc/logrotate.d/` directory. For example, you can configure the logs to rotate weekly, retaining only the most recent four weeks' worth of files.

/var/log/nginx/*.log {
    weekly
    rotate 4
    compress
    missingok
    notifempty
    create 0640 root adm
    sharedscripts
    postrotate
        systemctl reload nginx > /dev/null 2>/dev/null || true
    endscript
}

  This enables automatic log management, ensuring the integrity of the records without consuming excessive disk space.

  Besides log cleanup, updating system and application security patches is a key focus of maintenance. Cloud servers frequently face scans and attacks from the external network. If the operating system or middleware has known vulnerabilities, they can easily be exploited by hackers. For example, components such as OpenSSL, Apache, PHP, and MySQL release multiple security updates every year. Ignoring patch updates is tantamount to opening the door for attackers.

  In Ubuntu or Debian systems, you can update the system using the following command:

sudo apt update
sudo apt upgrade -y

  If you want to install only security patches without affecting other stable versions, you can use:

sudo unattended-upgrade

  On CentOS or Rocky Linux systems, the following can be executed:

sudo yum update -y

  Or simply update the security patches:

sudo yum --security update

  Before performing a system update, it is recommended to back up the cloud server with a snapshot to prevent compatibility issues or configuration errors caused by the update. Most cloud platforms support creating snapshots, which is a simple operation.

  Besides updates to the operating system itself, version upgrades of web servers, middleware, and databases are equally crucial. For example:

#  Update Nginx
sudo apt install nginx -y  

#  Update MySQL
sudo apt install mysql-server -y  

# Update PHP
sudo apt install php8.2 php8.2-fpm php8.2-mysql -y

  After the update is completed, the service status and compatibility should be checked immediately to ensure normal business access.

  Regular maintenance includes not only system updates but also attention to server security policies and resource optimization. The following command can be used to check which services are listening on the system's ports:

sudo netstat -tulnp

  If you discover any unnecessary services, such as temporary testing ports or older versions of background programs, you should immediately close or uninstall them. Additionally, you can configure firewall policies via ufw (Ubuntu) or firewalld (CentOS) to restrict unnecessary external access. For example, you can open only SSH (port 22), HTTP (port 80), and HTTPS (port 443).

sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable

  System security also includes account management. It is recommended to disable root remote login and configure key authentication for SSH.

sudo vim /etc/ssh/sshd_config

  Find the following configuration items and modify them:

PermitRootLogin no
PasswordAuthentication no

  Then restart the SSH service:

sudo systemctl restart ssh

  This method can prevent brute-force attacks and improve the security of remote access.

  Another often overlooked maintenance aspect is resource monitoring. CPU, memory, bandwidth, and disk usage directly impact service performance. Linux systems provide various tools for real-time monitoring of resource usage, such as:

top
htop
iostat
vmstat

  Additionally, it is recommended to deploy automated monitoring tools such as Prometheus, Zabbix, or Grafana to monitor performance metrics through charts and set up alert rules. Once an anomaly occurs, such as sustained high CPU usage or abnormal disk writes, the system will automatically issue an alert to help administrators handle the situation promptly.

  To improve the efficiency of long-term maintenance, automated scripts can be used to simplify cleanup and update tasks. For example, a shell script can be written to perform log cleanup and security patch updates weekly.

#!/bin/bash
# Cloud server regular maintenance script

echo "Start system update..."
sudo apt update && sudo apt upgrade -y

echo "Clean up old logs..."
find /var/log -type f -name "*.log" -mtime +7 -exec gzip {} \;
find /var/log -type f -name "*.gz" -mtime +30 -delete

echo "Delete cache files..."
sudo apt autoclean -y
sudo apt autoremove -y

echo "System maintenance complete。"

  Save the script as /usr/local/bin/maintenance.sh and add it to the scheduled tasks:

sudo crontab -e

  Add the following line to make the system execute every Monday morning:

0 3 * * 1 bash /usr/local/bin/maintenance.sh >> /var/log/maintenance.log 2>&1

  In this way, the server can be maintained automatically without human intervention.

  For database servers (such as MySQL or PostgreSQL), regular data backups and index optimization should also be performed. MySQL backups can be performed using the `mysqldump` command.

mysqldump -u root -p mydatabase > /backup/mydatabase_$(date +%F).sql

  Regularly clean up expired backup files to save storage space:

find /backup -type f -name "*.sql" -mtime +30 -delete

  For databases that are frequently updated, it is recommended to enable regular automatic backups and store them in off-site storage or cloud object storage services (such as OSS, S3).

  For security, it's also advisable to regularly check system logs for unusual login or attack records. For example, check SSH login logs:

sudo cat /var/log/auth.log | grep "Failed password"

  If a large number of attempts are detected from the same IP address, that IP address should be blocked immediately.

sudo ufw deny from 192.168.1.100

  You can also install Fail2ban to automatically detect and block malicious IPs:

sudo apt install fail2ban -y

  The configuration file is located at `/etc/fail2ban/jail.local`, and custom rules can be defined to prevent brute-force attacks.

  The stability and security of cloud servers rely heavily on regular maintenance. Cleaning logs frees up storage space, updating patches defends against potential vulnerabilities, and automated scripts improve operational efficiency. Maintenance is not a one-time event but a long-term, continuous management process. Only a regularly maintained, well-structured, and secure cloud server can truly become a stable and reliable foundation for business operations, maintaining a sustained operational advantage in digital competition.

Relevant contents

What are the common firewall types for Japanese VPS servers? The AppImage application cannot be launched on a Debian system on an overseas VPS. What are the standards for identifying VPS server qualifications? Four ways to see through a supplier's strength. What are some solutions for lag issues when accessing the BT Panel from overseas? Hong Kong VPS sort buffer configuration standard US VPS cloud server Windows container image management What aspects of data security protection are considered for Japanese VPS? Performance optimization for high-bandwidth VPS in Japan: query caching, memory allocation, and GPU resource sharing. Technical solutions for improving GPU resource utilization in US server containers What are the technical principles behind high-defense IP DDoS attack protection?
Go back

24/7/365 support.We work when you work

Support