(Transfer) CHKCONFIG management init script with red hat

zhaozj2021-02-16  112

Jimmy ball translation: feng dahui 2002-05-20 14:51:37 another reference document: http://www.freeelamp.com/new/publish/1003237634/index_html

By Jimmy Ball Translation: Feng Dahui fdh@163.net 2001.12.11 A simple but very useful stuff in your management tool. I like to find new UNIX commands, especially those about system management. When I learned the Red Hat released Chkconfig, I remembered the unix variant from Silicon Graphics Inc., CHKCONFIG under IRIX. IRIX's ChkConfig is used to activate the service when the system is initialized, there is no need to edit, rename or move the init script in mobile / etc. Similarly, the purpose of Red Hat design chkconfig is the service that is used to manage system initialization. However, after I read the manual carefully and made some tests, I quickly found the Red Hat expanded CHKCONFIG, and the system task when the symbolic connection to the init script was determined, it is really saving! About started basics When your Linux starts, the first process it displays is init. If you haven't seen the display init process before, enter: # ps -ef | grep init will see the PID of the init. In short, INIT runs / etc / inittab described in the task described. The tasks described in / etc / inittab are started after init, but other tasks are started very simple. For example, by default Red Hat's / etc / inittab sets a trap to the Ctrl-Alt-delete key, when these keys are pressed in the console mode (not XDM), run the shutdown command. When starting, the init is set based on the / etc / inittab setting option, but it will be executed when this key is happened. The format of the inittab allows the notes to start the comment line, and the normal entries are defined by ":". Compliance with the following format: ID: runlevel: action: Process ID Represents user-defined unique flags, Runlevel can make a combination of 0-6 or empty, Action comes from a keyword Keyword Description INIT How to treat Process, Process is to execute command. The various keywords describing the Action field can be found in the inittab manual. Commonly used keywords, not all, UNIX platforms include these: INITDEFAULT - Defines running level Wait, which is entered after a system startup - will be executed once (when entering the run level). The init process will wait for this process to be terminated. Boot - Defines the process that is executed when started. Bootwait - Similar to boot, but init in the termination of the Sysinit waiting for the process before going running Sysinit, defining the process during boot, in front of any boot or bootwait inittab entry carried out. The RunLvel field indicates system status. For example, running grade 0 represents the system shutdown, and the run level 6 represents the system restart. Unfortunate things, not all Linux releases follow the same runtime definition. In Red Hat, by default, these 0. The system hangs 1. However, users SINGLE-User mode 2. Multiuser, no NFS 3. Complete multi-user Complete MultiUser Mode 4. User Custom 5. X11 (XDM) Log in) 6. Restart Each run level has a corresponding directory under /etc/rc.d. Such as running level 5, the directory is /etc/rc.d/rc5.d. Contains the related files of the relevant tasks that start this run level.

In Red Hat, these files are generally a symbolic connection of the shell script, which can be found in /etc/rc.d/init.d. Let's take a simple example to see these things, below these two examples from our inittab file: ID: 3: INitDefault: L3: 3: Wait: /etc/rc.d/rc 3 in the Red HAT system This is typical. Once INIT is started, read / etc / inittab. From the first line, we know that init will run the run level from the run after the system starts. Once we arrived at the run level, the second line tells init to run the script /etc/rc.d/rc 3 and wait for the termination before execution. The RC script of the /etc/rc.d directory receives 3 as a parameter. This 3 is equivalent to running level 3. Result RC Scripts Perform all scripts in the /etc/rc.d/rc3.d directory. It first implements all KILL "Kill" Kill Process or Service) with parameter "STOP", followed, it runs all scripts that are headed by letter S, with parameter "start" launching processes or services. Finally, the execution order of the K and S scripts is based on sorting; the script named S90Mysql will be executed before S95HTTPD. The script in /etc/rc.d/rc3.d is actually a symbolic connection to files in /etc/rc.d/init.d. UNIX administrators can put files in RC3.D, and if the Red Hat's init.d directory is the first location of all scripts, then claims to logically connect to the RC * .d directory. The management of these documents is annoying, trivial. ChkConfig now takes over this thing! Red Hat's CHKCONFIG tool is designed for the symbolic connection in administrative /etc/rc.d/rc[0-6].d. Viewing Chkconfig Item (Entries) Chkconfig's binary software Under / sbin, the default permissions allow any user to execute. But users with no root privileges can only look at the current chkconfig configuration. Input [root] # chkconfig --List | GREP ON output part of the content is as follows: AMD 0: OFF 1: OFF 2: OFF 3: OFF 4: ON 5: ON 6: Off APMD 0: OFF 1: Off 2: On 3: Off 4: ON 5: Off 6: Off ARPWATCH 0: OFF 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off ATD 0: OFF 1: Off 2: Off 3: on 4: ON 5: ON 6: OFF AutoFS 0: Off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off Named 0: Off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Of Off bootparamd 0: Off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off KeyTable 0: Off 1: Off 2: on 3: On 4: on 5: On 6: Off crred 0: Off 1 : OFF 2: on 3: on 4: on 5: on 6: Off Syslog 0: Off 1: Off 2: on 3: on 4: ON 5: On 6: Off Netfs 0: Off 1: Off 2: Off 3 : On 4: on 5: On 6: Off NetWork 0: Off 1: Off 2: On 3: On 4: on 5: On 6: OFF At each line of output, the first paragraph represents in / etc / rc. The name of the init feet in D / Init.d. The rest of the segment indicates the state of each running stage 0-6 of the script into each run stage. For example, Crond should start when entering run levels 2, 3, 4, 5, when entering 0, 1 and 6, stop.

