当前位置:网站首页>11、 Service introduction and port

11、 Service introduction and port

2022-07-06 21:53:00 Lyon-w

Introduction to service management
What is the main function of the server ? Mainly through the network to provide services , such as apache Provide a web service ,mysql Provide a database service ,dns Provide a domain name resolution service ,ftp Provide a file server service ,dhcp Provide an address assignment service and so on .

Classify by function
system service : The object of service · Mainly the system itself and system users .
Network services : Provide corresponding services to clients through the network .( such as web,ftp)

Daemon and Service
daemon: Chinese is the patron saint , The computer is called daemon : The daemon is the program that really provides services . such as web=httpd、httpd Namely web Daemons of 、ftp=vsftpd、dns=named samba=smbd nmbd these d Namely daemon It means .
service: service . It is provided by a daemon .

Server and client :
Client/Server

Relationship between service and port
Distinguish the corresponding relationship between the port numbers of services :
80 httpd
23 telnet
22 sshd
21 vsftpd
53 named(dns)
67 dhcpd
25 smtp(mail)

The port number can be accessed through /etc/services View this file .

Check the running status of the service port
netstat -tlunp | grep 873(xinetd)
lsof -i:873 Check which service is running on this port number

systemd process
1、Systemd Is the system daemon , All system services have Systemd To start the , its PID yes 1, Replace the original CentOS6 Of init.d.
2、Systemd Some administrative commands are provided , It involves all aspects of system management , It includes :systemctl、systemd-analyze、hostnamectl、localectl、 timedatectl、loginctl And other management tools .
3、systemd The service will be resident in memory , Therefore, the execution speed is relatively fast , And realize the parallel service startup , It solves the problem of service dependency .

systemctl command
systemctl yes Systemd Main command of , Used to manage system and service status
systemctl poweroff # System shutdown
systemctl reboot # Reboot

Unit
Systemd Can manage all system resources . Different resources are collectively called Unit( Company ).
unit type
Unit In all 12 Types :
Type meaning Service unit system service Target unit Multiple Unit A group of Device Unit Hardware device Mount Unit Mount point of file system Automount Unit Auto mount point Path Unit File or path Scope Unit Not by Systemd External process started Slice Unit Process group Snapshot UnitSystemd snapshot , Can switch back to a snapshot Socket Unit Communication between processes socketSwap Unitswap file Timer Unit Timer

unit management
grammar :systemctl An admin command unitname Management command description status Check the status start Turn on stop close restart restart reload Load profile enable Boot up disable Turn off startup is-active Check whether the service status is started is-enabled Check whether the service starts automatically list-dependencies 【unitname】 View unit dependencies mask No service , Unable to start or boot start-up unmask relieve mask

Single unit Status view
command :systemctl [command] [unit]
command It mainly includes :
status: This is the one I'm going to connect to right now unit The state of , It will list if there is any execution in progress 、 No by default when starting up 、 Login and other information .
is-active : Is it running at present
is-enable : Do you want to enable this by default when you power on unit
is-failed: Start failed unit
show: Show a certain Unit All the underlying parameters of

status According to the unit State type
Loaded Is the state of the next boot , There are several basic states :
enabled: This daemon Will be executed at boot time
disabled: This daemon It will not be executed at boot time
static: This daemon You can't start it yourself (enable must not ), But it may be used by others enabled To wake up ( Dependent services )
mask: This daemon Can't be started anyway , Because it has been forced to log off ( Not deleted ). It can be done by systemctl unmask Change the mode back to the original state .
Active It's the current state , There are several basic states :
active (running): It means that one or more programs are executing in the system , for instance , In the process of implementation vsftpd That's the pattern . active (exited): A service that ends normally only once , At present, there is no program executing in the system .
active (waiting): In the process of implementation , But wait for other events to continue processing .
inactive: This service doesn't mean to run at present .

All of the current system unit state ( understand )
systemctl list-units # List running Unit
systemctl list-units --all # List all Unit, Including not finding the configuration file or failed to start
systemctl list-units --all --state=inactive # List all the Unit
systemctl list-units --failed # List all the... That failed to load Unit
systemctl list-units --type=service # List all running 、 The type is service Of Unit

View Service Dependencies ( understand )
systemctl list-dependencies [unit] # List unit rely on
systemctl list-dependencies --all [unit] # Expand to show dependencies
systemctl list-dependencies [unit] [--reverse] # Reverse query depends on ,unit By whom

Target
When you start the computer , A lot of... Needs to be activated Unit. If every start , It is necessary to write down what is needed for this startup one by one Unit, It's obviously very inconvenient .Systemd The solution Target.
In short ,Target It's just one. Unit Group , Contains many related Unit . Start something Target When ,Systemd It's going to start all of the Unit. In this sense ,Target This concept is similar to " Status point ", Start something Target It's like starting to a certain state .
Conventional init In startup mode , Yes RunLevel The concept of , Follow Target It's very similar . The difference is ,RunLevel They are mutually exclusive. , There can be no more RunLevel At the same time to start , But many Target It can start at the same time . for example
Default start graph tatget, This target It depends on multi-user.target Others, such as target.

target management
$ systemctl list-unit-files --type=target # View all of the current system Target
$ systemctl list-dependencies multi-user.target # View one Target All that is included Unit
$ systemctl get-default # View the default at startup Target
$ sudo systemctl set-default multi-user.target # Set the default at startup Target
$ sudo systemctl isolate multi-user.target # Switch Target

common target
graphical.target: It's text plus graphical interface , This project has included the following
multi-user.target. multi-user.target: Plain text mode .
rescue.target: When you can't use root When logging in ,systemd An additional temporary system will be added when starting up , It has nothing to do with your original system .
emergency.target: Emergency handling system error , Still need to use root The landing situation , When you can't use rescue.target when , You can try this pattern .
shutdown.target: Is the process of shutdown .
getty.target: You can set how many... You need tty And so on. , If you want to reduce tty Project , You can modify this configuration file .

Target And Tradition RunLevel Connection and difference of
Tradition Runlevel target name -> Soft link
Runlevel 0 runlevel0.target -> poweroff.target
Runlevel 1 runlevel1.target -> rescue.target
Runlevel 2 runlevel2.target -> multi-user.target
Runlevel 3 runlevel3.target -> multi-user.target
Runlevel 4 runlevel4.target -> multi-user.target
Runlevel 5 runlevel5.target -> graphical.target
Runlevel 6 runlevel6.target -> reboot.target

systemd And init The main differences in the process are as follows ( understand )
1. default RunLevel( stay /etc/inittab File settings ) Now it's the default Target replace , Location is /etc/systemd/system/default.target, Usually symbols are linked to graphical.target( The graphical interface ) perhaps multi-user.target( Multi user command line ).
2. Where to start the script , It used to be /etc/init.d Catalog , Symbols link to different RunLevel Catalog ( such as /etc/rc3.d、/etc/rc5.d etc. ), Now it's in /lib/systemd/system and /etc/systemd/system Catalog .
3. The location of the configuration file , before init The configuration file for the process is /etc/inittab, Configuration files for various services are stored in /etc/sysconfig Catalog . Now the configuration files are mainly stored in /lib/systemd Catalog , stay /etc/systemd Changes in the directory can override the original settings .

原网站

版权声明
本文为[Lyon-w]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061335374791.html