This article uses a CentOS system as an example, but the same applies to other distributions of Linux. Don’t obsess over the specific version, just understand the design intent.

This article is constantly updated. Other than errata, no additional annotation.

An overview of

  • Round nodes refer to directories and square nodes refer to files.
  • Many uncommon directories and files are omitted.
  • I’ll talk about that in a second/procDirectory and/varDirectory.

Linux treats the entire file system as a single tree, and the root of the tree is called the root file system, represented by a “/”.

directory content For example,
/bin Commands used by all users to complete basic maintenance tasks ls, cp
/etc Configuration files of the system and application software bashrc, passwd
/home Home directory for ordinary users /home/msh
/lib The system’s most basic shared link library and kernel module Libc – 2.17. So
/root Home directory of user root .bashrc, .ssh
/sbin Executable files used by super users, which are mostly system management commands ifconfig, iptables
/tmp Storing temporary files

The directory structure of the /usr directory is similar to that of the root directory, but the files in the root directory are mostly system-level files, while the files in the /usr directory are user-level files, which are generally not system-specific.

directory content For example,
/usr/bin The location where most everyday applications are stored yum, git
/usr/include C/C + + header files ctype.h
/usr/lib Library files for ordinary users Mysql library file
/usr/local Personally installed software, usually manually specified; Similar to the directory structure of the “/usr” directory
/usr/sbin Hypervisors that are not required by superusers useradd

A top priority

The/proc directory

The /proc directory mounts a virtual file system that maps system and process run-time information in memory as virtual files.

System information

The direct subdirectory under /proc typically stores system information. Monkeys use only two:

directory content For example,
/proc/cpuinfo Information about the processor Physical ID, CPU cores, Siblings, processor
/proc/version The kernel version number of the system The Linux version 3.10.0

/proc/version Determines the kernel version number and CPU architecture (such as I686); /etc/centos-release Determines the distribution number (similar to other distributions).

Uname -a is similar to cat /proc/version.

Process information

The focus is on the process information for the /proc/ directory mapping. Take the rsyslogd process as an example:

directory content For example,
/proc/<pid>/cmdline The complete command to start the current process /usr/sbin/rsyslogd-n
/proc/<pid>/cwd The soft chain of the current process working directory cwd -> /
/proc/<pid>/environ A list of environment variables for the current process LANG=zh_CN.UTF-8
/proc/<pid>/exe Starts the soft chain of executables for the current process exe -> /usr/sbin/rsyslogd
/proc/<pid>/fd Directory that holds file descriptors held by the current process (in the form of a soft chain pointing to the actual file) 2 -> /dev/null

6 -> /var/log/messages
/proc/<pid>/limits Soft and hard limits (and units) on resources used by the current process Open Files (default soft limit 1024)
/proc/<pid>/task Directory that holds information about each thread in which the current process is running. In order to<tid>As the directory name of each thread, the directory structure and/proc/<pid>similar 1037, 1050, 1051

A few additional points:

  • Use ulimit to view or modify resource limits for the current process.
  • Soft limits can be modified at any time by the process itself; Hard restrictions can only be modified with root permission.
  • A brief introduction to the Linux thread model and thread switching.

The/var directory

The /var directory stores data files, such as program data and logs. But online logs are usually only placed in the /var directory.

System log /var/log/messages

System-level logs are recorded using rsyslog. The configuration file is /etc/rsyslog.conf. /var/log/messages:

# Log anything (except mail) of level info or higher. # Don't log private authentication messages! *.info; mail.none; authpriv.none; cron.none /var/log/messagesCopy the code

*. Info Indicates that all service messages whose priority is greater than or equal to the info priority are recorded in /var/log/messages. Mail. none Indicates that no mail messages are recorded in /var/log/messages.

In addition to security authentication, mail, and scheduled tasks, info logs and higher-level logs sent to STdout and Stderr are recorded in /var/log/messages.

OOM kill

Monkey used /var/log/messages to locate an OOM kill problem.

A user often complains that his app mentions Yarn after a variety of containers exit 137 and then retry. If the frame does not exit 137 by itself, 137 usually means “container” because of kill -9, so mentor prompts the monkey to kill in OOM. To test this idea, you must find “traces of the relevant container being killed by OOM.”

Linux monitors memory usage. If memory is running low, OOM Killer calculates the process priority and kills the process with the highest priority to release memory. Resource overload is commonly configured in Yarn clusters (Linux also has memory overload). When cluster resources are tight, large Containers are easily killed by OOM.

The three steps of OOM kill, “Find insufficient memory”, “Calculate priority” and “select process kill”, are recorded in /var/log/messages. The monkey actually found the OOM kill log of the corresponding container near the specified point in time. The memory resources are similar to those applied for by the Container.

Have to pass.

There are a few minor problems with judgment:

  • Monkey determines whether the container is the target process based on the OOM kill time and memory.

Suggestions for personal use

For the purposes of this article, the reader is not concerned with the differences between distributions and kernel versions.

Yes, there is a difference. For example, CentOS 6.5 can verify the directory structure that this article will explain. In CentOS 7.2, system-level directories such as /bin are soft-linked to user-level directories such as /usr/bin. Other distributions such as Debian may be even more different.

If you must, it is generally recommended to install all shared software in the /usr/local directory (similar in structure to /usr) and to install private software in the user’s home directory.


Reference:

  • The role of subdirectories in the Linux root directory
  • In-depth understanding of proc file systems on Linux

This article is published under the Creative Commons Attribution – Share Alike 4.0 International License. The attribution and link to this article must be reserved.