We can use the Find command to find files ending in /etc/rc.d to confine the correctness we set: [root] # Find /etc/rc.d -name '* crond' -Print / etc / rc. D / Init.d / crd /etc/rc.d/rc0.d/k60crond /etc/rc.d/rc1.d/k60crond /etc/rc.d/rc2.d/s40crond /etc/rc.d/ Rc3.d / s40crond /etc/rc.d/rc4.d/s40crond /etc/rc.d/rc5.d/s40crond /etc/rc.d/rc6.d/k60crond Note Each "OFF" reported by ChkConfig Section (0, 1, 6), a KILL script exists Script is in place Each "ON" section (2, 3, 4, 5), there is a START script. Next, execute a different Find command to confine the type of each discovered file: [root] # Find /etc/rc.d -name '* crond' -exec file {}; /etc/rc.d/init .d / crond: bourne shell script text/etc/rc.d/rc0.d/k60crond: symbolic link to ../init.d/crond /etc/rc.d/rc1.d/k60crond: Symbolic Link TO. ./init.d/crond /etc/rc.d: symbolic link to ../init.d/crond /etc/rc.d/rc3.d/s40crond: Symbolic link to ../ Init.d / crd /etc/rc.d/rc4.d/s40crond: symbolic link to ../init.d/crond /etc/rc.d/rc5.d/s40crond: Symbolic link to ../init. D / crd /etc/rc.d/rc6.d/k60crond: symbolic link to ../init.d/crond This indicates that crones found in Init.D are a shell script that found all other files are Connection to the crred script. Adjusting the ChkConfig item Adjusting ChkConfig is almost as easy as the current settings. Format: ChkConfig [--level ] For example, if we decide to prohibit Crond, # chkconfig --level 2 crd Off (execution) is turned off at Run CHKCONFIG. Run Chkconfig --List will make sure that crones have been adjusted. Further, the following Find Command Command displays a KILL script that has been replaced in the directory RC2.D instead of the Start script: [root] # Find /etc/rc.d -name '* crond' -print /etc/rc.d/ INIT.D / crd /etc/rc.d/rc0.d/k60crond /etc/rc.d/rc1.d/k60crond /etc/rc.d/rc2.d/k60crond /etc/rc.d/rc3. D / S40crond /etc/rc.d/rc4.d/s40crond /etc/rc.d/rc5.d/s40crond /etc/rc.d/rc6.d/k60crond keeps ChkConfig is not automatically banned or activated It is just a simple change of the symbolic connection, and the super user can use this command /etc/rc.d/init.d/crond Stop immediately prohibited Crond service.

