In Linux hosting environments, performance issues are often related to CPU and RAM usage. To diagnose these issues, you can use the following commands:
top - Displays the current state of the system, providing information on CPU and RAM usage.
htop - An advanced version of top that offers a more user-friendly interface.
dmesg - Shows kernel messages to help identify system errors.
free -m - Displays RAM usage in megabytes.
vmstat 1 - Updates system statistics every second.
CPU Usage Issues
If CPU usage is high, some processes may be consuming excessive resources. Use top or htop to identify the most resource-intensive processes.
Solution Steps:
Identify high CPU-consuming processes.
Terminate the process using kill (PID is the process ID).
Restart the process if necessary.
RAM Usage Issues
If RAM usage exceeds 90%, the system may slow down. Again, use top or htop to identify the issues.
Solution Steps:
Identify the highest RAM-consuming processes.
Use kill to close unnecessary processes.
Swap space may need to be increased. To do this, follow these steps:
Create a new swap file: sudo fallocate -l 2G /swapfile
Activate the swap file: sudo chmod 600 /swapfile and sudo mkswap /swapfile
Start the swap space: sudo swapon /swapfile
To make the swap file persistent, use echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab.
Restarting Services
If you have made changes in configuration files, you may need to restart the relevant services. You can use the following commands:
sudo systemctl restart apache2 - Restarts the Apache web server.
sudo systemctl restart mysql - Restarts the MySQL server.
sudo systemctl restart nginx - Restarts the Nginx server.
After making changes in configuration files, don’t forget to check the service status using systemctl status .