Linux server administrator daily necessary monitoring commands

  
                  

Do you want to know what your server is doing? Then you need to know the basic commands described in this article. Once you are familiar with these commands, you have laid the foundation for becoming a professional Linux system administrator.

You can get a lot of information from these shell commands through a graphical user interface (GUI) program, depending on which Linux distribution you use. For example, SUSE Linux has an excellent, graphical configuration and management tool, YaST, and KDE's KDE System Guard is equally good.

However, one common thread Linux administrators need to understand is that the GUI should be run on the server only when absolutely necessary. That's because the Linux GUI consumes system resources that could otherwise be used more reasonably elsewhere. So, while using GUI programs is a good place to do a basic check on server health, if you want to know what's going on, close the GUI and start using these tools from the Linux command shell.

This also means that you should open the GUI on the server whenever you need it; turn it off when you don't need it. To ensure optimal performance, the Linux server should run at runlevel 3, which fully supports the network and multiple users, but does not open the GUI when the machine boots. If you really need a graphical desktop, you can always get a graphical desktop by running startx from the shell prompt.

If your server is booted into a graphical desktop, you will need to change this. To do this, go to the terminal window, use the su command to switch to the root user, and then open the /etc/inittab file with your favorite editor.

Once inside the file, find the initdefault line and change id:5:initdefault: to id:3:initdefault:.

If there is no /etc/inittab file, create one and add the id:3 line. Save and exit. The next time you boot into the server, it will boot into run level 3. If you don't want to restart after making this change, you can also set the run level of the server immediately with the command init 3.

Once your server is running in init 3, you can start using the following shells to see what's going on in your server.

iostat

The iostat command details the storage subsystem aspect. You usually use iostat to monitor how the storage subsystem is generally healthy, and to detect slow input/output problems before users notice that the server is slow. Believe me, you should find these problems before users find these problems!

meminfo and free

meminfo shows you the memory aspect in detail. You can usually use another program, such as cat and grep, to access the information of meminfo. For example, cat /proc/meminfo shows you in detail how the server's memory is used at any one time.

If you want to quickly get an overview of the memory, you can use the free command. In short, free gives you an overview; meminfo gives you detailed information.

mpstat

The mpstat command reports the activity of each available processor on a multiprocessor server. Today, due to multi-core processors, this command is available for almost all servers. Mpstat can also report the average activity of processors on all servers. It allows you to display total processor statistics by system or by processor. This summary information can alert you to potential application issues before they provoke users.

netstat

netstat, like ps, is also a Linux tool used by Linux administrators every day. It shows a lot of information about the network, such as socket usage, routing, interfaces, protocols, network statistics, and more. Some of the most common options are as follows:

-a Display all information about the socket

-r Display routing information

-i Display statistics for network interfaces

-s Display statistics for network protocols

nmon

nmon is short for Nigel&squo;s Monitor, a popular open source tool for monitoring the performance of Linux systems. Nmon can monitor performance information for multiple subsystems such as processor utilization, memory usage, run queue information, disk input/output statistics, network input/output statistics, memory paging activity, and process metrics. Then, you can view nmon's real-time system measurement results through the curses & ldquo; graphical & rdquo; interface.

To run nmon, you can launch the tool from the shell. Once started, simply enter the one-button command to select the subsystem to monitor. For example, to get statistics on processors, memory, and disks, just enter c, m, and d, respectively. You can also use the nmon with the -f flag to save performance statistics to a CSV file for later analysis.

For everyday server monitoring, I think nmon is one of the most useful programs in my Linux system management toolkit.

pma

The pmap command is used to report the amount of memory used by the server's processes. You can use this tool to determine which processes on the server are allocated memory and who is using a lot of memory.

ps and pstree

The two commands ps and pstree are two powerful assistants for Linux system administrators. They all display all currently running processes in a list. Ps can tell you how much memory and processor time the server's program is using. Pstree shows less information, but highlights which processes are child processes of other processes. With this information in hand, you can discover the out-of-control process and then terminate these processes with the Linux kill command.

sar

The sar program is like a Swiss army knife in the field of system monitoring tools. The sar command actually consists of three programs: sar that displays data, sa1 that collects data, and sa2 that holds data. Once installed, sar can generate detailed summary information showing processor usage, memory paging activity, network input/output and transport statistics, process creation activities, and disk device activity. The big difference between sar and nmon is that the former is more suitable for long-term monitoring system. I think nmon is more suitable for helping me quickly check the running status of the server.

strace

strace is often considered a programmer's debugging tool, but its utility is not just for debugging. It can intercept and record the progress of the process call system. Thus, it is a practical diagnostic, teaching and debugging tool. For example, you can use strace to find out which configuration file a program actually uses at startup.

But strace does have a flaw. When it checks a process, the performance of the process can plummet. Therefore, strace is used only if I have a very good reason to believe that a program is causing the problem.

tcpdum

tcpdump is a simple and reliable network monitoring utility. Its basic protocol analysis capabilities give you a cursory view of the situation on the network. But if you want to really analyze the network, you should use Wireshark (described below).

to

The top command shows the status of the active process. By default, it shows the most processor-intensive tasks running on the server, and the list is refreshed every 5 seconds. You can also categorize processes by multiple criteria, such as PID (process ID); age, latest column first; time, cumulative time; and resident memory usage and total processor usage since startup time. I think it provides a quick and easy way to see if there is a process that is about to get out of control and cause problems.

uptime

Uptime can be used to see how long a server has been running and how many users have logged in. It also shows an overview of the average server load. The optimal value for the load is 1 or less, which means that each process can access the processor immediately, and there is no loss of processor cycles.

vmstat

In general, you can use vmstat to monitor virtual memory. Linux continues to use virtual memory for optimal storage performance.

If your application is using too much memory, you will encounter frequent page-outs. —— that program enters the system hard drive from memory. Exchange space. Your server may go to this stage: it takes more time to manage memory paging than it takes to run an application —— this situation is called thrashing. When your computer is shaking, performance plummets. Vmstat can display average data or actual samples, which can help you find a lot of programs and processes that use memory, so that they don't cause the server to run like a snail.

Wireshark

Wireshark was formerly known as Ethereal (and is still often called) and is a similar tool for tcpdump, but it is more advanced and has much more advanced protocol analysis and reporting capabilities. Wireshark has both a GUI interface and a shell interface. If you are engaged in professional-level network management, you can only use ethereal. And if you're using Wireshark/ethereal, I highly recommend reading Chris Sander's Practical Packet Analysis, which provides an in-depth look at how to get the most out of this utility.

This article is only a general overview of some of Linux's most valuable system monitors. However, if you are proficient in these programs, you will lay the foundation for becoming a top Linux system administrator.

Copyright © Windows knowledge All Rights Reserved