Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Startup process and Service Control of Linux system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Blog structure starts 5 stages of Linux shutdown what is daemon and Service (service) profile for service type through systemctl management service Systemctl

one。 Start 5 phases:

The boot of the kernel.

Run init.

System initialization.

Set up the terminal.

The user logs in to the system.

1. Post

After the server host is powered on, the CPU, memory, graphics card, keyboard and other devices will be initially tested according to the settings in the motherboard BIOS. After successful detection, the control of the system will be transferred according to the preset boot sequence, and the local hard disk will be handed over most of the time.

2.MBR boot

When booting the system from the local hard disk, first transfer the system control to the partition containing the operating system boot file according to the setting of the MBR (master boot record) in the first sector of the hard disk, or call the boot menu directly according to the boot information in the MBR record (such as GRUB)

3.GRUB menu

For Linux operating system, GRUB (Unified Boot Loader) is the most widely used multi-system bootstrap program. After system control is passed to GRUB, a boot menu will be displayed for the user to choose, and the Linux kernel file will be loaded according to the selected option (or default), and then system control will be transferred to the kernel. It is important to note that Centos 7 uses the GRUB2 boot loader.

4. Load the Linux kernel

The Linux is a pre-compiled special binary file, which is between various hardware resources and system programs, and is responsible for resource allocation and scheduling. After the kernel takes over the control of the system, it will fully control the running process of the entire Linux operating system. On Centos systems, the default kernel file is "/ boot/vmlinuz-3.10.0-514.el7.x86_64".

5.init process initialization

In order to further boot the system, the Linux kernel first loads the "/ sbin/init" program in the system to run in memory, and the init process completes a series of system initialization processes, and finally waits for the user to log in.

II. Type of init program:

