Control the system usingproc file system

xiaoxiao2021-03-06  51

Real-Time Management Linux Using / PROC File System to Control System Graham White (GWHITE AT UK.IBM.com) IT Expert, Hursley, IBM 2003 / Proc File System is one of Linux's excellent characteristics, this article tells you more about Its most practical basics. Using / PROC, you need to close and reboot the machine to manage many of the details of the operating system, which is very useful for administrators who require the system to be as high as possible. Anyone who has managed the business-based system knows the value of the computer's normal running time - or in turn, knowing that users will bring you many headaches due to trouble. One of the main reasons for the company's UNIX servers is due to its reliability and stability. If you carefully manage, you can usually do not need to restart these servers for a long time. In order to do perfect, you can perform some administrative tasks in real time, or even the level of the kernel, thereby maintaining the availability of the server. Although it is still necessary to restart the system due to the upgrade hardware or to kick off the power cord, it is understood that many administrative tasks can be performed without interfering services, always beneficial. This article provides tips and techniques that do not need to reboot to perform on various management tasks and change systems. Linux provides a variety of methods to change the value and setting of the underlying operating system while maintaining the system normally operation. These methods have two basic forms, and a form is common for all Linux systems and provides this form in the Linux kernel (you can find more information about Linux kernels in Linux Kernel Archives and download kernel source code For the reference, there is a link to Linux Kernel Archives), and there is also a form being unique to each distributing version and is provided by the vendor. These two methods will be discussed herein. Changing the kernel of the Run provides a very good way to the administrator to change the kernel when the system is run without re-guiding the kernel / system. This is implemented by / proc virtual file system. Linux Gazette gives a reference about / proc, which is one of the easiest and easiest reference I have seen. (See References, there are links to this article.) / Proc file system mainly allows you to view the kernel in the run, this point for monitoring performance, find system information, understand how the system is configured and change the configuration Very useful. The file system is called a virtual file system because it is actually not a file system. It is just a mapping provided by the kernel, which is attached to the usual file system structure, allowing you to access it. We can use some way to change the parameters of the kernel in the running of the system, which gives the system administrator's power and high flexibility in changing the kernel settings. This implementation is the inspirational idea of ​​part Linux kernel developers. But the power is the big meeting? Sometimes it is true. If you are ready to change anything in the / proc file system, you must make sure you know what is changed and what it affects the system. These technologies are indeed useful, but the wrong move will bring complete undesirable results. If you are not familiar with this content, or if you are not sure about what you do, please practice on a machine that you or your company is not important. How to change first, consider how to make the kernel change. There are two sufficient reasons to explain why not switch to / proc file system, open a file with a text editor, make a series of changes, then save the file, and then exit.

These two reasons are: Data Integrity: All of these files describe the running system, because the kernel can change any of these files at any time, so if you open an editor, then change some data, while the system is also These data are changing under the bottom floor, then no matter what you save, it is impossible to be desired by the kernel. Virtual file: All of these files do not exist. How to synchronize the saved data, etc.? Therefore, the solution is that no editor is used to change any of these files. Whenever any content in the / proc file system, you should use the echo command, and then redirect the output redirection to / proc from the file. For example: echo "Your-New-kernel-value"> / proc / your / file is similar, if you want to view the information in / proc, you should use commands for this use, or use the CAT command under the command line. Change what should be well used / proc does not require you a kernel master, just understand the structure of this file system, you can greatly help you. Until one day users ask you some specific features, I am very happy to have learned to make changes, and you may think it is necessary to know anything about / proc. In this regard, the / proc file system helps system administrators through its structure and document permissions. Each file in Proc has a set of very special file permissions allocated to it, and each file is a specific user ID. This is achieved very carefully to provide the correct functionality to administrators and users. The following list summarizes what specific permissions on each file: read-only: No user can change the file; it is used to represent system information root write: If a file in / proc is written, You can only write root read by root users: Some files are invisible to the general system users, but only others are visible to the root user: For various reasons, you may see three licenses that are different from the above. The combination of rights about / proc, you will find the most common situation, and most of its files are read-only, except / proc / sys directory. Most of the kernel parameters (instead of information) are placed in this directory, and design can be changed while the system is running. So this directory is the main purpose of this article. What is the last point to be understood is to understand what you want to change / proc. When viewing various files in / proc, some files are found to be readable for us, some files are data files. These data files are still readable by using specific utilities (such as TOP, LSPCI, and Free). You will also notice that there are two different formats for us to read them: some are binary switches, and other information is included. The binary switch file contains only 0 (off) or 1 (open) representing a particular kernel function. Make changes in detail the usage and exact information of each file in / proc beyond the ranges involved herein. To get any other information about the / proc file that is not involved in this article, a best source is that the Linux kernel source code itself, which contains some very good documents. For system administrators, the following files in / proc are useful. This doesn't mean it is a detailed description, but is just a reference in everyday use. / Proc / SCSI / PROC / SCSI / SCSI as a system administrator, the most useful content that needs to be understood is that more disk space can be added to how to add more disk space without restarting the system in the case of a heat exchange drive.

If you don't use / proc, you can insert the drive, but in order to identify the new disk, you must re-boot the system. Here, the following command can be used to identify the new drive: Echo "SCSI Add-Single-Device Wxyz"> / proc / scsi / SCSI is the normal operation of the command, and must specify the correct parameter value W, X, Y and Z as follows: W is the host adapter identifier, 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 identity Z is the LUN number, When the first LUN is zero (0), once the disk is added to the system, you can poured any previously formatted file system, or it can begin formatting it. For example, if you do not determine which device is device, or want to check any previously existing partitions, you can use commands such as fdisk -l to report this information. Conversely, the command removed from the system without rebooting the system is: echo "scsi remove-desi-device wxyz"> / proc / scsi / scsi in the input this command and heats the heat SCSI disk from Before removing the system, make sure you first remove 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 assigned. If the user gets the error message declares that since the number of open files has reached the maximum, they cannot open more files, they may need to increase this value. This value can be set to have any multiple files and can change this value by writing a new digital value to the file. Default setting: 4096 / proc / sys / fs / file-nr This file is related to file-max, it has three values: the maximum number of file handles of the number of file handles has been used, the file is read-only , Only for display information. / proc / sys / fs / inode- * Any operation performed by a file starting with the name "Inode" is the same as the operation performed on the name of the name "file", but the operation performed is related to the index node. And independent of the file handle. / proc / sys / fs / overflowuid and / proc / sys / fs / overflowgid These two files saves the user ID (UID) and Group ID (GID) of any file system that supports 16-bit user ID and group identity. These values ​​can be changed, but if you really feel that you need this, you may find that the change group and password file item are easier. Default Settings: 65534 / Proc / Sys / FS / Super-Max This file specifies the maximum number of hyper block handlers. Any file system that is hung needs to use a super block, so if a large number of file systems are hung, you may use the super block handler. Default Settings: 256 / Proc / Sys / FS / SUPER-NR This file displays the number of currently allocated super blocks. This file is read-only and is only used to display information.

/ proc / sys / kernel / proc / sys / kernel / acct This file has three configurable values, depending on the number of available spaces on the file system containing the log, these values ​​are controlled when the value is started to perform process accounting: If the available space is lower than this percentage, stop process accounting If the available space is higher than this percentage value, the start process account checks the frequency (in seconds) of the above two values ​​to change a certain value of this file. A string of numbers separated by spaces should be returned. Default setting: 2 4 30 If only less than 2% of the available space containing the log file, these values ​​will stop the billing, if there is 4% or more free space, start the bill again. Take a check every 30 seconds. / proc / sys / kernel / ctrl-alt-del This file has a binary value that reacts when receiving the Ctrl Alt Delete button combination. These two values ​​indicate that zero (0) value indicates capture Ctrl Alt Delete and send it to the init program. This will allow the system to close and restart perfectly, just like you enter the shutdown command.壹 (1) value means that Ctrl Alt Delete will not capture, will perform non-clean off, just close the power directly. Default Settings: 0 / Proc / Sys / Kernel / DomainName This file allows you to configure network domain names. It has no default, perhaps the domain name has been set, maybe there is no setting. / proc / sys / kernel / hostname This file allows you to configure the network hostname. It does not have a default, may have set a host name, and may not be set. / proc / sys / kernel / msgmax This file specifies the maximum length of messages sent from one process to another. The message delivery between the processes is performed in the memory of the kernel. It is not swapped onto the disk, so if this value is added, the amount of memory used is added. Default setting: 8192 / proc / sys / kernel / msgmnb This file specifies the maximum number of bytes in a message queue. Default setting: 16384 / proc / sys / kernel / msgmni This file specifies the maximum number of message queue identifiers. Default setting: 16 / proc / sys / kernel / Panic This file indicates that the kernel wait for the time (in seconds) before the kernel is retracted. Zero (0) Second Settings will prohibit reboot when the kernel is seriously incorrect. Default Settings: 0 / Proc / Sys / Kernel / Printk This file has four numeric values, which defines where it will be sent according to the importance of logging messages. For more information on different log levels, please read the Syslog (2) Online Help page. The four values ​​of the file are: Console Log Level: Messages above this value will be printed to the console default message log level: the priority will be used to print the minimum message without priority messages Log Level: Console Log Level You can set the minimum (highest priority) default console log level: Console log level default default defaults: 6 4 1 7 / proc / sys / kernel / shmall This file is the total amount of shared memory (in bytes) on any given time system.

Default Settings: 2097152 / Proc / Sys / Kernel / SHMAX This file specifies the size of the maximum shared memory segment allowed by the kernel (by byte). Default Settings: 3355432 / Proc / Sys / Kernel / SHMMNI This file represents the maximum number of interrogation segments for the entire system. Default setting: 4096 / proc / sys / kernel / sysrq If the value specified by the file is non-zero, activate System Request Key. Default Settings: 0 / Proc / Sys / Kernel / Threads-Max This file specifies the maximum number of threads that the kernel can use. Default setting: 2048 / proc / sys / net / proc / sys / net / core / message_burst Write a new warning message (in 1/10 seconds); other warnings received during this time The message will be discarded. This is used to prevent certain attempts from "drowning" Denial of Service) of your system. Default setting: 50 (5 seconds) / proc / sys / net / core / message_cost This file has a cost value associated with each warning message. The larger the value, the more you want to ignore the warning message. Default setting: 5 / proc / sys / net / core / netdev_max_backlog This file is specified, and the rate of receiving the packet at the interface is faster than the kernel, allowing the maximum number of packets to the queue. Default setting: 300 / proc / sys / net / core / optMEM_MAX This file specifies the size of the maximum buffer allowed for each socket. / Proc / Sys / Net / Core / RMEM_DEFAULT This file specifies the default value (in bytes) of the receiving socket buffer size. / proc / sys / net / core / rmem_max This file specifies the maximum value of the receiving socket buffer size (in bytes). / Proc / Sys / Net / Core / WMEM_DEFAULT This file specifies the default value of the send socket buffer size (in bytes). / proc / sys / net / core / wmem_max This file specifies the maximum value of the transmit socket buffer size (in bytes). / Proc / Sys / Net / IPv4 All IPv4 and IPv6 parameters are recorded in the kernel source code document. See File /usr/src/linux/documentation/neetworking/ip-sysctl.txt. / Proc / Sys / Net / IPv6 with IPv4. / Proc / Sys / VM / Proc / Sys / VM / BUFFERMEM This file controls the number of entire system memory for buffer memory (represented by percentage). It has three values ​​that set these three values ​​by writing a series of numbers separated by spaces. The minimum percentage of memory used for buffers If there is not much memory in the event, and the system memory is reducing this, the system will attempt to maintain the number of buffers memory. Maximum percentage default setting for buffer: 2 10 60 / proc / sys / vm / freepages This file control system should deal with all levels of available memory. It has three values ​​that set these three values ​​by writing a series of numbers separated by spaces. If the number of available pages in the system reaches the minimum, only the kernel is allowed to assign some memory. If the number of available pages available in the system is lower than this limit, the kernel will be swapped in a relatively active manner to release memory, thereby maintaining system performance. The kernel will try to keep this quantity of system memory available. The kernel exchange will be started below this value.

