Chapter 4 Service Management and Chapter 4 Service

Source: Internet
Author: User

Chapter 4 Service Management and Chapter 4 Service

Directory:

11.1 service concept

11.2 manage independent daemon

11.3 automatic start of Management Service

11.4 managing xinetd and related instantaneous daemon

11.5 CentOS 7 Management Service

CentOS 7 and CentOS 6 manage services in different ways. This document describes the management methods on CentOS 6 and the service management methods on CentOS 7.

11.1 service concept

A service is a process that provides external services. Generally, services are stored in the background. To continuously provide external service requests at any time, the service process must be resident in the memory, it should not be related to the terminal; otherwise, the terminal exits after exiting the service program. In addition, to receive external requests to provide external services, you need to have a "service window" dedicated to this service, which is the port number, you can find the service provider by using the port number.

One end of the service is called the server, and the client that requests the service from the server is called. First, the server starts the service process and the corresponding port number is opened. Then, the client specifies the Server IP address and port number to send a request to the server. The kernel of the server receives the request packet, then, analyze the data packet and find that the request is a certain port number. The kernel knows which application listens to the port number, so send the request message to the corresponding application. After the application receives the message, connect to the client and transmit data.

In addition, it should be noted that not all services always provide port numbers. For example, the xinetd service takes over the corresponding port only when necessary, for example, when the rsync listening port is 222, when rsync is requested, the port number of xinetd during the listening process is 222. Xinetd does not have a port number when it is not requested.

 

In Linux, services are divided into independent daemon and super daemon processes. Independent daemon monitors the backend by itself. Basically, all services are independent daemon services. The super daemon refers to the xinetd service, which manages some special services on behalf of it. When such services are requested, xinetd will notify it to start the service, after a service is provided, the service is shut down. Such a service is called an instantaneous daemon, that is, it only exists in the instantaneous state.

However, you must understand that the super daemon xinetd itself is an independent daemon with resident memory because it needs to listen to requests from the instantaneous daemon processes managed by the outside. Generally, xinetd does not occupy the port number when it is not working. during work, xinetd occupies the port number of the requested instantaneous daemon and is in the listening status.

11.2 manage independent daemon

On CentOS 6, all service scripts are in the/etc/rc. d/init. d/directory, and/etc/init. d/is its soft link. All scripts in this directory are LSB-style scripts, which can basically accept parameters such as start, stop, restart, reload, and status.

[root@xuexi tmp]# ls /etc/init.dabrt-ccpp         cpuspeed   irqbalance    messagebus  psacct       saslauthdabrtd             crond      kdump         netconsole  quota_nld    singleabrt-oops         functions  killall       netfs       rdisc        smartdacpid             haldaemon  lvm2-lvmetad  network     restorecond  sshdatd               halt       lvm2-monitor  ntpd        rngd         svnserveauditd            ip6tables  mcelogd       ntpdate     rsyslog      sysstatblk-availability  iptables   mdmonitor     postfix     sandbox      udev-post

Manage independent daemon services

/Etc/init. d/service_name restart | start | stop | status # method 1 service service_name restart | start | stop | status # method 2

To enable the service to be managed by service commands, place the service scripts in the/etc/init. d directory.

11.3 automatic start of Management Service

The chkconfig command can manage services that exist in the/etc/init. d/directory and the script content meets certain conditions.

To enable chkconfig to manage whether the service is automatically started when it is started, you only need to place the script in the/etc/init. d directory, and then add the chkconfig line and description line at the front of the script. For example:

#!/bin/bash# chkconfig: - 85 15# description: The Apache HTTP Server is an efficient and extensible

The two rows must be in front of all non-Annotated rows, and the two rows must be "commented ". The chkconfig line "-" indicates that it is applicable to running level 123456, and 85 indicates that when the instance is started, its starting sequence is, which indicates that when the instance is shut down and the service is stopped, its Stopping sequence is 15. You can give a description to the description line, but you must give the "description:" keyword.

Then, you can have chkconfig to manage the service startup.

