[Switch] CentOS setting program to start automatically at boot

Reprinted from: http://www.centos.bz/2011/09/centos-setup-process-startup-boot/

In the CentOS system, there are two main ways to set the program installed by yourself to start up.
1. Add the command to start the program to the /etc/rc.d/rc.local file. For example, the following is to set the boot to start httpd.

copy code
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
/usr/local/apache/bin/apachectl start
copy code

2. Add the written startup script to the directory /etc/rc.d/init.d/, and then use the command chkconfig to set the startup.

chkconfig function description: check and set various services of the system.

Syntax: chkconfig [--add][--del][--list][system service] or chkconfig [--level <level code>][system service][on/off/reset]

--add add service

--del delete service

--list View the startup status of each service

For example, we set up self-starting mysql:

copy code
1 # Put the mysql startup script into the directory where all scripts are run /etc/rc.d/init.d 2 cp /lamp/mysql-5.0
 . 41 /support-files/mysql.server /etc/rc.d/init . d/ mysqld
 3 4 #Change permissions
 5 chown root.root /etc/rc.d/init.d/ mysqld
 6 7 #All users can execute, only root can modify
 8 chmod 755 /etc/rc.d/init .d/ mysqld
 9 10 #Put mysqld into the linux startup management system
 11 chkconfig -- add mysqld
 12 13 #Check the status of all services at each run level
 14 chkconfig -- list mysqld
 15 16  
   
    
  
  
 #As long as runlevel 3 is started, others are closed
 17 chkconfig --levels 245 mysqld off
copy code

For example: we write the httpd script and put it in the /etc/rc.d/init.d/ directory, use

chkconfig --add httpd
chkconfig httpd on

The command is set to start up.

 

3. Add the command to start the program to the /etc/rc.d/rc.sysinit file

 

The script /etc/rc.d/rc.sysinit completes the startup of system service programs, such as setting system environment variables, setting system clock, loading fonts, checking and loading file systems, generating system startup information log files, etc.

 

For example, we set up self-starting apache:

echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326341990&siteId=291194637