Default setting: 512 768 1024 / Proc / Sys / VM / KSWAPD This file control allows the kernel to exchange memory. It has three values ​​that set these three values ​​by writing a string of numbers separated by spaces: the number of kernel tested a maximum number of pages released at a time. If you want to increase the bandwidth during the memory switch, you need to add this value. The core attempts to release the minimum number of pages in each switch. The number of kernels written in a swap. This has the greatest impact on system performance. The greater this value, the more data exchanged, the less the time spent on the disk. However, this value will affect system performance due to the "drowning" request queue. Default setting: 512 32 8 / proc / sys / vm / pagecache This file is the same as the work content of / proc / sys / vm / buffermem, but it is a memory mapping and general cache for files. Make kernel settings have persistent here to provide a convenient utility for changing any core parameters in / proc / sys directory. It allows you to change the kernel in the run (similar to the Echo and redirection method used above), but it also has a configuration file that is executed when the system boot. This allows you to change the kernel in the run and add these changes to the configuration file to facilitate these changes to take effect after the system reboots. This utility is called Sysctl, in the SysctL (online help page, the complete documentation for this utility is a complete document note. Sysctl configuration file is /etc/sysctl.conf, editing the file, and in sysctl.conf The file is recorded. Sysctl regards the files under / proc / sys as a single variable that can be changed. So, with / proc / proc / sys / fs / file-max as an example, it represents the system The maximum number of file handles allowed, this file is represented as fs.file-max. This example reveals some wonderful things in the sysctl representation. Since SysctL can only change the variables in / proc / sys directory, and people always It is considered that the variable is in this directory, so the portion of the variable name (/ proc / sys) is omitted. The other to explain is that the directory separator (forward slash /) is replaced with the number in English (point .). Convert files in / proc / sys to the variables in sysctl have two simple rules: Remove the front section / proc / sys. Turn the front slope in the file name. These two rules make you Can convert any file names in / proc / sys into any variable name in SysctL. General file to variable translation to: / proc / sys / div / file -> Dir.File Dir1.dir2.file - -> / file / sys / dir1 / dir2 / file You can use the command sysctl -a to view all variables that can be changed and their current settings. Use sysctl to change variables, which work is exactly the same as the ECHO methods used above. Its representation is: SYSCTL -W DIR.FILE = "VALUE" or uses file-max as an example, use one of the following two methods to change this value to 16384: sysctl -w fs.file-max = "16384 "Or: echo" 16384 "> / proc / sys / fs / file-max Don't forget that sysctl will not add the changes to the configuration file; this will be done with manual. If you want to reboot, The changes you have done before, you must maintain this profile. Note: Not all distributed versions provide SYSCTL support.

If your specific system belongs to this, you can add these commands to the startup script with the ECHO and redirecting methods described above, so that the system will execute them each time you boot. Commands for setting the system change other non-kernel system parameters while the system is run, and these settings are possible without rebooting the system. This approach is possible. Files containing these parameters are listed in the /etc/init.d directory, which is primarily classified by service, daemons, and servers. Since more and more scripts can be listed in this directory, it is impossible to discuss all various configurations. However, some examples are listed below, discuss how to operate the scripts under /etc/init.d on different Linux distributions. The example here may be useful, discussed to change the daemon, then reload the configuration without rebooting the system: Change the web server configuration, then reload the Apache to remove unwanted inetd login service operation network settings via NFS Export a new file system start / stop the firewall First, the common method is to operate the system service directly through the script in /etc/init.d. These scripts use parameters to operate the services; you can view what valid options can be viewed by entering the script but without any parameters. Common parameters are: Start: Start the stopped service Stop: Stop the running service RESTART: Stop the running service, then restart the service; it will start the stopped service Reload: without interruption any connection , Reload the service configuration status: Report service is running, or stopped, for example, the following command will reload the xinetd configuration without terminating any connected user sessions (if you change / etc / Xinetd.conf, then this command is useful): /etc/init.d/xinetd Reload Red Hat provides service, which allows you to operate. The function provided by the service command is the same as the input feet. Its syntax is as follows: Service Script-name [parameter], for example: Service Xinetd Reload Suse also provides a command named RC. This command is similar to the above service command, but there is no space between the command and the script name. Its syntax is as follows: RC {script-name} Parameter For example, Rcapache Start is similar to that changed kernel parameters. Once the system is rebooted, the changes to these services will be lost. Nowadays, more and more distribution are beginning to use the chkconfig command, which manages services that are started at various run levels (including boot). When writing this article, the syntax of the chkconfig command is slightly different due to the version of the Linux version, but if the input does not have any parameters, a list of how to use this command is displayed. You can also find more information about ChkConfig by Chkconfig. End language Using / Proc file system Real-time Configuring Linux kernel is not a relaxed thing, however, once the structure of the file system, and master how to operate With a file and parameters, you have a powerful tool that allows your server to be available at any time. Thank you very grateful to the proofreading of Adrian Fewings.

转载请注明原文地址:https://www.9cbs.com/read-117453.html

New Post(0)