search
HomeOperation and MaintenanceLinux Operation and MaintenanceSummary of Linux system startup and service management (organized and shared)

This article brings you relevant knowledge about system startup and service management in Linux. During normal operation, the server rarely restarts, but if an unknown fault occurs or human error occurs, , an abnormal startup situation may occur. I hope this helps everyone.

Summary of Linux system startup and service management (organized and shared)

1. Foreword

During normal operation, the server rarely restarts, but if an unknown fault occurs or human error occurs, In this case, abnormal startup may occur. Although the Linux system startup process is relatively low-level knowledge, in order to deepen the understanding of the Linux system, this article is summarized.

2. Linux system startup process

Summary of Linux system startup and service management (organized and shared)

#2.1 Power-on self-test

After the server host is turned on, it will be based on the settings in the motherboard BIOS. The CPU, memory, graphics card, hard disk and other devices are initially tested. After successful detection, system control is transferred according to the preset startup sequence, and most of the time it is transferred to the local hard disk.

2.2 MBR boot

- When booting the system from the local hard disk, system control is first transferred to the system containing the MBR (Master Boot Record) settings in the first sector of the hard disk. The partition of the operating system boot file; or directly call the boot menu (such as GRUB) based on the boot information in the MBR record.

2.3 GRUB Menu

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

2.4 Loading the Linux kernel

The Linux kernel 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 system control, it will fully control the running process of the entire Linux operating system.
In CentoS system, the default kernel file is located in "/boot/vmlinuz-3.10.0-514.el7.x86_64".

2.5 init process initialization

In order to complete the further system boot process, the Linux kernel first loads the "/sbin/init" program in the system into the memory and runs it. The init process is responsible for completing a series of system initialization process, and finally waits for the user to log in.

2.6 Summary of the system startup process

  • Detect the first device that can boot the system, such as a hard disk or optical drive
  • Run the startup GRUB placed in the MBR sector Boot program
  • GRUB boot program reads the GRUB configuration file/boot/grub2/grub.cfg to obtain the settings and path locations of the kernel and image file systems
  • Load the kernel and image file systems into the memory
  • Load the hardware driver, and the kernel loads the init process into the memory to run

3. Init process and systemd

3.1 init process

  • The /sbin/init program is loaded and run by the Linux kernel
  • The init process is the first process in the system
  • The PID number of the init process is always 1
[root@c7-1 ~]#ll /sbin/initlrwxrwxrwx. 1 root root 22 8月  13 21:44 /sbin/init -> ../lib/systemd/systemd

3.2 Centos5/6/7 init process comparison

Summary of Linux system startup and service management (organized and shared)

3.3 systemd

  • #systemd is an init software for the Linux operating system
  • CentOS7 uses a new systemd startup method to replace the traditional SysVinit
  • The first init process running in CentOS7 is /lib/systemd/systemd
[root@c7-1 ~]#ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 8月15 ?       00:00:31 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root          2      0  0 8月15 ?       00:00:00 [kthreadd]
root          4      2  0 8月15 ?       00:00:00 [kworker/0:0H]
root          6      2  0 8月15 ?       00:00:00 [ksoftirqd/0]
root          7      2  0 8月15 ?       00:00:00 [migration/0]
......

3.4 systemd unit type

Unit type Extension Description
Service .service Describes a system service
Socket . socket Describes a socket for inter-process communication
Device .device Describes a device file recognized by the kernel
Mount .mount Describes the mount point of a file system
Automount .automount Describes an automatic mount point for a file system
Swap .swap Describes a Memory swap device or swap file
Path .path Describes a file or directory in a file system
Timer .timer Describes a timer (used to implement cron-like scheduling tasks)
Snapshot .snapshot Used to save the state of a systemd
Scope .scope Use systemd’s bus interface for programming Create an external process
Slice .slice Describes a group of management system processes organized hierarchically in a Cgroup
Target .target Describes a group of systemd units

3.5 运行级别对应的 systemd 目标

运行级别 systemd 的 target 说明
0 target 关机状态,使用该级别时将会关闭主机
1 rescue.target 单用户模式,不需要密码验证即可登录系统,多用于系统维护
2 multi-user.target 用户定义/域特定运行级别。默认等同于3
3 multi-user.target 字符界面的完整多用户模式,大多数服务器主机运行在此级别
4 multi-user.target 用户定义/域特定运行级别。默认等同于3
5 graphical.target 图形界面的多用户模式,提供了图形桌面操作环境
6 reboot.target 重新启动,使用该级别时将会重启主机

3.6 systemd 管理命令 systemctl

格式:

systemctl COMMAND name.service		#.service 也可以省略

Sysvinit 和 Systemd 命令对比

Sysvinit命令 Systemd命令 含义
service name start systemctl start name 启动服务
service name stop systemctl stop name 关闭服务
service name restart systemctl restart name 重启服务不管当前是启动还是关闭状态
service name reload systemctl reload name 重新载入服务配置信息而不中断服务
service name condrestart systemctl condrestart name 运行状态的服务可以重启,不在运行状态无法重启
service name status systemctl status name 查看服务的运行状态
chkconfig name on systemctl enable name 设置服务为开机自启动
chkconfig name off systemctl disable name 设置服务为开机关闭
chkconfig name systemctl is-enabled name 检查服务是否开机自启
chkconfig name --add systemctl daemon-reload 创建一个新服务文件,或者变更配置的时候使用

示例:

#启动 httpd 服务
systemctl start httpd 
#停止 httpd 服务
systemctl stop httpd
#重启 httpd 服务
systemctl restart httpd
#查看 httpd 服务状态
systemctl status httpd
#禁止自动和手动启动服务(可以关闭运行的服务)
systemctl mask name.service	
#取消禁止
systemctl unmask name.service
#查看某服务当前是否正在运行
systemctl is-active name.service
#查看所有服务
systemctl list-unit-files --type=service
#查看所有已经激活的服务
systemctl list-unit-files --type=service | grep enabled
#列出启动失败的服务
systemctl --failed --type=service
或
systemctl list-units --state failed
或
systemctl list-unit-files --state=failed
#开启 httpd 服务并设置开机自启
systemctl enable --now httpd.service
#关闭 httpd 服务并关闭开机自启
systemctl disable --now httpd.service
#查看服务的依赖关系
systemctl list-dependencies name.service
#杀掉进程
systemctl kill unitname

4.总结

  作为一名运维工程,对 Linux 系统服务的管理是基本技能。一个系统在安装完成后免不了要对系统进行优化,关闭不必要的服务,节省系统资源,保护服务器不受网络攻击,这也是运维工作的职责所在,熟练掌握 Linux 系统的底层原理和基本操作,在面对问题的时候才不会茫然不知所措!

相关推荐:《Linux视频教程

The above is the detailed content of Summary of Linux system startup and service management (organized and shared). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

How to choose Hadoop version in DebianHow to choose Hadoop version in DebianApr 13, 2025 am 11:48 AM

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

TigerVNC share file method on DebianTigerVNC share file method on DebianApr 13, 2025 am 11:45 AM

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool