Linux Troubleshooting Tips
Hi everyone. Linux is the most commonly used OS in servers. There are many distributions of Linux which are used for different purposes. While configuring, running services, taking backups etc we face many issues and have to resolve them. Here in this article, I have shown some tips to resolve those issues. So let's begin.
There are many
commands and tools useful for detecting the problem and solve them. Also, there
may be a hardware-level issue.
In case of a network-related issue, we should do a ping to the server or if any automated
ping-script configured, we should see it’s result. Then check the cable's
connectivity to the hardware and make sure that there are no loose connections
or faults in the connectors. Here we can
use ethtool
to check if the ethernet is detectable or not. In case of power failure,
we should also check the power cables and the supply.
Using dmidecode command
we can view the server’s SMBIOS report about it’s hardware. To check RAM, we
can use a flag --type memory with dmidecode. We can also install custom
programs to check RAM.
cat
/etc/redhat-release -view RHEL release
free
-m -view memory details (total, used, free, shared, cache, available)
w -view logged
users
uptime -view system
uptime
cat
/proc/cpuinfo -view CPU details
cat /proc/loadavg -view average
load of server
If there are no
server problem then we have to check the service or application running on it.
To check if an application is running or not, we can use multiple commands-
ps
-ef | grep APPLICATION_NAME,
netstat
-plunt | grep APPLICATION_NAME,
service
status APPLICATION_NAME.
To view the
status of all available services at once use service
--status-all. Here we can additionally use more or less for page-wise viewing.
To view the
services that are enabled on boot, use chkconfig
--list.
We can also use pstree to view
running services in a hierarchical manner.
We can also
check the logs from the subdirectories of /var/log
or /etc/systemd to know more details.
To view the kernel messages, use dmesg.
Then use tail to view the last 10
messages.
We can monitor the Linux process using top command. It shows Process ID (PID) with its user, priority, nice level, virtual, resident and shareable memories used by the process, percentage of CPU and memory usage, the process running time, command.
Here we can sort
the processes based on attributes (memory, CPU usage, running time etc) by
pressing M, P, T. Press o and then enter the attribute and value
(PID=Value or COMMAND=apache) to see details.
To displays the processes in a parent-child hierarchy press V (capital).
Press h for help.
Htop is a more advanced and interactive tool to monitor the Linux process with better UI, shortcut keys etc. By default, it is not installed in RHEL or CentOS or Ubuntu systems but we can install it using yum (Yellowdog Updater Modified) or apt. Here we can scroll the process list vertically and horizontally to see all processes and complete command lines.
After identifying the process, we can kill it or change it’s priority
using renice -n PRIORITY_VALUE -p PID
to reduce its memory and CPU usage.
To view the disk
space usage, we can use many commands. Some of them are-
Disk filesystem
is a very useful command. Use df -h to view the storage in the hard drive. To know the
filesystem type use df -hT. To view
the used inodes, use df -i.
To
view the delivered reads, writes, read KB/s, write KB/s and the average time for
I/O (await number) for a device, use iostat
-xz 1. It is a utility of sysstat
package. If the drive is saturated with data requests or has
a hardware problem, then it’s await number will be bigger. Also, %util shows
device utilization.
By default, sysstat is not installed in systems, we can install it using yum or apt.