Chkconfig [-- add | -- del] <name> # Set/etc/init. d. You can add the services managed by chkconfig to the chkconfig management list, or delete chkconfig [-- list] [name] # From the list to list information about the services with the specified name. Name can use all to list all services in the chkconfig management list. The chkconfig [-- level <levels>] <name> <on | off | reset> # list services with the specified name at the specified level. enable or disable the auto-start function. # Resetting indicates resetting to the level specified in the script

Of course, in addition to chkconfig, you can manage Automatic startup, and put the startup command in the/etc/rc. d/rc. local file.

11.4 manage xinetd and related instantaneous daemon 11.4.1 manage instantaneous daemon

This type of service cannot be started directly using the service command. You can only set it in the corresponding file in the/etc/xinetd. d/directory (of course, you can also configure it in/etc/xinetd. conf) and then manage it by xinetd.

First install the xinetd program.

[Root @ xuexi tmp] # yum-y install xinetd [root @ xuexi tmp] # chkconfig -- list ...... omit xinetd 0: off 1: off 2: off 3: on 4: on 5: on 6: offxinetd based services: chargen-dgram: off chargen-stream: off daytime-dgram: off daytime-stream: off discard-dgram: off discard-stream: off echo-dgram: off echo-stream: off rsync: off tcpmux-server: off time-dgram: off time-stream: off

First, make sure that xinetd is already working in the background.

service xinetd start

Manage the instantaneous daemon. This type of service is special. Its self-starting status and service running status are synchronized. That is to say, if chkconfig is set to self-starting, the service is started; otherwise, the service is stopped. In addition, the specified level is invalid. Their startup level inherits from the xinetd startup level, and xinetd takes over the port number of the instantaneous daemon triggered by it.

For example, start the instantaneous daemon process rsync.

chkconfig rsync on
11.4.2 configure the instantaneous daemon

The instantaneous daemon is controlled by two configuration files. One is the xinetd configuration file/etc/xinetd. conf provides the default configuration. One is/etc/xinetd. d.

For example, to configure rsync, the following is the default configuration of/etc/xinetd. d/rsync.

[Root @ xuexi tmp] # vi/etc/xinetd. d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync # defines the rsync service. The name must be the same as/etc/xinetd. d/file with the same name {disable = yes # yes indicates not to start, no indicates to start, equivalent to chkconfig rsync {on | off }, therefore, the setting will take effect directly in chkconfig. flags = IPv6 # et_type = stream # This indicates that the tcp-type socket wait = no # whether the service is single-thread or multi-thread, the format is whether the request that exceeds the limit is waiting, no indicates multi-thread user = root # How to Run rsync server =/usr/bin/rsync # service program server_args = -- daemon # parameter log_on_failure + = USERID # log of connection failure, + indicates that the specified USERID is added to the global corresponding entry}

In addition, there are several options:

[Access control options] do not conflict addresses in the following two control lists. Only_from: defines the access control list for allowed connections, supports single IP address, CIDR format and long mask format network segment, host name hostname, DOMAIN (.abc.com) no_access: defines the list of access not allowed, the syntax format is the same as only_from [listener address] bind = ip_addrinterface = ip_addr # equivalent to bind [resource control] cps = args1 args2instances = Nper_source = N

The meaning of these three options is as follows.

11.5 CentOS 7 Management Service

Service name start => systemctl start name. service

Service name stop ==> systemctl stop name. service

Service name restart => systemctl restart name. service

Service name status ==> systemctl status name. service

 

Check whether the service is activated (running): systemctl is-active name. service

View All activated: systemctl list-units -- type service

View all services: systemctl list-units -- type service -- all

 

Set automatic start upon startup: chkconfig name on ==> systemctl enable name. service

Disable auto start upon startup: chkconfig name off ==> systemctl disable name. service

Check whether the service is automatically started upon startup: chkconfig -- list name => is-enabled name. service

View the Automatic startup status of all services: chkconfig -- list => systemctl list-unit-files -- type service

 

Back to series article outline: http://www.cnblogs.com/f-ck-need-u/p/7048359.html

Reprinted please indicate the source: http://www.cnblogs.com/f-ck-need-u/p/7059321.html

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.