Finally, you can use a command line to activate / disable a command of multiple runs. For example, CHKCONFIGLELS 2345 CROND ON sets crones to start at run levels 2, 3, 4, and 5. When you delete an item, it is also very appropriate to delete a service. For example, there is no need to import a local account on the client for Sendmail. It is not necessary to run sendmail's most daemon. In this case, I found that it is necessary to prohibit Sendmail services, reducing potential security issues, deleting sendmail from ChkConfig, entering: chkconfig --del sendmail in the following, our Find command shows that there is no symbolic connection, but not Sendmail's init script still has: [root] # find /etc/rc.d -name '* sendmail' -print /etc/rc.d/init.d/sendmail in my opinion this is perfect. The script is retained, in case sendmail needs to be implemented as a service? But all the symbols are connected. We can prohibit Sendmail services in each run level, which will place a kill script in each rc * .d subdirectory, although sendmail starts from the initialization phase, is an unnecessary task, but I have seen some systems. Administrators need to manually start service at a specific occasion. Stay the Kill script to ensure clean service. Add a chkconfig to now, everything goes well, we already know how to use ChkConfig how to view, adjust, and delete the service. Add a new service now. Look at the script below. -------------------------------------------------- - Listing 1. Oracle Script ---------------------------------------------------------------------------------------------------------------------------------- --------- #! / Bin / sh #chkconfig: 2345 80 05 #description: Oracle 8 Server Ora_Home = / usr / home / oracle / product / 8.0.5 ora_owner = Oracle IF [ ! -f $ ora_home / bin / dbstart] Then Echo "Oracle Startup: Cannot Start" EXIT FI Case "$ 1" in "start") SU- $ ora_owner -c $ ora_home / bin / dbstart su- $ ora_owner -c "$ ORA_HOME / BIN / LSNRCTL START ";;" stop ") SU- $ ora_owner -c $ ora_home / bin / dbshut su- $ ora_owner -c" $ ora_home / bin / lsnrctl stop "; esac ------- ---------------------------------------------- Use this script, Oracle 8 can start with the parameter "start" to stop with the "STOP" parameter. It meets the minimum requirement of the init script can be used in combination with the /etc/rc.d/rc script. Put the script in /etc/rc.d/init.d and run (with root): chmod x /etc/rc.d/init.d/oracle makes your script executable. If you are worried about the normal user to see this script, you can set more stringent file permissions.

As long as this script can be run as a separate script as a separate script. Note Two lines in the script: #CHKCONFIG: 2345 80 05 #Description: Oracle 8 Server ChkConfig Requires these lines to determine how to implement the initial run level add service, how to set the priority of the startup and stop order. These rows indicate the script to launch Oracle 8 services for running stages 2, 3, 4, and 5. In addition, the initiation priority will be set to 80 and stop the priority setting to 05. Now the script is in a suitable location, and there is appropriate execution permission, as well as the appropriate ChkConfig comment, we can add the init script, as root, # chkconfig --add oracle. With ChkConfig query, we can verify our added: [ Root] # chkconfig --List | Grep Oracle Oracle 0: Off 1: Off 2: On 3: On 4: On 5: On 6: Off, we can use the standard FIND command to see how ChkConfig sets a symbolic connection: [ ROOT] # find /etc/rc.d -name '* oracle' -print /etc/rc.d/init.d/racle /etc/rc.d/rc0.d/k05racle /etc/rc.d/rc1 .d / k05racle /etc/rc.d/rc2.d/s80Oracle /etc/rc.d/rc3.d/s80Oracle /etc/rc.d/rc4.d/s80OrCle /etc/rc.d/rc5.d / S80Oracle /etc/rc.d/rc6.d/k05oracle is as needed, the name of the KILL connection contains priority 05 and the START connection contains 80. If you need to adjust priority, (e.g. We stop priority needs to be set to 03), simply adjust the CHKCONFIG note line of the Oracle Init script and run the reset command command, as shown below. Symbol connection is renamed: [root] # chkconfig oracle reset [root] # Find /etc/rc.d -name '* oracle' -print /etc/rc.d/init.d/racle /etc/rc.d /RC0.D/K03Oracle /etc/rc.d/rc1.d/k03racle /etc/rc.d/rc2.d/s80racle /etc/rc.d/rc3.d/s80Oracle /etc/rc.d/rc4 .D / s80racle /etc/rc.d/rc5.d/s80racle /etc/rc.d/rc6.d/k03racle Red Hat 7 improvements you may know, inetd in Red Hat 7 has been XINETD replace. Moreover, the function of ChkConfig has been extended to manage some XineTd's Internet service. Examples are as follows: [root] # chkconfig --List ... Xinetd Based Services: Finger: on LinuxConf-Web: Off REEC: OFF RLOGIN: OFF RSH: OFF NTALK: OFF TALK: OFF TELNET: ON TFTP: OFF WU-FTPD : ON to ban a Xinetd service, maybe it, you should enter: [root] # chkconfig finger off. Very simple, huh, huh. However, there is a problem here.

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

New Post(0)