SysV: init, before CentOS 5, configuration file: / etc/inittab. Upstart: init,CentOS 6, configuration file: / etc/inittab, / etc/init/*.conf. Systemd: systemd, CentOS 7, configuration files: / usr/lib/systemd/system, / etc/systemd/system.

three。 Operation level

The Linux system has 7 runlevels (runlevel):

Runlevel 0: system shutdown state, system default runlevel cannot be set to 0, otherwise runlevel 1: single user working state, root authority, for system maintenance, disable remote login runlevel 2: multi-user state (no NFS) runlevel 3: complete multiuser state (with NFS), enter console command line mode runlevel 4: system is not in use Keep the runlevel 5:X11 console, log in and enter the graphical GUI mode runlevel 6: the system shuts down and restarts normally, and the default runlevel cannot be set to 6 Otherwise, six terminals are defined in the following six lines that cannot be started properly in inittab: 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

Users log in to the system

Generally speaking, there are three ways for users to log in:

(1) Command line login (2) ssh login (3) graphical interface login

four。 The switching mode between graphic mode and text mode

The Linux preset provides six command window terminals for us to log in.

By default, we log in to the first window, that is, tty1, and the six windows are tty1,tty2. Tty6, you can press Ctrl + Alt + F1 ~ F6 to switch them.

Sync synchronizes data from memory to hard disk shutdown shutdown instruction shutdown-h now shuts down immediately shutdown-h 20:25 the system shuts down at 20:25 today shutdown-h + 10 is a minute later the shutdown-r now system immediately restarts the shutdown-r + 10 system restarts the reboot restart = = shutdown- R nowhalt shuts down the system the correct shutdown process is: sync > shutdown > reboot > halt whether it is to restart the system or shut down the system The first step is to run the sync command to write the data in memory to disk. The commands for shutdown include shutdown-h now poweroff and init 0 to restart the system, and shutdown-r now reboot init 6 service startup, Shutdown and observation: startup: / etc/init.d/daemon start shutdown: / etc/init.d/daemon stop restart: / etc/init.d/daemon restart status observation: / etc/init.d/daemon status service startup classification: service dependency problem: classification of execution level: setting execution level default service to start: default to start: chkconfig daemon on default does not start: chkconfig Whether daemon off observation is enabled by default: chkconfig-- switching behavior of list daemon execution level: init3  init 5 (pure switch to graphical interface)

five。 What is daemon and Service (service)

(1) systemd has the following advantages:

Parallel processing of all services to speed up the boot process: self-check of on-demand startup mode (systemctl) service dependency in response to request: according to daemon functional classification: unit (service unit) aggregates multiple daemons into a group: downwards compatible with old init service scripts:

(2) configuration file placement directory of systemd

/ usr/lib/systemd/system/: the main startup script settings for each service are somewhat similar to the previous files under / etc/init.d; the service scripts generated during the execution of the / run/systemd/system/: system have higher priority than / usr/lib/systemd/system/! / etc/systemd/system/: administrator according to the requirements of the host system to create the execution script, in fact, this directory is a bit like the previous / etc/rc.d/rc5.d/Sxx and other functions! Execution priority is also higher than / run/systemd/system/.

(3) daemon and Services (service)

(4) manage services through systemctl

1. Active (running): it means that one or more programs are executing in the system, for example, the executing vsftpd is this mode. 2. Active (exited): a service that ends normally after only one execution, and there are currently no programs executed in the system. For example, the quotaon function, which is only available once when booting or mounting, is this mode! Quotaon does not need to be executed all the time. After only one execution, leave it to the file system to handle on its own. Most of the small services that are usually written in bash shell are of this type (no need to be resident in memory). 3. Active (waiting): in progress, but wait for other events to continue processing. 4. Inactive: this service currently has no intention of running. Since there are so many current states of daemon, is it possible that the default state of daemon is in addition to 5, enabled: this daemon will be executed at boot 6, disabled: this daemon will not be executed at boot 7, static: this daemon cannot be started by itself (enable cannot), but may be awakened by other enabled services (dependent services) 8, mask: this daemon can not be started anyway! Because it has been forced to log out (not deleted). Can be changed back to the original state by systemctl unmask

Give examples to illustrate

Force service logout (mask)

Root@localhost ~] # systemctl stop firewalld [root@localhost ~] # systemctl mask firewalld\\ is to clear the launched script [root@localhost ~] # systemctl status firewalld ● firewalld.service Loaded: masked (/ dev/null; bad) Active: inactive (dead) since six 2019-11-23 23:05:22 CST 17s ago Main PID: 752 (code=exited, status=0/SUCCESS) November 23 23:03:40 localhost.localdomain systemd [1]: Starting firewalld-dynamic fi....11 23 23:03:43 localhost.localdomain systemd [1]: Started firewalld-dynamic fir....11 23 23:05:22 localhost.localdomain systemd [1]: Stopping firewalld.service...11 23 23:05:22 localhost.localdomain systemd [1]: Stopped firewalld.service.Hint: Some lines were ellipsized Use-l to show in full. [root@localhost ~] # [root@localhost ~] # systemctl unmask firewalld\\ remove mask [root@localhost ~] # systemctl status firewalld

VI. By default, there are 26 target unit in CentOS 7.1s

There are mainly the following

Graphical.target: text plus graphical interface, this project already includes the following multi-user.target project! Multi-user.target: plain text mode! Rescue.target: if you can't log in using root, systemd will add an extra temporary system when you boot, regardless of your original system. At this point, you can get permission from root to maintain your system. But this is an extra system, so you may need to go to chroot to get your original system emergency.target: emergency handling system errors, or if you still need to log in using root, you can try using this mode when you can't use rescue.target! 5.shutdown.target: this is the process of shutting down the computer. 6.getty.target: you can set up how many tty you need, and if you want to lower the tty project, you can modify the configuration file of this thing!

The normal mode is multi-user.target and graphical.target, and the rescue mode is mainly rescue.target and more serious emergency.target. If you want to modify the number of tty that can provide login, modify the getty.target project. Basically, the ones we use most often, of course, are multi-user and graphical.

[root@localhost ~] # systemctl poweroff\\ system shutdown [root@localhost ~] # systemctl reboot\\ restart [root@localhost ~] # systemctl suspend\\ enter pause mode [root@localhost ~] # systemctl hibernate\\ enter hibernation mode [root@localhost ~] # systemctl rescue\ force rescue mode [root@localhost] # systemctl emergency\ force emergency rescue mode

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report