Linux system service Classifications
Generally divided into two categories, self-initiated services and super services.
1, Stand_alone: This daemon can start the service on its own.
2, Super daemon: A special daemon to unify the management.
Service-to-port correspondence
The network service provided by the system usually corresponds to the port and can be viewed in the file/etc/services for each service and port.
To view the FTP port number in the file:
FTP 21/tcpftp 21/udp FSP fspd
Daemon startup script and startup mode stand alone startup mode
The startup script for the service is in the/ETC/INIT.D directory, which is a directory of links, and the actual directory is/ETC/RC.D/INIT.D. The script inside will detect the environment, find the configuration file, and some other preparations, and then invoke the service program. It is generally called in the following form, and command corresponds to the shell script in the/ETC/INIT.D directory:
Command (Start|stop|status)
such as viewing the status of the FTP service:
[Email protected] init.d]#/vsftpd statusvsftpd is stopped
As mentioned above, VSFTPD is a shell script in the/ETC/INIT.D directory.
In addition to starting, stopping, and viewing the service in this way, Linux also provides a shell script: service.
So the status of the FTP service can also be viewed in the following ways:
[Email protected] init.d]# service VSFTPD STATUSVSFTPD is stopped
The service script looks for the shell script specified by the first parameter in the/ETC/INIT.D directory, then invokes the shell script and takes the second argument as a parameter to the shell script. In fact, the quality is the same as the above method of invocation. The implementation details of the service script can be viewed in detail.
Super Daemon Start-up mode
In fact Super Daemon itself is a stand alone service (by default, XINETD is not installed. ), and then manage other services based on the configuration file of the service it manages.
Its managed service profile is in the/ETC/XINETD.D directory, and the default configuration file is in/etc/xinetd.conf.
For example, to start the Rsync service managed by xinetd, modify the file/etc/xinetd.d/rsync and change the Disable=yes to Disable=yes:
# default:off# description:the rsync server is a good addition to an FTP server, as it # allows CRC Checksumming etc . Service rsync{ disable = no flags = IPv6 socket_type = Stream Wait = no user = Root Server =/usr/bin/rsync Server_args =--daemon log_on_failure + = USERID}
Then restart XINETD:
Service xinetd Restart
Set up the service immediately after booting. We first understand how the Linux host is turned on: 1, turn on the computer power, start to read the BIOS and the host self-test; 2, through the BIOS to obtain the first bootable device, read the main boot area (MBR) to get the boot loader; 3. By starting the loader setup, get kernel and load the memory and detect the system hardware; 4. The kernel actively calls the INIT process, 5. The init process starts to perform system initialization (/ETC/RC.D/RC.SYSINIT); 6. Daemonstart (/etc/rc.d/rc[0-6].d/*) According to the settings of INIT, 7, load native settings (/etc/rc.d/rc.local).
From the above steps, we only need to modify the service in the RC[0-6].D directory to set up the service boot. Chkconfig: Setting up system services conveniently, Linux provides a command to manage system services by default boot or not: Chkconfig
Chkconfig [--level [0123456]] [service name] [On|off]
For example: We set the VSFTPD service to boot from
[Email protected] init.d]# chkconfig--level 3 vsftpd on [[email protected] init.d]# Chkconfig--list | grep vsftpdvsftpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
As you can see, the VSFTPD will start automatically when the run level is 3. For 0-6 different operating levels, there are/etc/rc.d/rc[0-6].d corresponding to them. In each directory, files that have s or K begin, point to the/etc/rc.d/init.d/* directory. s stands for start, K for stop. When the system starts, the/ETC/RC.D/RC script is called to execute the script under different directories: 1, according to different runlevel, call different RC[0-6].D directories; 2, find/etc/rc.d/rcn.d/k?? * Start the file and proceed with "/etc/rc.d/rcn.d/k??" *stop "operation; 3, find/etc/rc.d/rcn.d/s?? * Start the file and run "/etc/rc.d/rcn.d/s"?? *start "operation. For example, the files in the corresponding RC3.D directory have changed after the VSFTPD has been set up above:
[Email protected] init.d]# Ls-l/etc/rc.d/rc3.d/| grep vsftpdlrwxrwxrwx. 1 root root 13:25 s60vsftpd. /init.d/vsftpd
Chkconfig: Setting up your own system service requires creating a new shell script in the/ETC/INIT.D directory and then executing the chkconfig command to add the directory to the Chkconfig managed service.
[[email protected] init.d]# chkconfig [--add|--del] [service name] parameter:--add: Add a service name to Chkconfig to manage, the service name must be in the/etc/init.d/ Inside--del: Delete a service for chkconfig management
Specific examples can focus on subsequent memcached service-initiated blogs.
Understanding Linux System Services (daemons)