How to Make Service Start on Boot Linux ?

Source: Internet
Author: User
Keywords how to make service start on boot linux linux service start on boot linux systemd service start on boot
One, linux system operating level
Before introducing the service self-start, let's first understand the run level of the Linux system. There are 7 run levels in the Linux system, from 0 to 6. The system defaults to run at level 3 (id: 3: initdefault:).
Alibaba Cloud Simple Application Server:  Anti COVID-19 SME Enablement Program
$300 coupon package for all new SMEs and a $500 coupon for paying customers.

To modify the default run level of the system, you can modify it in vim /etc/inittab (be careful not to set the default run level to 0 or 6, otherwise the system will keep shutting down or restarting once it is turned on)

runlevel

#View system run level

System operating level:

0: shutdown

1: Single user

2: Incomplete multi-user, without NFS service

3: Fully multi-user

4: Not assigned

5: Graphical interface

6: Restart

Two, service and port
How to query the installed services:

(1) Query RPM package installation service

chkconfig --list

#This command can see the self-starting status of all RPM package installation services

(2) Service of source package installation

#View the installation location of the service, generally under /usr/local

(3) Port view

vim /etc/services lists the conventional ports, there are 65536 (from 0 to 65535) in total, of which less than 10,000 are reserved by the system.

To view which services are enabled, use the command netstat -tlunp

# -T: List tcp data

# -U: List udp data

# -L: List the network services being monitored

# -N: Use port number to display service instead of service name

# -P: List the process ID (PID) of the service

# -A: You can see what is being connected

Three, service management
(1) Management of RPM package service (xinetd services are becoming less and less, so I don’t consider it here, the following is for independent services)

There is a default location for the RPM package installation, as follows:

/Etc/init.d/: Start script location

/Etc/sysconfig/: Initialization environment configuration file location

/Etc/: Configuration file location

/Etc/xinetd.cong: xinetd configuration file

/Etc/xinetd/: startup script based on xinetd service

/Var/lib/: data generated by the service

/Var/log/: log location

Launch of independent services:

1./etc/init.d/Independent service name start|stop|status|restart

, Such as: /etc/init.d/httpd start

# This is to start by an absolute path. There are also the same scripts under /etc/rc.d/init.d, and soft links can be used, so it can be /etc/rc.d/init.d/httpd start

2.service independent service name start|stop|status|restart

, Such as: service mysqld status

#Note that service is a unique command of the redhat series, please pay attention when using it

Self-starting of independent services:

Chkconfig --list | grep mysqld 1. chkconfig --list | grep mysqld

#Check whether the auto-start is set (note that it is not whether the service is currently started, but whether it is self-starting at boot time)

Chkconfig --level 2345 mysqld on

#Set self-starting, 2345 represents the operating level of the system, that is, set it to start automatically at level 2345, and --level can be omitted

Chkconfig --level 2345 mysqld off

#Set at the 2345 level to not start automatically

2. Modify the /etc/rc.d/rc.local or /etc/rc.local file and add the startup script

3. Use the ntsysv command to manage auto-start (this is an interface, essentially the same way as chkconfig in 1)

(2) Management of source code package service

The start of the source code package service:

1. Use the absolute path and call the startup script to start. Different source code packages have different startup scripts. You can check the installation instructions of the source package and check the method of starting the script.

, Such as: /usr/local/apache2/bin/apachectl start|stop

2. Let the source code package service be recognized by service management commands (that is, I want to start it with service or ntsysv)

For example, let the apache service of the source package be started by the service command management (soft link the start command to init.d)

Ln -s /usr/local/apache2/bin/apachectl /etc/init.d/

You can start it like this: service apachectl start

3. For example, let the apache service of the source package be automatically started by the chkconfig and ntsysv commands

Add the following two sentences in /etc/init.d/apache vim

Chkconfig: 35 86 77

#Specify httpd scripts can be managed by the chkconfig command. The format is chkconfig: run level startup sequence shutdown sequence (first look at cd /etc/rc3.d/, 3 represents the run level, the beginning of s is the start, and the beginning of k is kill. Just make sure that the sequence number does not exist. )

Description: source package apache

#Description, free content

Chkconfig --add apachectl

Chkconfig --list | grep apachectl is there again

Self-starting of the source code package service

Add in vim /etc/rc.d/rc.local

/Usr/local/apache2/bin/apachectl start

2. See the above ------> independent service self-starting 3. For example, let the apache service of the source package be managed by the chkconfig and ntsysv commands to start automatically, and then treat it as an independent service
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.