Automatic NFS startup and Its Principle
The NFS server has been configured, but we need to restart the NFS service after the machine restarts. To avoid this problem, we need to enable the NFS and portmap services to automatically start at startup, so as to avoid errors such as mount clntudp_create: RPC: Program not registered. To enable the script to run automatically at startup, you need to understand the linux Startup Process. We know that the first program to run after the system loads the kernel is init, so its PID will always be 1. You can view it by using the top command; the init program first needs to read the/etc/inittab file, and the init program will create the process according to the content of the file in order. Www.2cto.com open this file, regardless of the comments starting with #. There are seven parts: the first part and the second part.
The Init program first reads the first part and determines the shell Running level. The running level here is 3. Shell has a total of 7 running levels. The comments at the beginning of the/etc/inittab file explain the seven running levels in detail, if you are not familiar with shell Running, this is a must-have view. Then the init program reads the second part and runs the script/etc/rc. d/rc. sysinit, which mainly contains the system initialization command. Next, you need to run the scripts in the corresponding directory according to the determined shell Running level to start related services. The running level of my machine is 3, and init runs the script in the/etc/rc. d/rc3.d directory according to this level number. The remaining parts are about the key combination and UPS power supply. If you are interested, take a look. Here we know that the init program starts the script in the corresponding directory in the/etc/rc. d directory based on the running level number to start related services. Run the script in the/etc/rc. d/rc3.d directory. If the running level is 5, run the script in the/etc/rc. d/rc5.d directory. Let's take a look at the files in the/etc/rc. d directory.
The/etc/rc. d directory contains three common files and eight directory files. Init. the d directory is the directory where various programs and scripts are stored, while the files from rc0.d to rc6.d are init. the link file of the program file in the d directory is assigned to the corresponding running level. Let's take a look at the files in the/etc/rc. d/rc3.d directory:
The NFS service and portmap service that we want to start upon startup are in the first row of the second column and the third row of the last column in the image, namely, K20nfs and S13portmap. Www.2cto.com we can see that all the files in the directory start with K or S, and then follow a number, then the file name. What does this mean? S is the start, the service is enabled, K is the kill, and the service is disabled. After the system determines the running level, enter the corresponding rcN. d directory, execute the files starting with S to enable the relevant service process, and execute them in sequence according to the number after S. when changing the running level, the script starting with K is executed first, and then the script starting with S is executed in the order of numbers following them. When you exit the system, execute the files starting with K in sequence to close related services. Now we know that at the running level 3, the nfs service is not started with startup by default, while the portmap service is started with startup, the nfs service is 13th enabled by the system. After we manually start the nfs service, the nfs service is 20th disabled when it is shut down. I have a question: what is the order of enabling and disabling these services? The answer is the program itself. We can open the script for portmap and nfs service to check that the script path is/etc/rc. d/init. d/portmap (nfs ). Enter the command: less/etc/rc. d/init. d/portmap (nfs)
As shown in, the portmap service runs at the 345 level. The activation sequence is 13th and the closing sequence is 87th. the nfs service is not enabled at any running level, and the enabling sequence is 60th, the closing order is 20th. (When the service is not started at any running level, the field of the running level is replaced .) Obviously, to enable the NFS service automatically, you need to change the nfs service status from K to S in the rcN. d directory corresponding to the corresponding level. When the running level is 2, the system does not run NFS. Therefore, we only need to enable the NFS service at the 3, 4, and 5 levels. (Level 4 is not enabled at all, so that the NFS service is enabled on Level 4 without knowing how to use it. However, if everyone says so, I will follow the big stream .) How can I change www.2cto.com? The system provides a convenient method to use: Use the chkconfig command. Chkconfig is mainly used to query and manage the activation of services at different running levels. Note that the chkconfig command does not change the content in the script, but only changes the program in rcN. d. Enter the chkconfig command and press Enter. You can see that it has four main functions:
Chkconfig -- list name lists the running levels of the specified service. Chkconfig -- add name adds a service Chkconfig -- del name to delete a service Chkconfig [-- level <levels>] <name> <on | off | reset> to change/reset the running level of the specified service, enter chkconfig -- level 345 nfs on, you can enable the NFS service to run automatically at the running level 3, 4, and 5.
Author: zhl_shanghai