1. Use chkconfig to configure the startup level
In other CentOS or RedHat systems, if services are installed later, such as httpd, mysqld, and postfix, the system will not start automatically after installation. Even if you manually run/etc/init. d/mysqld start to start the service, the system will not start the service automatically after the server is restarted. At this time, we need to set up after installation so that the system can automatically start these services to avoid unnecessary losses and troubles. In fact, the command is very simple, just use chkconfig.
For example, you need to set mysqld to automatically start upon startup:
| The code is as follows: |
Copy code |
|
Chkconfig mysqld on |
To cancel automatic startup of a service, you only need to change the "on" parameter to "off.
For example, to cancel automatic start of postfix:
| The code is as follows: |
Copy code |
|
Chkconfig postfix off |
It is worth noting that if this service has not been added to the chkconfig list, you need to add it using the -- add parameter:
| The code is as follows: |
Copy code |
|
Chkconfig -- add postfix |
To query all the automatically started Services, enter:
| The code is as follows: |
Copy code |
|
Chkconfig -- list |
If you only want to view the specified service, you only need to add the service name after "-- list". For example, check whether the httpd service is automatically started:
| The code is as follows: |
Copy code |
|
Chkconfig -- list httpd
Httpd 0: off 1: off 2: off 3: off 4: off 5: off 6: off |
At this time, 0 ~ If both are off, the httpd service will not be automatically started when the system starts. We enter:
| The code is as follows: |
Copy code |
|
Chkconfig httpd on |
At this time:
| The code is as follows: |
Copy code |
|
Httpd 0: off 1: off 2: on 3: on 4: on 5: on 6: off |
2 ~ If all five are on, it indicates that it will be automatically started.
2. Modify the file/etc/rc. d/rc. local:
Take apache, mysql, samba, svn, and other services as an example:
| The code is as follows: |
Copy code |
|
[Web page creation tutorial]-[http://www.111cn.net]
Vi/etc/rc. d/rc. local
# Add the following command
/Usr/sbin/apachectl start
/Etc/rc. d/init. d/mysqld start
/Etc/rc. d/init. d/smb start
/Usr/local/subversion/bin/svnserve-d |
Example
CentOS sets automatic start of a service. Here we take the sshd service as an example: Check whether sshd is a system service: # chkconfig -- list | grep sshd will display: sshd 0: off 1: off 2: off 3: off 4: off 5: off 6: off www.111cn.net use the following command to set the sshd service to automatically start: # chkconfig -- level 5 sshd on to view it again:
The setting is successful! After the system is restarted, the access is successful using SecureCRT.