How to monitor a CentOS server
Use built-in tools like top, htop, df, du, free, vmstat, iostat, and ss for real-time monitoring of CPU, memory, disk, and network usage. 2. Enable system logging via /var/log files and journalctl, and configure log rotation to manage disk space. 3. Set up centralized monitoring with Zabbix or Nagios NRPE for continuous, scalable oversight. 4. Create simple shell scripts to monitor disk, CPU, or memory and schedule alerts via cron. 5. Secure the system using auditd, monitor failed logins in /var/log/secure, and optionally deploy fail2ban to block malicious access attempts. Consistent monitoring of resources, logs, and access—combined with automation—ensures system stability, performance, and security over time.
Monitoring a CentOS server effectively ensures system stability, performance, and security. Here’s a practical guide to help you set up comprehensive monitoring using built-in tools and lightweight third-party utilities.

1. Use Built-in Tools for Real-Time System Monitoring
CentOS comes with several command-line tools that give you immediate insight into system health.
-
top / htop
Runtop
to see real-time CPU, memory usage, and running processes. For a more user-friendly interface, installhtop
:sudo yum install htop -y htop
df and du
Check disk usage:df -h # Show disk space in human-readable format du -sh /path/to/directory # Check folder size
free
Monitor memory usage:free -h
vmstat and iostat
Part of thesysstat
package, these help monitor system performance and I/O:sudo yum install sysstat -y vmstat 2 5 # Report every 2 seconds, 5 times iostat -x 2 # Extended I/O statistics
netstat or ss
Monitor network connections:ss -tuln # List all listening ports (modern replacement for netstat)
2. Enable and Configure System Logging
Logs are essential for diagnosing issues and detecting anomalies.
Check system logs in
/var/log
Key files:/var/log/messages
– General system messages/var/log/secure
– Authentication and SSH logs/var/log/yum.log
– Package installation history/var/log/boot.log
– Boot process messages
Use journalctl (for systems with systemd)
View logs from the systemd journal:journalctl -xe # View detailed logs with context journalctl -u sshd # Logs for a specific service journalctl --since today # Logs from today only
Set log rotation
Ensure logs don’t consume too much disk space. Edit configurations in/etc/logrotate.conf
or/etc/logrotate.d/
.
3. Set Up Automated Monitoring with Nagios or Zabbix (Optional)
For continuous, centralized monitoring—especially in production—consider installing a monitoring solution.
Zabbix (recommended for scalability)
Install Zabbix agent on CentOS to report metrics to a central server:sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm sudo yum clean all sudo yum install zabbix-agent -y
Edit
/etc/zabbix/zabbix_agentd.conf
:Server=your_zabbix_server_ip ServerActive=your_zabbix_server_ip Hostname=your_host_name_in_zabbix
Then start and enable the service:
sudo systemctl start zabbix-agent sudo systemctl enable zabbix-agent
Nagios NRPE
Allows remote monitoring of system metrics like load, disk, and CPU.
4. Monitor Critical Metrics with Simple Scripts and Alerts
You can write basic shell scripts to check system conditions and send alerts.
Example: Disk usage alert script
#!/bin/bash THRESHOLD=80 USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//') if [ $USAGE -gt $THRESHOLD ]; then echo "Warning: Root disk usage is ${USAGE}%" | mail -s "Disk Alert" admin@example.com fi
Save it as disk_check.sh
, make it executable, and schedule it with cron:
crontab -e # Add line: # */30 * * * * /path/to/disk_check.sh
Similarly, monitor CPU load or memory and trigger alerts via email or tools like curl
to a webhook.
5. Secure and Audit Your System
Monitoring isn’t just performance—security matters too.
Install and configure auditd
sudo yum install audit -y sudo systemctl start auditd sudo systemctl enable auditd
Use
ausearch
oraureport
to review audit logs.Monitor failed login attempts
Check/var/log/secure
regularly:grep "Failed password" /var/log/secure | tail -10
Use fail2ban (optional)
Automatically blocks IPs after repeated failed logins.
Monitoring a CentOS server doesn’t require complex tools to start. Use the built-in utilities daily, set up logging, and gradually adopt automated solutions like Zabbix as your needs grow. The key is consistency—regular checks and timely alerts prevent small issues from becoming outages.
Basically, keep an eye on resources, logs, and access—and automate what you can.
The above is the detailed content of How to monitor a CentOS server. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Identifythenewdiskusinglsblkorfdisk-ltolocatethecorrectdevicelike/dev/sdb.2.Optionallypartitionthediskwithfdisk/dev/sdb,createaprimarypartitionusingdefaultsettings,andwritechangeswithw,thenrunpartprobetoupdatethekernel.3.Createafilesystemusingmkfs-tx

