Linux real-time management-use/proc file system to control the system
Graham White (gwhite at uk.ibm.com)
IT expert, hursley, IBM
August 2003
Http://community.csdn.net/expert/topicview1.asp? Id = 2589879
The/proc file system is Linux
This article describes some of its most practical basics. Use
/Proc, you no longer need to shut down and reboot the machine to manage many details about the operating system, which is useful for administrators who require the highest availability of the system.
Anyone who has ever managed a system of commercial importance knows the value of the normal running time of the Computer-or, in turn, knows that the time of failure may cause you a lot of headaches. Adopted by the company
UNIX
One of the main reasons for the server is its reliability and stability. If you manage these servers carefully, you do not need to restart them for a long time. To achieve perfection, you can execute some management tasks in real time.
To the kernel level to maintain the availability of the server. Although the system still needs to be restarted because of hardware upgrade or someone's power cord disconnection, it is known that many management tasks can be executed without interfering with the service.
Rows, always beneficial.
This article providesNo need to rebootYou will be able to execute tips and tips on various management tasks and system changes. Linux
Various methods are provided to change the value and settings of the underlying operating system while the system is running normally. These methods have two basic forms, one of which is common to all Linux systems.
The kernel provides this form, which is exclusive to each distribution version and provided by the supplier. This article will discuss these two methods.
Change the parameters of the running kernel
Linux
Provides administrators with a great way to change the kernel while the system is running, without the need to reboot the kernel/system. This is through/proc
Virtual File System implementation. Linux Gazette provides a copy
/proc
It is one of the simplest and easiest references I have ever seen. (See references for a link to this Article .)/proc
The file system allows you to view the running kernel, which is useful for monitoring performance, searching for system information, understanding how the system is configured, and changing the configuration. The file system is called
Virtual File SystemBecause it is not actually a file system. It is only a ing provided by the kernel. It is attached to the common file system structure so that you can access it.
We can use some method to change the kernel parameters while the system is running normally. This fact gives the system administrator powerful capabilities and high flexibility in changing the kernel settings. This implementation comes from some Linux
Kernel developers are inspired by the idea. But is it a bad thing to have too many capabilities? Sometimes. If you want to change/proc
Any content in the file system, you
RequiredMake sure that you know what you are changing and what impact it will have on the system. These technologies are indeed useful, but wrong actions will bring completely undesirable results. If you are not familiar with this content, or are not sure about the impact of a change, please practice on a machine that is not important to you or your company.
How to change
First, consider how to doNoModify the kernel. There are two good reasons why you cannot switch/proc
File System, open a file in a text editor, make a series of changes, save the file, and then exit. The two reasons are:
- Data Integrity: all these files describe the running system. Since the kernel can change any of these files at any time, if you open an editor and then change some data, the system is changing the data at the underlying level, so no matter what you save, it cannot be what the kernel expects.
- Virtual files: all these files do not actually exist. How to synchronize stored data?
Therefore, the solution is not to use the editor to change any of these files. Every change/proc
Useecho
Command, and then redirect from the command line output/proc
. For example:
echo "Your-New-Kernel-Value" >
/proc/your/file
Similarly, if you want to view/proc
In the command line, you should use a command specifically for this purpose, or usecat
Command.
What to change
Good use/proc
You do not need to be a kernel expert. You only need to have a basic understanding of the structure of the file system, which can greatly help you. It is not until one day that a user asks you about some specific features that make you glad to have worked hard to find out where to make the changes.
/proc
Everything in. In this regard,/proc
The file system uses its structure and File Permission to help the system administrator.
/proc
Each file in has a very special file license assigned to it, and each file belongs to a specific user identity. This is implemented very carefully to provide the correct functions to Administrators and Users. The following list lists the specific permissions of each file:
- Read-Only: This file cannot be changed by any user. It is used to indicate system information.
- Root write: If
/proc
A file in is writable, which can only be written by the root user.
- Root read: some files are invisible to general system users, but only to root users.
- Others: for various reasons, you may see a different combination of the three common Permissions
About/proc
, You will find that most of its files are read-only,/proc/sys
Directory. This directory stores most kernel parameters (rather than information) and is designed to be changed while the system is running. Therefore, this directory is the subject of this article.
Change/proc
The last thing to understand is what to write to these files. When viewing/proc
Some of these files are readable and some are data files. By using a specific utility (such
top
,lspci
Andfree
), These data files are still readable. You will also notice that for us, there are two different formats for readable files: some are binary switches, and some include other information. The binary switch file only contains
0 (off) or 1 (on ).
Make changes
The usage and exact information of each file in/proc is beyond the scope of this article. To obtain any other information about the/proc file not involved in this article, it is the best
The source code is the source code of the Linux kernel. It contains some excellent documents. It is useful for system administrators and the following files in/proc. This does not mean that it is a detailed description,
It is only a reference that is easy to check in daily use.
/Proc/SCSI
/Proc/SCSI
As a system administrator, the most useful information you need to know is how to add more disk space without restarting the system when there is a hot swap drive. If you do not use/proc, you can insert a drive, but to enable the system to identify a new disk, you must reboot the system immediately. Here, you can use the following command to make the system recognize the new drive:
Echo "SCSI add-single-device w x y z">/proc/SCSI
To make the Command run properly, you must specify the correct parameter values w, x, y, and z, as shown below:
W is the host adapter identifier, and the first adapter is zero (0)
X is the SCSI channel on the host Adapter. The first channel is zero (0)
Y is the scsi id of the device.
Z is the Lun number, and the first Lun is zero (0)
After a disk is added to the system, you can mount any previously formatted file system or start formatting it. For example, if you are not sure what device the disk is or want to check any previous partitions, you can use commands such as fdisk-L to report this information to you.
On the contrary, the command to remove a device from the system without restarting the system is:
Echo "SCSI remove-single-device w x y z">/proc/SCSI
Before entering this command and removing the swap SCSI disk from the system, ensure that you first detach any file system that has been installed from the disk.
/Proc/sys/fs/
/Proc/sys/fs/file-max
This file specifies the maximum number of file handles that can be allocated. If you get an error message stating that the number of opened files has reached the maximum value, so that they cannot open more files, you may need to increase the value. You can set this value to any number of files and change it by writing a new numeric value to the file.
Default: 4096
/Proc/sys/fs/file-NR
This file is related to file-Max. It has three values:
Number of allocated file handles
Number of file handles used
Maximum number of file handles
This file is read-only and only used to display information.
/Proc/sys/fs/inode -*
Operations performed on any file starting with the name "inode" are the same as those on the above files starting with the name "file", but the operations performed are related to the index node, it is not related to the file handle.
/Proc/sys/fs/overflowuid and/proc/sys/fs/overflowgid
The two files respectively store the user IDs and group IDs of any file system that support the 16-bit user IDs and group IDs ). You can change these values, but if you do think you need to do so, you may find it easier to change the organization and password file items.
Default: 65534
/Proc/sys/fs/super-max
This file specifies the maximum number of super block processors. Super block is required for any mounted file system. Therefore, if a large number of mounted file systems are installed, the super block processing program may be used up.
Default: 256