In CentOS, the system log files are mainly stored in the /var/log directory. Common ones include: 1./var/log/messages record system messages; 2./var/log/secure record authentication-related logs; 3./var/log/dmesg record kernel information; 4./var/log/cron record timing task information; 5./var/log/boot.log record startup process. CentOS7 and above use rsyslog to manage logs, combined with systemd's journald tool, can be viewed through the journalctl command. It is also recommended to use logrotate to rotate logs and real

ToconfigureakickstartfileforautomatedCentOSinstallation,startwithatemplate,customizeessentialsectionslikelanguage,disksetup,andpackageselection,placethefilewheretheinstallercanaccessit,andtestitviabootablemediaorPXE.Beginbycopyinganexistingsamplefrom

TochangeyourownpasswordinCentOS,runpasswdandenteryourcurrentpasswordfollowedbythenewpasswordtwice.2.Tochangeanotheruser’spassword,usesudopasswdusernameorrunpasswdusernameasroot,whichdoesnotrequiretheuser’soldpassword.3.Toforceausertochangetheirpasswo

Make sure the system has loaded the bonding module and confirm that the network card interface is available, use modprobebonding and lsmod to verify; 2. Create /etc/sysconfig/network-scripts/ifcfg-bond0 configuration files, set DEVICE, TYPE, BONDING_MASTER, IP parameters and BONDING_OPTS=mode=active-backupmiimon=100primary=ens33; 3. Configure ifcfg files of physical network cards ens33 and ens34, set MASTER=bond0, SLAVE=yes and remove IP configuration

The key to installing CentOS7, 8 or 9 is to create a bootable USB drive and set up a BIOS. 1. Download the appropriate ISO image. CentOS7 recommends DVDISO, 8 and 9 recommends Minimal or BootISO, pay attention to selecting the correct architecture (x86_64 or aarch64); 2. Windows users use Rufus to write ISO to the USB disk, select GPT partition and FAT32 file system, and Mac/Linux users use dd command to write to the device path carefully; 3. Enter the BIOS settings to boot from the USB disk, and enter the startup menu through the shortcut keys such as F12/F2/Del/Esc to adjust the USB device to the first startup item; 4. Select the language during the installation process.

The method of using top or htop to view CPU usage is as follows: 1. After running the top command in the terminal, the %Cpu(s) line at the top shows the overall usage status, including subdivided items such as us (user process), sy (system kernel), ni (adjust priority), id (idle), wa (waiting for I/O); 2. Press the number 1 to view the detailed data of each CPU core; 3. Run htop to intuitively see the color bar chart and the real-time status bar, and list the CPU % occupancy of each process; 4. Press the P key to sort the occupancy rate to quickly locate the problem process; 5. High iowait (wa) value may indicate a disk bottleneck, and it needs to be investigated in combination with other tools; 6. Short-term tasks are recommended to cooperate with scripts or mpstat records; 7. Far.

When running the free-m command, the system memory usage will be displayed in MB units to help quickly judge the memory status. 1. Pay attention to the used value in the line "-/buffers/cache". This value represents the memory actually occupied by the program. If it is close to the total memory, it means that the memory is tight; 2. Linux will use free memory as cache, so the used value in the first line may be high but does not mean that the memory is insufficient; 3. You can combine other parameters such as -h (automatically select unit), -s (refresh interval), and -t (display total memory). For example, free-ms5 can refresh the memory information every 5 seconds to observe the trend.
