小白带你一起学Linux之Linux程序管理

Linux程序管理

一、Linux程序与进程

1、程序,进程,线程的概念

  • 程序:是一组指令及参数的集合,按照既定的逻辑控制计算机运行用来完成特定任务,是静态的;

  • 进程:是运行着的程序,是操作系统执行的基本单位,是程序运行的过程, 是动态的,是有生命周期(一个程序从开启到关闭的时间)及运行状态的。是操作系统分配内存、CPU时间片等资源的基本单位。

  • 线程:是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位。(一般指cpu,一线程代表一份cpu资源)

2、程序和进程的区别

  • 程序是静态的,它只是一组指令的集合,不具有任何的运行意义。而进程是程序运行的动态过程;

  • 进程和程序并不是一一对应的关系,相同的程序运行在不同的数据集上就是不同的进程;

  • 进程还具有并发性和交往性,而程序却是封闭的。

3、进程和线程的区别

  • 一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发拥有多个线程,而一个线程同时只能被一个进程所拥有;

  • 线程不能单独执行,但是每一个线程都有程序的入口、执行序列以及程序出口,它必须组成进程才能被执行。

二、Linux进程基础(生命周期)

1、进程生命周期

  • 父进程复制自己的地址空间(fork)创建一个新的(子)进程结构。每个新进程分配一个唯一的进程 ID(PID),PID和父进程ID(PPID)是子进程环境的元素,任何进程都可以创建子进程。

  • 所有进程都是第一个系统进程的后代:在centos6中,第一个系统进程是init,而在centos7中,第一个系统进程是systemd。

2、父子进程的关系

  • 子进程由父进程产生,在linux系统中,使用系统调用fork创建进程。fork复制的内容包括父进程的数据和堆栈段以及父进程的进程环境子进程继承父进程的安全性身份、过去和当前的文件描述符、端口和资源特权、环境变量,以及程序代码。

  • 运行过程:子进程运行时父进程休眠。当子进程完成时发出(exit)信号请求,在退出时,子进程已经关闭或丢弃了其资源环境后,剩余释放不掉的资源称之为僵尸进程。父进程在子进程退出时收到信号而被唤醒,清理剩余的结构,然后继续执行其自己的程序代码。

环境变量

这两种是不一样的,原因是是否有环境变量
[root@bogon ~]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面  anaconda-ks.cfg  sshd_config
[root@bogon ~]# /usr/bin/ls
公共  模板  视频  图片  文档  下载  音乐  桌面  anaconda-ks.cfg  sshd_config
[root@bogon ~]# echo $PATH 环境变量中的路径变量
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[root@bogon ~]# env 查看所有环境变量
SHELL=/bin/bash
HISTCONTROL=ignoredups
HISTSIZE=1000
HOSTNAME=bogon
PWD=/root
LOGNAME=root
XDG_SESSION_TYPE=tty
MOTD_SHOWN=pam
HOME=/root
LANG=zh_CN.UTF-8

[root@bogon ~]# echo $HISTSIZE
1000

三、程序管理

1、课程目标

  • 掌握Linux系统安装软件的方法

  • 掌握Linux系统软件管理命令

  • 熟练配置yum源

  • 掌握systemd管理机制

2、常见的软件包类型

1)rpm包:.rpm为后缀,红帽系列操作系统(RedHat,CentOS,OpenSUSE)主要的软件包封装格式,已经做好默认设置,如安装路径,配置文件存放路径,需要手动的解决依赖关系。(相关命令:rpm,yum,dnf)

2)deb包:.deb为后缀,debian系列操作系统(debian,Ubuntu,kali)主要的软件包封装格式,已经做好默认设置,如安装路径,配置文件存放路径等,需要手动的解决依赖关系。(相关命令:dpkg,apt[-get])

3)二进制包:一般以.bin为后缀,直接被计算机执行安装。

4)源码包:一般C语言(高级语言中最底层的语言,一般结合汇编进行驱动编写)编写,安装前需要编译为二进制包;配置【如,安装路径,配置文件路径,运行用户,运行组,功能模块】--->编译--->安装;文件比较集中,便于后期进行维护与管理。

注意:

1.1,2不能选择安装,提前指定好的安装路径

2.依赖关系:安装软件包所需的基础环境

rpm单包安装时需要 手动解决依赖关系

yum能够解决单包安装的问题,自动解决依赖关系,但是源文件里面得有相应文件

3.Windows安装包格式 .exe .msi

MAC安装包格式 .dmg

4.Debian的安装命令 dpkg单包安装 apt或apt -get 常用指令里面有 ubantu

5.记住以后安装的每个软件的版本号

3、安装方法

  • 使用独立的rpm包安装

需要下载对应的rpm包,一般在centos系统镜像中存在大量的rpm包

  • rpm包的命名方法

zip-0-11.el7.x86_64.rpm

软件名.版本号.安装平台.安装架构平台的位数(32位,x86或者64位,x86_64).rpm

要记软件版本号

  • rpm命令使用方法

已安装软件包查看选项

-q:查看指定rpm包是否安装;rpm -q 软件名

-qa 【all】:查看系统中所有已安装的软件包;rpm -qa [| grep 软件名]

-qi 【infomation】:查看已安装软件包的开发信息;rpm -qi 软件名

-ql  【list】:查看已安装软件包的安装路径及生成的文件;rpm -ql 软件名

-qf 【find】:查看命令由哪个软件包安装;which 命令字  rpm -qf 命令的绝对路径;常用于:系统中没有对应指令且不知道由哪个软件包安装生成

-qc:查看已安装软件的配置文件;rpm -qc 软件名;一般情况下,使用rpm安装的应用程序的配置文件都存储在/etc/[应用程序的名称]

-qd:查看已安装软件的帮助文档信息;rpm -qd 软件名

未安装软件包查看选项

-qpi:查看未安装的软件包开发信息;rpm -pqi 软件包名称(全格式)

-qpl:查看未安装软件包的安装路径及生成文件;rpm -pql 软件包名称(全格式)

安装、升级、卸载选项

-i 【install】:安装软件包;rpm -ivh /path/软件包名称(全格式)

-v:【verify】详细显示安装过程

-h:【human】人性化显示

-U:【update】升级软件包;rpm -Uvh 软件包名称

-e:【exclude】卸载已安装软件包;只能一个依赖一个依赖的卸载

--nodeps:忽略依赖关系的进行卸载、升级或安装 不建议用

特殊安装

#将所有相关软件包放到同一目录下

rpm -ivh *
依赖关系有前后顺序时不好用

4、yum(dnf)安装

可以自动解决依赖关系

要么本地有源仓库,要么联网用网上源仓库,否则不好使

  • yum相关配置文件

yum源配置文件

指定yum程序运行时查找软件包的存储路径

 /etc/yum.repos.d

yum程序配置文件

yum程序运行时的运行配置

 /etc/dnf/dnf.conf
 /etc/yum.conf

缓存保存路径

 /var/cache/dnf
  • yum源类型

本地yum源

利用本地存在的软件包路径

 file://localPath(绝对路径)【路径下要包含“repodata(包含rpm包的元数据)”目录】

网络yum源

利用网络存储的软件包路径

 http://域名/Path #不常用
 ​
 https://域名/Path
 ​
 ftp://域名/Path  #不常用

常见网络yum源

 #网易yum源
 ​
 ​
 ​
 #阿里云yum源
  tee /etc/yum.repos.d/alicloud.repo << 'EOF'
 [alicloud-os]
 name=Alibaba Cloud OS
 baseurl=https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/
 enabled=1
 gpgcheck=0
 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-rockylinux
  
 [alicloud-appstream]
 name=Alibaba Cloud AppStream
 baseurl=https://mirrors.aliyun.com/rockylinux/8/AppStream/x86_64/os/
 enabled=1
 gpgcheck=0
 gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-rockylinux
 EOF
 ​
 #epel源
 ​
 yum -y install epel-release

常见开源镜像站

 
清华大学
 ​
 https://mirrors.tuna.tsinghua.edu.cn/help/centos/
 ​
 网易开源镜像站
 ​
 http://mirrors.16com/
 ​
 阿里云
 ​
  • 配置本地yum源
 cd /etc/yum.repos.d
 [root@localhost yum.repos.d]# rm -rf *
 vim local.repo
 [local]
 name=local  #描述信息
 baseurl=file:///mnt/AppStream  # 指定软件包及其元数据存储路径
 enabled=1  #是否使用该源,0表示不使用,1表示使用
 gpgcheck=0  #(一般使用不验证的方式) [gpgcheck=1]
 gpgkey=keyPath
 ​
 ################################
 yum clean all
 ​
 yum makecache 
 ​
 mount  /dev/sr0 /mnt

5、yum命令语法

 yum [options] command [package ...]
  • 子命令(command)
 install [软件包名] [--downloadonly]
 #安装【只下载】
 remove [软件包名]
 #卸载
 list
 #查看yum源中的软件包列表
 update [软件包名]
 #更新所有软件包
 yum clean all
 #清空元数据缓存
 yum makecache 
 #生成元数据缓存
 yum grouplist
 查看当前源中存在的可用安装组
 yum groupinstall "带 GUI 的服务器"
  • 命令选项
 -y:非交互

交互式安装:yum install 软件名

 Is this ok?
 ​
 y
 ​
 安装
 ​
 n
 ​
 不下载不安装

非交互式安装:yum -y install 软件名

6、源码包(编译)安装

是指通过软件的原始源代码(Source Code)进行手动编译、配置和安装的过程。与直接使用预编译的二进制包(如 RPM、DEB 文件)不同,源码包安装需要用户自行完成从代码到可执行程序的转换。

 需要依赖gcc和make环境
 ​
 配置:cd 源码包的解压路径;./configure --prefix=安装路径(/usr/local/nginx)
 ​
 编译:make
 ​
 安装:make install

.configure --help

   --help                             print this message
 ​
   --prefix=PATH                      set installation prefix #设置安装路径,必须是绝对路径
   --sbin-path=PATH                   set nginx binary pathname
   --modules-path=PATH                set modules path
   --conf-path=PATH                   set nginx.conf pathname
   --error-log-path=PATH              set error log pathname
   --pid-path=PATH                    set nginx.pid pathname
   --lock-path=PATH                   set nginx.lock pathname #进程锁
 ​
   --user=USER                        set non-privileged user for
                                      worker processes
   --group=GROUP                      set non-privileged group for
                                      worker processes
 ​
   --build=NAME                       set build name
   --builddir=DIR                     set build directory
 ​
   --with-select_module               enable select module
   --without-select_module            disable select module
   --with-poll_module                 enable poll module
   --without-poll_module              disable poll module
 ​
   --with-threads                     enable thread pool support
 ​
   --with-file-aio                    enable file AIO support
 ​
   --without-quic_bpf_module          disable ngx_quic_bpf_module
 ​
   --with-http_ssl_module             enable ngx_http_ssl_module #加密
   --with-http_v2_module              enable ngx_http_v2_module
   --with-http_v3_module              enable ngx_http_v3_module
   --with-http_realip_module          enable ngx_http_realip_module
   --with-http_addition_module        enable ngx_http_addition_module
   --with-http_xslt_module            enable ngx_http_xslt_module
   --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
   --with-http_image_filter_module    enable ngx_http_image_filter_module
   --with-http_image_filter_module=dynamic
                                      enable dynamic ngx_http_image_filter_module
   --with-http_geoip_module           enable ngx_http_geoip_module
   --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
   --with-http_sub_module             enable ngx_http_sub_module
   --with-http_dav_module             enable ngx_http_dav_module
   --with-http_flv_module             enable ngx_http_flv_module
   --with-http_mp4_module             enable ngx_http_mp4_module
   --with-http_gunzip_module          enable ngx_http_gunzip_module
   --with-http_gzip_static_module     enable ngx_http_gzip_static_module
   --with-http_auth_request_module    enable ngx_http_auth_request_module
   --with-http_random_index_module    enable ngx_http_random_index_module
   --with-http_secure_link_module     enable ngx_http_secure_link_module
   --with-http_degradation_module     enable ngx_http_degradation_module
   --with-http_slice_module           enable ngx_http_slice_module
   --with-http_stub_status_module     enable ngx_http_stub_status_module
 ​
   --without-http_charset_module      disable ngx_http_charset_module
   --without-http_gzip_module         disable ngx_http_gzip_module
   --without-http_ssi_module          disable ngx_http_ssi_module
   --without-http_userid_module       disable ngx_http_userid_module
   --without-http_access_module       disable ngx_http_access_module
   --without-http_auth_basic_module   disable ngx_http_auth_basic_module
   --without-http_mirror_module       disable ngx_http_mirror_module
   --without-http_autoindex_module    disable ngx_http_autoindex_module
   --without-http_geo_module          disable ngx_http_geo_module
   --without-http_map_module          disable ngx_http_map_module
   --without-http_split_clients_module disable ngx_http_split_clients_module
   --without-http_referer_module      disable ngx_http_referer_module
   --without-http_rewrite_module      disable ngx_http_rewrite_module
   --without-http_proxy_module        disable ngx_http_proxy_module
   --without-http_fastcgi_module      disable ngx_http_fastcgi_module
   --without-http_uwsgi_module        disable ngx_http_uwsgi_module
   --without-http_scgi_module         disable ngx_http_scgi_module
   --without-http_grpc_module         disable ngx_http_grpc_module
   --without-http_memcached_module    disable ngx_http_memcached_module
   --without-http_limit_conn_module   disable ngx_http_limit_conn_module
   --without-http_limit_req_module    disable ngx_http_limit_req_module
   --without-http_empty_gif_module    disable ngx_http_empty_gif_module
   --without-http_browser_module      disable ngx_http_browser_module
   --without-http_upstream_hash_module
                                      disable ngx_http_upstream_hash_module
   --without-http_upstream_ip_hash_module
                                      disable ngx_http_upstream_ip_hash_module
   --without-http_upstream_least_conn_module
                                      disable ngx_http_upstream_least_conn_module
   --without-http_upstream_random_module
                                      disable ngx_http_upstream_random_module
   --without-http_upstream_keepalive_module
                                      disable ngx_http_upstream_keepalive_module
   --without-http_upstream_zone_module
                                      disable ngx_http_upstream_zone_module
 ​
   --with-http_perl_module            enable ngx_http_perl_module
   --with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
   --with-perl_modules_path=PATH      set Perl modules path
   --with-perl=PATH                   set perl binary pathname
 ​
   --http-log-path=PATH               set http access log pathname
   --http-client-body-temp-path=PATH  set path to store
                                      http client request body temporary files
   --http-proxy-temp-path=PATH        set path to store
                                      http proxy temporary files
   --http-fastcgi-temp-path=PATH      set path to store
                                      http fastcgi temporary files
   --http-uwsgi-temp-path=PATH        set path to store
                                      http uwsgi temporary files
   --http-scgi-temp-path=PATH         set path to store
                                      http scgi temporary files
 ​
   --without-http                     disable HTTP server
   --without-http-cache               disable HTTP cache
 ​
   --with-mail                        enable POP3/IMAP4/SMTP proxy module
   --with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
   --with-mail_ssl_module             enable ngx_mail_ssl_module
   --without-mail_pop3_module         disable ngx_mail_pop3_module
   --without-mail_imap_module         disable ngx_mail_imap_module
   --without-mail_smtp_module         disable ngx_mail_smtp_module
 ​
   --with-stream                      enable TCP/UDP proxy module
   --with-stream=dynamic              enable dynamic TCP/UDP proxy module
   --with-stream_ssl_module           enable ngx_stream_ssl_module
   --with-stream_realip_module        enable ngx_stream_realip_module
   --with-stream_geoip_module         enable ngx_stream_geoip_module
   --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
   --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
   --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
   --without-stream_access_module     disable ngx_stream_access_module
   --without-stream_geo_module        disable ngx_stream_geo_module
   --without-stream_map_module        disable ngx_stream_map_module
   --without-stream_split_clients_module
                                      disable ngx_stream_split_clients_module
   --without-stream_return_module     disable ngx_stream_return_module
   --without-stream_pass_module       disable ngx_stream_pass_module
   --without-stream_set_module        disable ngx_stream_set_module
   --without-stream_upstream_hash_module
                                      disable ngx_stream_upstream_hash_module
   --without-stream_upstream_least_conn_module
                                      disable ngx_stream_upstream_least_conn_module
   --without-stream_upstream_random_module
                                      disable ngx_stream_upstream_random_module
   --without-stream_upstream_zone_module
                                      disable ngx_stream_upstream_zone_module
 ​
   --with-google_perftools_module     enable ngx_google_perftools_module
   --with-cpp_test_module             enable ngx_cpp_test_module
 ​
   --add-module=PATH                  enable external module
   --add-dynamic-module=PATH          enable dynamic external module
 ​
   --with-compat                      dynamic modules compatibility
 ​
   --with-cc=PATH                     set C compiler pathname
   --with-cpp=PATH                    set C preprocessor pathname
   --with-cc-opt=OPTIONS              set additional C compiler options
   --with-ld-opt=OPTIONS              set additional linker options
   --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                      pentium, pentiumpro, pentium3, pentium4,
                                      athlon, opteron, sparc32, sparc64, ppc64
 ​
   --without-pcre                     disable PCRE library usage
   --with-pcre                        force PCRE library usage
   --with-pcre=DIR                    set path to PCRE library sources
   --with-pcre-opt=OPTIONS            set additional build options for PCRE
   --with-pcre-jit                    build PCRE with JIT compilation support
   --without-pcre2                    do not use PCRE2 library
 ​
   --with-zlib=DIR                    set path to zlib library sources
   --with-zlib-opt=OPTIONS            set additional build options for zlib
   --with-zlib-asm=CPU                use zlib assembler sources optimized
                                      for the specified CPU, valid values:
                                      pentium, pentiumpro
 ​
   --with-libatomic                   force libatomic_ops library usage
   --with-libatomic=DIR               set path to libatomic_ops library sources
 ​
   --with-openssl=DIR                 set path to OpenSSL library sources
   --with-openssl-opt=OPTIONS         set additional build options for OpenSSL
 ​
   --with-debug                       enable debug logging
 
  
  • 案例

nginx编译安装

 tar xf  nginx-1.12.0.tar.gz
 ​
 cd nginx-1.12.0
 ​
 ./configure --prefix=/usr/local/nginx1.12
 ​
 发现依赖缺失
 ​
 解决依赖
 ​
 yum install -y pcre-devel或者untils  
 ​
 yum install -y zlib-devel
 ​
 配置完成后
 ​
 在源码包下生成Makefile文件
 ​
 make
 ​
 编译
 ​
 make  install
 ​
 安装
 ​
 命令合并
 ​
 ./configure --prefix=/usr/local/nginx18  && make  && make install
 ​
 验证
 ​
 cd /usr/local/nginx1.12
 ​
 ###命令优化####
 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
 
  

注意

编译安装完成的软件默认不被systemd管理

7、二进制安装

 只需要运行bin文件
  • 案例
jdk-6u14-linux-x64.bin
 ​
 ./jdk-6u14-linux-x64.bin
 ​
 根据提示进行操作即可

注意:

1.&& 会检测前面命令的执行结果,前面执行,后面就执行;前面不执行,后面不执行

  1. || 前面不执行,后面执行

  2. ;只做命令分割

 [root@bogon local]# mkdir aa/bb/cc
 mkdir: 无法创建目录 “aa/bb/cc”: 没有那个文件或目录
 [root@bogon local]# mkdir aa/bb/cc && touch f1
 mkdir: 无法创建目录 “aa/bb/cc”: 没有那个文件或目录
 [root@bogon local]# ls
 bin  games    lib    libexec  nginx-1.28.0  share
 etc  include  lib64  nginx    sbin          src
 ​
 [root@bogon local]# mkdir aa/bb/cc || touch f1
 mkdir: 无法创建目录 “aa/bb/cc”: 没有那个文件或目录
 [root@bogon local]# ls
 bin  f1     include  lib64    nginx         sbin   src
 etc  games  lib      libexec  nginx-1.28.0  share

四、Linux操作系统启动流程详解

1、概述

Linux启动流程是从按下电源键到用户登录的完整过程,分为传统BIOS+MBR和现代UEFI+GPT两种模式。主流系统(如CentOS 7+/Ubuntu 18.04+)通常使用 UEFI + GRUB2 + systemd 组合。


2、启动流程核心阶段

1. 电源与固件阶段
  • UEFI/BIOS初始化

    • 硬件自检(POST, Power-On Self-Test)

    • UEFI特点:图形化界面、支持GPT分区、独立于OS的Shell环境

    • 定位启动设备:读取NVRAM(非遗失性存储信息)中的启动项(efibootmgr命令可管理)

2. 引导加载程序(Bootloader)
  • GRUB2 核心作用

    • 配置文件路径:/boot/grub2/grub.cfg(由grub2-mkconfig生成)

    • 关键配置参数:

       set root=(hd0,gpt1)  # 指定/boot所在分区
       linux /vmlinuz-5.4.0 root=/dev/sda2 ro  # 内核路径及挂载参数
       initrd /initramfs-5.4.0.img             # 初始化内存文件系统

  • 用户交互

    • e 临时编辑启动参数(如单用户模式 systemd.unit=rescue.target

    • c 进入GRUB命令行

3. 内核初始化
  • 内核解压与初始化

    • 加载vmlinuz:压缩的内核镜像

    • initramfs 作用:

      • 包含根文件系统挂载前的驱动(如LVM、RAID)

      • 提供dracut工具集(可通过dmesg | grep initramfs查看日志)

    • 挂载根文件系统(/)为只读模式

4. systemd 初始化进程
  • 首个用户态进程

    • PID=1,替代传统init

    • 核心任务:

      1. 解析/etc/systemd/system/default.target(默认运行级别)

      2. 并行启动服务单元(Unit)在/etc/systemd/system/

      3. 激活sysinit.target(系统初始化)、basic.target(基础服务)

  • 关键操作命令

     systemctl get-default         # 查看默认target 查看运行级别
     systemctl set-default multi-user.target  # 设置默认为命令行模式
     journalctl -b                # 查看本次启动日志

5. 用户登录阶段
  • 终端登录

    • getty 服务生成终端(/etc/systemd/system/getty.target.wants/

    • 调用login验证用户身份

  • 图形化登录

    • Display Manager(如GDM、LightDM)启动X/Wayland会话

     #密码认证
     [root@bogon ~]# cd /etc/pam.d/
     [root@bogon pam.d]# ls
     atd               gdm-fingerprint         polkit-1          sudo
     chfn              gdm-launch-environment  postlogin         sudo-i
     chsh              gdm-password            remote            su-l
     cockpit           gdm-pin                 runuser           system-auth
     config-util       gdm-smartcard           runuser-l         systemd-user
     crond             login                   smartcard-auth    vlock
     cups              other                   sshd              vmtoolsd
     fingerprint-auth  passwd                  sssd-shadowutils  xserver
     gdm-autologin     password-auth           su
     [root@bogon pam.d]# vim password-auth
     ​
     ​
     #清除历史记录
     history -c
     vim .bash_logout
     #可以设置每次登出过后清除操作记录
     vim /etc/profile
     HISTSIZE=
     #设置history记录数目
     ​


3、故障排查与调试技巧

1. 常见启动问题
故障现象 可能原因 解决方法
GRUB Rescue> 提示符 引导分区损坏/配置丢失 使用Live CD重建grub
Kernel panic 驱动缺失/根文件系统错误 检查initramfs是否包含所需驱动
systemd启动卡死 服务依赖死锁 添加systemd.unit=emergency.target内核参数
文件系统只读 fsck未通过或磁盘错误 手动运行fsck /dev/sda1
2. 救援模式操作
  1. 在GRUB界面添加启动参数:

     systemd.unit=rescue.target   # 单用户模式(需root密码)
     systemd.unit=emergency.target # 紧急模式(只挂载根文件系统)

  2. 重新挂载根文件系统为读写:

     mount -o remount,rw /

3. 关键文件修复
  • 重建GRUB(适用于MBR损坏):

     grub2-install /dev/sda        # 安装引导到磁盘
     grub2-mkconfig -o /boot/grub2/grub.cfg  # 生成配置文件

  • 重建initramfs(CentOS/RHEL):

     dracut -f /boot/initramfs-$(uname -r).img $(uname -r)


4、启动流程示意图(文本版)

 [UEFI固件] → 加载ESP分区(GPT分区都会产生)的GRUB → 载入内核和initramfs → 
            |                         |
            |                         v
            ←←←←←←←←←←←←←←←←←   systemd初始化 → 启动target → 用户登录

五、systemd管理机制(熟悉)

init进程是所有进程的父进程,systemd实际上是一种管理init的软件。只能管理rpm安装的

 units存储路径
 ​
 /usr/lib/systemd/system
 /etc/systemd/system 里面也有少量
  • 基于unit概念实现,常见的unit类型

单元类型 扩展名 说明
Service .service 描述一个系统服务
Target .target 描述一组systemd的单元
Socket .socket 描述一个进程间通信的套接字
Device .device 描述一个内核识别的设备文件
Mount .mount 描述一个文件系统的挂载点
Automount .automount 描述一个文件系统的自动挂载点
Swap .swap 描述一个内存交换设备或交换文件
Path .path 描述一个文件系统中文件或目录
Timer .timer 描述一个定时器(用于实现类似cron的调度任务)
Snapshot .snapshot 用于保存一个systemd的状态
Scope .scope 使用systemd的总线接口以编程的方式创建外部进程
Slice .slice 描述居于Cgroup的一组通过层次组织的管理系统进程

1、运行级别

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

注意:

1.control +alt+F2-6切换界面,control+alt+F1 切回原有界面

2.init0,2,3,4,5,6 都可单独切换 init0不可单独切换

查看运行级别

 runlevel
 ​
 N|运行级别数字   当前运行级别数字
 N NONE 指的是上一次的运行级别

切换运行级别

 init  运行级别数字

查看默认运行级别

 systemctl get-default

设置默认运行级别

 systemctl set-default  运行级别target
 #两种写法
 [root@bogon ~]# systemctl set-default runlevel3.target
 Removed "/etc/systemd/system/default.target".
 Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.
 Note: "multi-user.target" is the default unit (possibly a runtime override).
 ​
 [root@bogon ~]# systemctl set-default graphical.target 
 Removed "/etc/systemd/system/default.target".
 Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/graphical.target.

2、systemctl命令的使用

语法结构:

 systemctl  服务控制类型   服务名称[.service]

服务控制类型

 start:启动
 Active: active (running)#正常运行
 ​
 stop:停止
 Active: inactive (dead)#正常停止
 ​
 #还有
 Active: failed (Result:exit-code)#错误退出
 #还有一种无限重启

 status:#查看状态
 journalctl -xe #也可查看
 ​
 enable:#开机自启动
 disable:#开机不进行自启动
 --now 配合enable与disable使用;在进行开机自启或不自启的同时进行打开或关闭指定服务

reload:重载
#不停止服务,加载配置文件
#优雅的重启
restart:
#重启
#会停止服务
is-enabled:查看是否开机自启动
#结果1 disabled
关闭开机自启动

#结果2 enabled
开启开机自启动

  • 选项
-t

指定unit类型

Unit Commands

list-units

列出所有unit,一般与-t结合

案例

#将所有相关软件包放到同一目录下

rpm -ivh *
依赖关系有前后顺序时不好用

3、服务启动报错排查

脚本错误

###参数报错
Failed to restart crond.service: Unit is not loaded properly: Invalid argument.

See system logs and 'systemctl status crond.service' for details.

Loaded: error (Reason: Invalid argument)

###命令报错
8月 27 11:57:51 localhost.localdomain systemd[12545]: Failed at step EXEC spawning /usr/sbin/httpd1: No such file or directory
-- Subject: Process /usr/sbin/httpd1 co not be executed

配置文件错误

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

Active: failed (Result: exit-code)

AH00526: Syntax error on line 42 of /etc/httpd/conf/httpd.conf:

未知错误

Active: failed (Result: exit-code)
8月 27 12:03:41 localhost.localdomain useradd[12790]: failed adding user 'apache', exit code: 9
没有具体的错误提示
排查关联服务及配置文件

服务排错命令

journalctl -xe

图形化管理工具

ntsysv  #只能在图形化运行级别使用
rocky9没有 8还有

六、实操

 (一)rpm包安装

 上次元数据过期检查:0:12:55 前,执行于 2025年05月27日 星期二 19时53分18秒。
 依赖关系解决。
 ===============================================================================
  软件包                 架构        版本                  #交互式下载  [root@bogon ~]# yum install httpd  上次元数据过期检查:0:04:50 前,执行于 2025年05月27日 星期二 19时53分18秒。  依赖关系解决。  ===============================================================================   软件包                 架构       版本                 仓库           大小  ===============================================================================  安装:   httpd                 x86_64      2.4.62-1.el9_5.2     appstream       45 k  安装依赖关系:   apr                   x86_64      1.7.0-12.el9_3       appstream      122 k   apr-util               x86_64      1.6.1-23.el9         appstream       94 k   apr-util-bdb           x86_64      1.6.1-23.el9         appstream       12 k   httpd-core             x86_64      2.4.62-1.el9_5.2     appstream      1.4 M   httpd-filesystem       noarch      2.4.62-1.el9_5.2     appstream       12 k   httpd-tools           x86_64      2.4.62-1.el9_5.2     appstream       79 k   rocky-logos-httpd     noarch      90.15-2.el9           appstream       24 k  安装弱的依赖:   apr-util-openssl       x86_64      1.6.1-23.el9         appstream       14 k   mod_http2             x86_64      2.0.26-2.el9_4.1     appstream      163 k   mod_lua               x86_64      2.4.62-1.el9_5.2     appstream       59 k  ​  事务概要  ===============================================================================  安装  11 软件包  ​  总下载:2.0 M  安装大小:6.1 M  确定吗?[y/N]:  ​  #只下载不安装  [root@bogon dnf]# yum install httpd --downloadonly 仓库            大小
 ===============================================================================
 安装:
  httpd                  x86_64      2.4.62-1.el9_5.2      appstream       45 k
 安装依赖关系:
  apr                    x86_64      1.7.0-12.el9_3        appstream      122 k
  apr-util               x86_64      1.6.1-23.el9          appstream       94 k
  apr-util-bdb           x86_64      1.6.1-23.el9          appstream       12 k
  httpd-core             x86_64      2.4.62-1.el9_5.2      appstream      1.4 M
  httpd-filesystem       noarch      2.4.62-1.el9_5.2      appstream       12 k
  httpd-tools            x86_64      2.4.62-1.el9_5.2      appstream       79 k
  rocky-logos-httpd      noarch      90.15-2.el9           appstream       24 k
 安装弱的依赖:
  apr-util-openssl       x86_64      1.6.1-23.el9          appstream       14 k
  mod_http2              x86_64      2.0.26-2.el9_4.1      appstream      163 k
  mod_lua                x86_64      2.4.62-1.el9_5.2      appstream       59 k
 ​
 事务概要
 ===============================================================================
 安装  11 软件包
 ​
 总下载:2.0 M
 安装大小:6.1 M
 YUM将仅会从事务下载软件包。
 确定吗?[y/N]: y #确定下载
 下载软件包:
 (1/11): apr-util-openssl-1.6.1-23.el9.x86_64.r  54 kB/s |  14 kB     00:00    
 (2/11): apr-util-bdb-1.6.1-23.el9.x86_64.rpm    44 kB/s |  12 kB     00:00    
 (3/11): rocky-logos-httpd-90.15-2.el9.noarch.r  79 kB/s |  24 kB     00:00    
 (4/11): apr-util-1.6.1-23.el9.x86_64.rpm       365 kB/s |  94 kB     00:00    
 (5/11): mod_http2-2.0.26-2.el9_4.1.x86_64.rpm  472 kB/s | 163 kB     00:00    
 (6/11): apr-1.7.0-12.el9_3.x86_64.rpm          392 kB/s | 122 kB     00:00    
 (7/11): mod_lua-2.4.62-1.el9_5.2.x86_64.rpm    573 kB/s |  59 kB     00:00    
 (8/11): httpd-tools-2.4.62-1.el9_5.2.x86_64.rp 992 kB/s |  79 kB     00:00    
 (9/11): httpd-filesystem-2.4.62-1.el9_5.2.noar 145 kB/s |  12 kB     00:00    
 (10/11): httpd-core-2.4.62-1.el9_5.2.x86_64.rp 3.0 MB/s | 1.4 MB     00:00    
 (11/11): httpd-2.4.62-1.el9_5.2.x86_64.rpm     110 kB/s |  45 kB     00:00    
 -------------------------------------------------------------------------------
 总计                                           1.0 MB/s | 2.0 MB     00:01     
 Rocky Linux 9 - AppStream                      1.7 MB/s | 1.7 kB     00:00    
 导入 GPG 公钥 0x350D275D:
  Userid: "Rocky Enterprise Software Foundation - Release key 2022 "
  指纹: 21CB 256A E16F C54C 6E65 2949 702D 426D 350D 275D
  来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
 确定吗?[y/N]: y  #确认
 导入公钥成功
 完毕!
 下载的软件包保存在缓存中,直到下次成功执行事务。
 您可以通过执行 'yum clean packages' 删除软件包缓存。
 [root@bogon dnf]# ls -ltr
 总用量 13872
 drwxr-xr-x. 3 root root      40  5月 22 09:01 baseos-522ed8e2b2f761ff
 -rw-r--r--. 1 root root  677843  5月 22 09:01 baseos-filenames.solvx
 -rw-r--r--. 1 root root  430325  5月 22 09:01 baseos-updateinfo.solvx
 -rw-r--r--. 1 root root 6299074  5月 22 09:01 appstream-filenames.solvx
 -rw-r--r--. 1 root root 1609132  5月 22 09:01 appstream-updateinfo.solvx
 drwxr-xr-x. 3 root root      40  5月 22 09:01 extras-90dfbd6ba528f77b
 -rw-r--r--. 1 root root    2985  5月 22 09:01 extras-filenames.solvx
 -rw-r--r--. 1 root root 1785259  5月 22 09:01 baseos.solv
 -rw-r--r--. 1 root root 2675364  5月 22 09:01 appstream.solv
 -rw-r--r--. 1 root root   20622  5月 22 09:01 extras.solv
 -rw-r--r--. 1 root root  679936  5月 22 09:01 packages.db
 -rw-r--r--. 1 root root       0  5月 27 19:53 last_makecache
 drwxr-xr-x. 4 root root      56  5月 27 20:06 appstream-25485261a76941d3
 -rw-r--r--. 1 root root       2  5月 27 20:06 expired_repos.json
 -rw-r--r--. 1 root root    1008  5月 27 20:06 tempfiles.json
 [root@bogon ~]# cd /var/cache
 [root@bogon cache]# cd dnf/
 [root@bogon dnf]# cd appstream-25485261a76941d3
 [root@bogon appstream-25485261a76941d3]# ls
 mirrorlist  packages  repodata
 [root@bogon appstream-25485261a76941d3]# cd packages/
 [root@bogon packages]# ls
 apr-1.7.0-12.el9_3.x86_64.rpm
 apr-util-1.6.1-23.el9.x86_64.rpm
 apr-util-bdb-1.6.1-23.el9.x86_64.rpm
 apr-util-openssl-1.6.1-23.el9.x86_64.rpm
 httpd-2.4.62-1.el9_5.2.x86_64.rpm
 httpd-core-2.4.62-1.el9_5.2.x86_64.rpm
 httpd-filesystem-2.4.62-1.el9_5.2.noarch.rpm
 httpd-tools-2.4.62-1.el9_5.2.x86_64.rpm
 mod_http2-2.0.26-2.el9_4.1.x86_64.rpm
 mod_lua-2.4.62-1.el9_5.2.x86_64.rpm
 rocky-logos-httpd-90.15-2.el9.noarch.rpm
 [root@bogon packages]# pwd
 /var/cache/dnf/appstream-25485261a76941d3/packages
 #centos7不是这个路径
 ​
 #演示单包安装 手动解决依赖关系
 [root@bogon home]# ls
 apr-1.7.0-12.el9_3.x86_64.rpm
 apr-util-1.6.1-23.el9.x86_64.rpm
 apr-util-bdb-1.6.1-23.el9.x86_64.rpm
 apr-util-openssl-1.6.1-23.el9.x86_64.rpm
 httpd-2.4.62-1.el9_5.2.x86_64.rpm
 httpd-core-2.4.62-1.el9_5.2.x86_64.rpm
 httpd-filesystem-2.4.62-1.el9_5.2.noarch.rpm
 httpd-tools-2.4.62-1.el9_5.2.x86_64.rpm
 mod_http2-2.0.26-2.el9_4.1.x86_64.rpm
 mod_lua-2.4.62-1.el9_5.2.x86_64.rpm
 rocky-logos-httpd-90.15-2.el9.noarch.rpm
 [root@bogon home]# rpm -ivh httpd-2.4.62-1.el9_5.2.x86_64.rpm
 错误:依赖检测失败:
         httpd-core = 0:2.4.62-1.el9_5.2 被 httpd-2.4.62-1.el9_5.2.x86_64 需要
         system-logos-httpd 被 httpd-2.4.62-1.el9_5.2.x86_64 需要
 
  

(二)非交互式安装

 
[root@bogon home]# yum install -y httpd
 上次元数据过期检查:0:26:31 前,执行于 2025年05月27日 星期二 19时53分18秒。
 依赖关系解决。
 ===============================================================================
  软件包                 架构        版本                  仓库            大小
 ===============================================================================
 安装:
  httpd                  x86_64      2.4.62-1.el9_5.2      appstream       45 k
 安装依赖关系:
  apr                    x86_64      1.7.0-12.el9_3        appstream      122 k
  apr-util               x86_64      1.6.1-23.el9          appstream       94 k
  apr-util-bdb           x86_64      1.6.1-23.el9          appstream       12 k
  httpd-core             x86_64      2.4.62-1.el9_5.2      appstream      1.4 M
  httpd-filesystem       noarch      2.4.62-1.el9_5.2      appstream       12 k
  httpd-tools            x86_64      2.4.62-1.el9_5.2      appstream       79 k
  rocky-logos-httpd      noarch      90.15-2.el9           appstream       24 k
 安装弱的依赖:
  apr-util-openssl       x86_64      1.6.1-23.el9          appstream       14 k
  mod_http2              x86_64      2.0.26-2.el9_4.1      appstream      163 k
  mod_lua                x86_64      2.4.62-1.el9_5.2      appstream       59 k
 ​
 事务概要
 ===============================================================================
 安装  11 软件包
 ​
 总下载:2.0 M
 安装大小:6.1 M
 下载软件包:
 (1/11): apr-util-openssl-1.6.1-23.el9.x86_64.r  46 kB/s |  14 kB     00:00    
 (2/11): apr-util-bdb-1.6.1-23.el9.x86_64.rpm    38 kB/s |  12 kB     00:00    
 (3/11): rocky-logos-httpd-90.15-2.el9.noarch.r  73 kB/s |  24 kB     00:00    
 (4/11): apr-util-1.6.1-23.el9.x86_64.rpm       338 kB/s |  94 kB     00:00    
 (5/11): mod_http2-2.0.26-2.el9_4.1.x86_64.rpm  429 kB/s | 163 kB     00:00    
 (6/11): apr-1.7.0-12.el9_3.x86_64.rpm          327 kB/s | 122 kB     00:00    
 (7/11): mod_lua-2.4.62-1.el9_5.2.x86_64.rpm    445 kB/s |  59 kB     00:00    
 (8/11): httpd-tools-2.4.62-1.el9_5.2.x86_64.rp 827 kB/s |  79 kB     00:00    
 (9/11): httpd-filesystem-2.4.62-1.el9_5.2.noar 129 kB/s |  12 kB     00:00    
 (10/11): httpd-2.4.62-1.el9_5.2.x86_64.rpm      55 kB/s |  45 kB     00:00    
 (11/11): httpd-core-2.4.62-1.el9_5.2.x86_64.rp 1.6 MB/s | 1.4 MB     00:00    
 -------------------------------------------------------------------------------
 总计                                           744 kB/s | 2.0 MB     00:02     
 运行事务检查
 事务检查成功。
 运行事务测试
 事务测试成功。
 运行事务
   准备中  :                                                                1/1 
   安装    : apr-1.7.0-12.el9_3.x86_64                                     1/11 
   安装    : apr-util-bdb-1.6.1-23.el9.x86_64                              2/11 
   安装    : apr-util-1.6.1-23.el9.x86_64                                  3/11 
   安装    : apr-util-openssl-1.6.1-23.el9.x86_64                          4/11 
   安装    : httpd-tools-2.4.62-1.el9_5.2.x86_64                           5/11 
   运行脚本: httpd-filesystem-2.4.62-1.el9_5.2.noarch                      6/11 
   安装    : httpd-filesystem-2.4.62-1.el9_5.2.noarch                      6/11 
   安装    : httpd-core-2.4.62-1.el9_5.2.x86_64                            7/11 
   安装    : mod_lua-2.4.62-1.el9_5.2.x86_64                               8/11 
   安装    : rocky-logos-httpd-90.15-2.el9.noarch                          9/11 
   安装    : mod_http2-2.0.26-2.el9_4.1.x86_64                            10/11 
   安装    : httpd-2.4.62-1.el9_5.2.x86_64                                11/11 
   运行脚本: httpd-2.4.62-1.el9_5.2.x86_64                                11/11 
   验证    : rocky-logos-httpd-90.15-2.el9.noarch                          1/11 
   验证    : apr-util-openssl-1.6.1-23.el9.x86_64                          2/11 
   验证    : apr-util-bdb-1.6.1-23.el9.x86_64                              3/11 
   验证    : apr-util-1.6.1-23.el9.x86_64                                  4/11 
   验证    : mod_http2-2.0.26-2.el9_4.1.x86_64                             5/11 
   验证    : apr-1.7.0-12.el9_3.x86_64                                     6/11 
   验证    : mod_lua-2.4.62-1.el9_5.2.x86_64                               7/11 
   验证    : httpd-tools-2.4.62-1.el9_5.2.x86_64                           8/11 
   验证    : httpd-filesystem-2.4.62-1.el9_5.2.noarch                      9/11 
   验证    : httpd-core-2.4.62-1.el9_5.2.x86_64                           10/11 
   验证    : httpd-2.4.62-1.el9_5.2.x86_64                                11/11 
 ​
 已安装:
   apr-1.7.0-12.el9_3.x86_64                                                    
   apr-util-1.6.1-23.el9.x86_64                                                 
   apr-util-bdb-1.6.1-23.el9.x86_64                                             
   apr-util-openssl-1.6.1-23.el9.x86_64                                         
   httpd-2.4.62-1.el9_5.2.x86_64                                                
   httpd-core-2.4.62-1.el9_5.2.x86_64                                           
   httpd-filesystem-2.4.62-1.el9_5.2.noarch                                     
   httpd-tools-2.4.62-1.el9_5.2.x86_64                                          
   mod_http2-2.0.26-2.el9_4.1.x86_64                                            
   mod_lua-2.4.62-1.el9_5.2.x86_64                                              
   rocky-logos-httpd-90.15-2.el9.noarch                                         
 ​
 完毕!

(三)卸载软件

 [root@bogon home]# rpm -ev httpd  
 #用--force强制卸载也不行 只能一个依赖一个依赖的卸载
 错误:依赖检测失败:
         httpd >= 2.4.51-7 被 (已安裝) mod_http2-2.0.26-2.el9_4.1.x86_64 需要
 #用yum卸载
 [root@bogon home]# yum remove httpd
 依赖关系解决。
 ===============================================================================
  软件包                架构       版本                    仓库            大小
 ===============================================================================
 移除:
  httpd                 x86_64     2.4.62-1.el9_5.2        @appstream      59 k
 清除未被使用的依赖关系:
  apr                   x86_64     1.7.0-12.el9_3          @appstream     288 k
  apr-util              x86_64     1.6.1-23.el9            @appstream     211 k
  apr-util-bdb          x86_64     1.6.1-23.el9            @appstream      15 k
  apr-util-openssl      x86_64     1.6.1-23.el9            @appstream      23 k
  httpd-core            x86_64     2.4.62-1.el9_5.2        @appstream     4.7 M
  httpd-filesystem      noarch     2.4.62-1.el9_5.2        @appstream     464  
  httpd-tools           x86_64     2.4.62-1.el9_5.2        @appstream     199 k
  mod_http2             x86_64     2.0.26-2.el9_4.1        @appstream     442 k
  mod_lua               x86_64     2.4.62-1.el9_5.2        @appstream     142 k
  rocky-logos-httpd     noarch     90.15-2.el9             @appstream      24 k
 ​
 事务概要
 ===============================================================================
 移除  11 软件包
 ​
 将会释放空间:6.1 M
 确定吗?[y/N]: y
 运行事务检查
 事务检查成功。
 运行事务测试
 事务测试成功。
 运行事务
   准备中  :                                                                1/1 
   运行脚本: httpd-2.4.62-1.el9_5.2.x86_64                                 1/11 
   删除    : httpd-2.4.62-1.el9_5.2.x86_64                                 1/11 
   运行脚本: httpd-2.4.62-1.el9_5.2.x86_64                                 1/11 
   删除    : mod_lua-2.4.62-1.el9_5.2.x86_64                               2/11 
   删除    : mod_http2-2.0.26-2.el9_4.1.x86_64                             3/11 
   删除    : rocky-logos-httpd-90.15-2.el9.noarch                          4/11 
   删除    : httpd-core-2.4.62-1.el9_5.2.x86_64                            5/11 
   删除    : httpd-tools-2.4.62-1.el9_5.2.x86_64                           6/11 
   删除    : httpd-filesystem-2.4.62-1.el9_5.2.noarch                      7/11 
   删除    : apr-util-1.6.1-23.el9.x86_64                                  8/11 
   删除    : apr-util-bdb-1.6.1-23.el9.x86_64                              9/11 
   删除    : apr-1.7.0-12.el9_3.x86_64                                    10/11 
   删除    : apr-util-openssl-1.6.1-23.el9.x86_64                         11/11 
   运行脚本: apr-util-openssl-1.6.1-23.el9.x86_64                         11/11 
   验证    : apr-1.7.0-12.el9_3.x86_64                                     1/11 
   验证    : apr-util-1.6.1-23.el9.x86_64                                  2/11 
   验证    : apr-util-bdb-1.6.1-23.el9.x86_64                              3/11 
   验证    : apr-util-openssl-1.6.1-23.el9.x86_64                          4/11 
   验证    : httpd-2.4.62-1.el9_5.2.x86_64                                 5/11 
   验证    : httpd-core-2.4.62-1.el9_5.2.x86_64                            6/11 
   验证    : httpd-filesystem-2.4.62-1.el9_5.2.noarch                      7/11 
   验证    : httpd-tools-2.4.62-1.el9_5.2.x86_64                           8/11 
   验证    : mod_http2-2.0.26-2.el9_4.1.x86_64                             9/11 
   验证    : mod_lua-2.4.62-1.el9_5.2.x86_64                              10/11 
   验证    : rocky-logos-httpd-90.15-2.el9.noarch                         11/11 
 ​
 已移除:
   apr-1.7.0-12.el9_3.x86_64                                                    
   apr-util-1.6.1-23.el9.x86_64                                                 
   apr-util-bdb-1.6.1-23.el9.x86_64                                             
   apr-util-openssl-1.6.1-23.el9.x86_64                                         
   httpd-2.4.62-1.el9_5.2.x86_64                                                
   httpd-core-2.4.62-1.el9_5.2.x86_64                                           
   httpd-filesystem-2.4.62-1.el9_5.2.noarch                                     
   httpd-tools-2.4.62-1.el9_5.2.x86_64                                          
   mod_http2-2.0.26-2.el9_4.1.x86_64                                            
   mod_lua-2.4.62-1.el9_5.2.x86_64                                              
   rocky-logos-httpd-90.15-2.el9.noarch                                         
 ​
 完毕!

(四)安装本地源

 
#挂载Rocky9镜像 如果不成功用图形界面试一下
 [root@localhost ~]# mount /dev/sr0 /mnt/
 mount: /mnt: WARNING: source write-protected, mounted read-only.
 [root@localhost ~]# cd /mnt/
 [root@localhost mnt]# ls
 AppStream  BaseOS  EFI  images  isolinux  LICENSE  media.repo
 [root@localhost mnt]# cd AppStream/
 [root@localhost AppStream]# ls
 Packages  repodata
 [root@localhost AppStream]# cd Packages
 [root@localhost Packages]# ls
 3  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
 [root@localhost Packages]# pwd
 /mnt/AppStream/Packages
 ​
 [root@localhost Packages]# cd /etc/yum.repos.d/
 [root@localhost yum.repos.d]# ls
 rocky-addons.repo  rocky-devel.repo  rocky-extras.repo  rocky.repo
 [root@localhost yum.repos.d]# mkdir backup
 [root@localhost yum.repos.d]# mv rocky* backup/
 [root@localhost yum.repos.d]# ls
 backup
 #修改配置文件
 [root@localhost yum.repos.d]# vim local.repo
 [local]
 name=local
 baseurl=file:///mnt/AppStream #指定路径,读取里面的两个文件
 enable=1
 gpgcheck=0
 #清除缓存文件
 [root@localhost yum.repos.d]# yum clean all
 0 个文件已删除
 [root@localhost yum.repos.d]# yum makecache
 local                                          180 MB/s | 7.9 MB     00:00    
 上次元数据过期检查:0:00:02 前,执行于 2025年05月27日 星期二 21时20分46秒。
 元数据缓存已建立。
 [root@localhost yum.repos.d]# yum search http
 上次元数据过期检查:0:00:19 前,执行于 2025年05月27日 星期二 21时20分46秒。
 =========================== 名称 和 概况 匹配:http ===========================
 fio-engine-http.x86_64 : HTTP engine for fio.
 http-parser.x86_64 : HTTP request/response parser for C
 http-parser.i686 : HTTP request/response parser for C
 httpcomponents-client.noarch : HTTP agent implementation based on
                              : httpcomponents HttpCore
 httpcomponents-core.noarch : Set of low level Java HTTP transport components
                            : for HTTP services
 httpd.x86_64 : Apache HTTP Server
 httpd-core.x86_64 : httpd minimal core
 httpd-devel.x86_64 : Development interfaces for the Apache HTTP Server
 httpd-filesystem.noarch : The basic directory layout for the Apache HTTP Server
 httpd-manual.noarch : Documentation for the Apache HTTP Server
 httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
 keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as
                                      : Keycloak client
 libnghttp2.x86_64 : A library implementing the HTTP/2 protocol
 mod_http2.x86_64 : module implementing HTTP/2 for Apache 2
 nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
 nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
 perl-HTTP-Cookies.noarch : HTTP cookie jars
 perl-HTTP-Message.noarch : HTTP style message
 perl-HTTP-Tiny.noarch : Small, simple, correct HTTP/1.1 client
 perl-LWP-Protocol-https.noarch : Provide HTTPS support for LWP::UserAgent
 perl-Net-HTTP.noarch : Low-level HTTP connection (client)
 python3-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD
                                              : as Keycloak client
 rocky-logos-httpd.noarch : Rocky Linux related icons and pictures used by httpd
 =============================== 名称 匹配:http ===============================
 libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in
                      : applications
 libmicrohttpd.i686 : Lightweight library for embedding a webserver in
                    : applications
 nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
 perl-HTTP-Date.noarch : Date conversion routines
 perl-HTTP-Negotiate.noarch : Choose a variant to serve
 =============================== 概况 匹配:http ===============================
 curl.x86_64 : A utility for getting files from remote servers (FTP, HTTP, and
             : others)
 elfutils-debuginfod.x86_64 : HTTP ELF/DWARF file server addressed by build-id
 elfutils-debuginfod-client.x86_64 : Library and command line client for
                                   : build-id HTTP ELF/DWARF server
 libserf.x86_64 : High-Performance Asynchronous HTTP Client Library
 libserf.i686 : High-Performance Asynchronous HTTP Client Library
 libsoup.x86_64 : Soup, an HTTP library implementation
 libsoup.i686 : Soup, an HTTP library implementation
 mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd
                        : Server
 mod_auth_openidc.x86_64 : OpenID Connect auth module for Apache HTTP Server
 mod_dav_svn.x86_64 : Apache httpd module for Subversion server
 mod_ldap.x86_64 : LDAP authentication modules for the Apache HTTP Server
 mod_lua.x86_64 : Lua scripting support for the Apache HTTP Server
 mod_md.x86_64 : Certificate provisioning using ACME for the Apache HTTP Server
 mod_proxy_cluster.x86_64 : JBoss mod_proxy_cluster for Apache httpd
 mod_proxy_html.x86_64 : HTML and XML content filters for the Apache HTTP Server
 mod_security.x86_64 : Security module for the Apache HTTP Server
 mod_session.x86_64 : Session interface for the Apache HTTP Server
 mod_ssl.x86_64 : SSL/TLS module for the Apache HTTP Server
 nbdkit-curl-plugin.x86_64 : HTTP/FTP (cURL) plugin for nbdkit
 neon.x86_64 : An HTTP and WebDAV client library
 neon.i686 : An HTTP and WebDAV client library
 python3-requests.noarch : HTTP library, written in Python, for human beings
 python3-urllib3.noarch : Python3 HTTP library with thread-safe connection
                        : pooling and file post
 python3.11-requests.noarch : HTTP library, written in Python, for human beings
 python3.11-urllib3.noarch : Python HTTP library with thread-safe connection
                           : pooling and file post
 python3.12-requests.noarch : HTTP library, written in Python, for human beings
 python3.12-urllib3.noarch : HTTP library with thread-safe connection pooling,
                           : file post, and more
 varnish.i686 : High-performance HTTP accelerator
 varnish.x86_64 : High-performance HTTP accelerator
 wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
 xmlrpc-c.x86_64 : Lightweight RPC library based on XML and HTTP
 xmlrpc-c.i686 : Lightweight RPC library based on XML and HTTP

(五)安装网络元

(六)源码包安装

 #拉入源码包文件
 [root@bogon ~]# ls
 公共  视频  文档  音乐  anaconda-ks.cfg      sshd_config
 模板  图片  下载  桌面  nginx-1.28.0.tar.gz
 把文件放入空间大的目录下
 [root@bogon ~]# mv nginx-1.28.0.tar.gz /home
 [root@bogon ~]# cd /home
 [root@bogon home]# ls
 hao  nginx-1.28.0.tar.gz
 #解压源码包
 [root@bogon home]# tar xf nginx-1.28.0.tar.gz -C /usr/local
 [root@bogon home]# cd /usr/local/nginx-1.28.0/
 [root@bogon nginx-1.28.0]# ls
 auto        CODE_OF_CONDUCT.md  contrib          LICENSE    SECURITY.md
 CHANGES     conf                CONTRIBUTING.md  man        src
 CHANGES.ru  configure           html             README.md
 #指定路径安装
 [root@bogon nginx-1.28.0]# ./configure --prefix=/usr/local/nginx
 checking for OS
  + Linux 5.14.0-503.40.1.el9_5.x86_64 x86_64
 checking for C compiler ... not found
 ​
 ./configure: error: C compiler cc is not found
 #缺乏依赖关系
 ​
 #安装gcc make 
 [root@bogon nginx-1.28.0]# yum install -y gcc make
 上次元数据过期检查:2:09:10 前,执行于 2025年05月28日 星期三 12时29分59秒。
 未找到匹配的参数: make
 错误:没有任何匹配: make
 #如果显示如上,重新挂载本地源
 [root@bogon yum.repos.d]# yum install -y gcc make
 Rocky Linux 9 - BaseOS                         553 kB/s | 2.3 MB     00:04    
 Rocky Linux 9 - AppStream                      1.5 MB/s | 8.4 MB     00:05    
 Rocky Linux 9 - Extras                          11 kB/s |  16 kB     00:01    
 依赖关系解决。
 ===============================================================================
  软件包              架构       版本                       仓库           大小
 ===============================================================================
 安装:
  gcc                 x86_64     11.5.0-5.el9_5             appstream      32 M
  make                x86_64     1:4.3-8.el9                baseos        529 k
 安装依赖关系:
  glibc-devel         x86_64     2.34-125.el9_5.8           appstream      25 k
  glibc-headers       x86_64     2.34-125.el9_5.8           appstream     429 k
  kernel-headers      x86_64     5.14.0-503.40.1.el9_5      appstream     3.5 M
  libxcrypt-devel     x86_64     4.4.18-3.el9               local          28 k
 ​
 事务概要
 ===============================================================================
 安装  6 软件包
 ​
 总计:37 M
 总下载:37 M
 安装大小:96 M
 下载软件包:
 (1/5): make-4.3-8.el9.x86_64.rpm               652 kB/s | 529 kB     00:00    
 (2/5): glibc-devel-2.34-125.el9_5.8.x86_64.rpm 124 kB/s |  25 kB     00:00    
 (3/5): glibc-headers-2.34-125.el9_5.8.x86_64.r 305 kB/s | 429 kB     00:01    
 (4/5): kernel-headers-5.14.0-503.40.1.el9_5.x8 793 kB/s | 3.5 MB     00:04    
 (5/5): gcc-11.5.0-5.el9_5.x86_64.rpm           2.0 MB/s |  32 MB     00:16    
 -------------------------------------------------------------------------------
 总计                                           2.0 MB/s |  37 MB     00:18     
 运行事务检查
 事务检查成功。
 运行事务测试
 事务测试成功。
 运行事务
   准备中  :                                                                1/1 
   安装    : kernel-headers-5.14.0-503.40.1.el9_5.x86_64                    1/6 
   安装    : glibc-headers-2.34-125.el9_5.8.x86_64                          2/6 
   安装    : glibc-devel-2.34-125.el9_5.8.x86_64                            3/6 
   安装    : libxcrypt-devel-4.4.18-3.el9.x86_64                            4/6 
   安装    : make-1:4.3-8.el9.x86_64                                        5/6 
   安装    : gcc-11.5.0-5.el9_5.x86_64                                      6/6 
   运行脚本: gcc-11.5.0-5.el9_5.x86_64                                      6/6 
   验证    : libxcrypt-devel-4.4.18-3.el9.x86_64                            1/6 
   验证    : make-1:4.3-8.el9.x86_64                                        2/6 
   验证    : gcc-11.5.0-5.el9_5.x86_64                                      3/6 
   验证    : glibc-headers-2.34-125.el9_5.8.x86_64                          4/6 
   验证    : glibc-devel-2.34-125.el9_5.8.x86_64                            5/6 
   验证    : kernel-headers-5.14.0-503.40.1.el9_5.x86_64                    6/6 
 ​
 已安装:
   gcc-11.5.0-5.el9_5.x86_64                                                    
   glibc-devel-2.34-125.el9_5.8.x86_64                                          
   glibc-headers-2.34-125.el9_5.8.x86_64                                        
   kernel-headers-5.14.0-503.40.1.el9_5.x86_64                                  
   libxcrypt-devel-4.4.18-3.el9.x86_64                                          
   make-1:4.3-8.el9.x86_64                                                      
 ​
 完毕!
 #再次尝试安装,发现缺少pcre
 [root@bogon nginx-1.28.0]# ./configure --prefix=/usr/local/nginx
 checking for OS
  + Linux 5.14.0-503.40.1.el9_5.x86_64 x86_64
 checking for C compiler ... found
  + using GNU C compiler
  + gcc version: 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
 checking for gcc -pipe switch ... found
 checking for -Wl,-E switch ... found
 checking for gcc builtin atomic operations ... found
 checking for C99 variadic macros ... found
 checking for gcc variadic macros ... found
 checking for gcc builtin 64 bit byteswap ... found
 checking for unistd.h ... found
 checking for inttypes.h ... found
 checking for limits.h ... found
 checking for sys/filio.h ... not found
 checking for sys/param.h ... found
 checking for sys/mount.h ... found
 checking for sys/statvfs.h ... found
 checking for crypt.h ... found
 checking for Linux specific features
 checking for epoll ... found
 checking for EPOLLRDHUP ... found
 checking for EPOLLEXCLUSIVE ... found
 checking for eventfd() ... found
 checking for O_PATH ... found
 checking for sendfile() ... found
 checking for sendfile64() ... found
 checking for sys/prctl.h ... found
 checking for prctl(PR_SET_DUMPABLE) ... found
 checking for prctl(PR_SET_KEEPCAPS) ... found
 checking for capabilities ... found
 checking for crypt_r() ... found
 checking for sys/vfs.h ... found
 checking for BPF sockhash ... found
 checking for SO_COOKIE ... found
 checking for UDP_SEGMENT ... found
 checking for nobody group ... found
 checking for poll() ... found
 checking for /dev/poll ... not found
 checking for kqueue ... not found
 checking for crypt() ... not found
 checking for crypt() in libcrypt ... found
 checking for F_READAHEAD ... not found
 checking for posix_fadvise() ... found
 checking for O_DIRECT ... found
 checking for F_NOCACHE ... not found
 checking for directio() ... not found
 checking for statfs() ... found
 checking for statvfs() ... found
 checking for dlopen() ... found
 checking for sched_yield() ... found
 checking for sched_setaffinity() ... found
 checking for SO_SETFIB ... not found
 checking for SO_REUSEPORT ... found
 checking for SO_ACCEPTFILTER ... not found
 checking for SO_BINDANY ... not found
 checking for IP_TRANSPARENT ... found
 checking for IP_BINDANY ... not found
 checking for IP_BIND_ADDRESS_NO_PORT ... found
 checking for IP_RECVDSTADDR ... not found
 checking for IP_SENDSRCADDR ... not found
 checking for IP_PKTINFO ... found
 checking for IPV6_RECVPKTINFO ... found
 checking for IP_MTU_DISCOVER ... found
 checking for IPV6_MTU_DISCOVER ... found
 checking for IP_DONTFRAG ... not found
 checking for IPV6_DONTFRAG ... found
 checking for TCP_DEFER_ACCEPT ... found
 checking for TCP_KEEPIDLE ... found
 checking for TCP_FASTOPEN ... found
 checking for TCP_INFO ... found
 checking for accept4() ... found
 checking for int size ... 4 bytes
 checking for long size ... 8 bytes
 checking for long long size ... 8 bytes
 checking for void * size ... 8 bytes
 checking for uint32_t ... found
 checking for uint64_t ... found
 checking for sig_atomic_t ... found
 checking for sig_atomic_t size ... 4 bytes
 checking for socklen_t ... found
 checking for in_addr_t ... found
 checking for in_port_t ... found
 checking for rlim_t ... found
 checking for uintptr_t ... uintptr_t found
 checking for system byte ordering ... little endian
 checking for size_t size ... 8 bytes
 checking for off_t size ... 8 bytes
 checking for time_t size ... 8 bytes
 checking for AF_INET6 ... found
 checking for setproctitle() ... not found
 checking for pread() ... found
 checking for pwrite() ... found
 checking for pwritev() ... found
 checking for strerrordesc_np() ... found
 checking for localtime_r() ... found
 checking for clock_gettime(CLOCK_MONOTONIC) ... found
 checking for posix_memalign() ... found
 checking for memalign() ... found
 checking for mmap(MAP_ANON|MAP_SHARED) ... found
 checking for mmap("/dev/zero", MAP_SHARED) ... found
 checking for System V shared memory ... found
 checking for POSIX semaphores ... found
 checking for struct msghdr.msg_control ... found
 checking for ioctl(FIONBIO) ... found
 checking for ioctl(FIONREAD) ... found
 checking for struct tm.tm_gmtoff ... found
 checking for struct dirent.d_namlen ... not found
 checking for struct dirent.d_type ... found
 checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
 checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
 checking for openat(), fstatat() ... found
 checking for getaddrinfo() ... found
 checking for PCRE2 library ... not found
 checking for PCRE library ... not found
 checking for PCRE library in /usr/local/ ... not found
 checking for PCRE library in /usr/include/pcre/ ... not found
 checking for PCRE library in /usr/pkg/ ... not found
 checking for PCRE library in /opt/local/ ... not found
 checking for PCRE library in /opt/homebrew/ ... not found
 ​
 ./configure: error: the HTTP rewrite module requires the PCRE library.
 You can either disable the module by using --without-http_rewrite_module
 option, or install the PCRE library into the system, or build the PCRE library
 statically from the source with nginx by using --with-pcre= option.
 #安装pcre,有pcre-utils 和 pcre-devel 版本 
 [root@bogon nginx-1.28.0]# yum install -y pcre-devel
 上次元数据过期检查:0:05:30 前,执行于 2025年05月28日 星期三 15时14分48秒。
 依赖关系解决。
 ===============================================================================
  软件包             架构           版本                仓库               大小
 ===============================================================================
 安装:
  pcre-devel         x86_64         8.44-4.el9          appstream         469 k
 安装依赖关系:
  pcre-cpp           x86_64         8.44-4.el9          appstream          25 k
  pcre-utf16         x86_64         8.44-4.el9          appstream         183 k
  pcre-utf32         x86_64         8.44-4.el9          appstream         173 k
 ​
 事务概要
 ===============================================================================
 安装  4 软件包
 ​
 总下载:850 k
 安装大小:2.6 M
 下载软件包:
 (1/4): pcre-utf32-8.44-4.el9.x86_64.rpm        157 kB/s | 173 kB     00:01    
 (2/4): pcre-utf16-8.44-4.el9.x86_64.rpm        163 kB/s | 183 kB     00:01    
 (3/4): pcre-cpp-8.44-4.el9.x86_64.rpm          227 kB/s |  25 kB     00:00    
 (4/4): pcre-devel-8.44-4.el9.x86_64.rpm        357 kB/s | 469 kB     00:01    
 -------------------------------------------------------------------------------
 总计                                           286 kB/s | 850 kB     00:02     
 运行事务检查
 事务检查成功。
 运行事务测试
 事务测试成功。
 运行事务
   准备中  :                                                                1/1 
   安装    : pcre-cpp-8.44-4.el9.x86_64                                     1/4 
   安装    : pcre-utf16-8.44-4.el9.x86_64                                   2/4 
   安装    : pcre-utf32-8.44-4.el9.x86_64                                   3/4 
   安装    : pcre-devel-8.44-4.el9.x86_64                                   4/4 
   运行脚本: pcre-devel-8.44-4.el9.x86_64                                   4/4 
   验证    : pcre-utf32-8.44-4.el9.x86_64                                   1/4 
   验证    : pcre-utf16-8.44-4.el9.x86_64                                   2/4 
   验证    : pcre-devel-8.44-4.el9.x86_64                                   3/4 
   验证    : pcre-cpp-8.44-4.el9.x86_64                                     4/4 
 ​
 已安装:
   pcre-cpp-8.44-4.el9.x86_64             pcre-devel-8.44-4.el9.x86_64          
   pcre-utf16-8.44-4.el9.x86_64           pcre-utf32-8.44-4.el9.x86_64          
 ​
 完毕!
 #同理安装 zlib
 [root@bogon nginx-1.28.0]# ./configure --prefix=/usr/local/nginx
 checking for OS
  + Linux 5.14.0-503.40.1.el9_5.x86_64 x86_64
 checking for C compiler ... found
  + using GNU C compiler
 ./configure: error: the HTTP gzip module requires the zlib library.
 You can either disable the module by using --without-http_gzip_module
 option, or install the zlib library into the system, or build the zlib library
 statically from the source with nginx by using --with-zlib= option.
 #安装zlib-devel
 [root@bogon nginx-1.28.0]# yum install -y zlib-devel
 上次元数据过期检查:0:07:31 前,执行于 2025年05月28日 星期三 15时14分48秒。
 依赖关系解决。
 ===============================================================================
  软件包             架构           版本                    仓库           大小
 ===============================================================================
 安装:
  zlib-devel         x86_64         1.2.11-40.el9           local          44 k
 ​
 事务概要
 ===============================================================================
 安装  1 软件包
 ​
 总计:44 k
 安装大小:138 k
 下载软件包:
 运行事务检查
 事务检查成功。
 运行事务测试
 事务测试成功。
 运行事务
   准备中  :                                                                1/1 
   安装    : zlib-devel-1.2.11-40.el9.x86_64                                1/1 
   运行脚本: zlib-devel-1.2.11-40.el9.x86_64                                1/1 
   验证    : zlib-devel-1.2.11-40.el9.x86_64                                1/1 
 ​
 已安装:
   zlib-devel-1.2.11-40.el9.x86_64                                              
 ​
 完毕!
 #再次安装
 [root@bogon nginx-1.28.0]# ./configure --prefix=/usr/local/nginx
 checking for OS
  + Linux 5.14.0-503.40.1.el9_5.x86_64 x86_64
 checking for C compiler ... found
  + using GNU C compiler
  + gcc version: 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
 checking for gcc -pipe switch ... found
 checking for -Wl,-E switch ... found
 checking for gcc builtin atomic operations ... found
 checking for C99 variadic macros ... found
 checking for gcc variadic macros ... found
 checking for gcc builtin 64 bit byteswap ... found
 checking for unistd.h ... found
 checking for inttypes.h ... found
 checking for limits.h ... found
 checking for sys/filio.h ... not found
 checking for sys/param.h ... found
 checking for sys/mount.h ... found
 checking for sys/statvfs.h ... found
 checking for crypt.h ... found
 checking for Linux specific features
 checking for epoll ... found
 checking for EPOLLRDHUP ... found
 checking for EPOLLEXCLUSIVE ... found
 checking for eventfd() ... found
 checking for O_PATH ... found
 checking for sendfile() ... found
 checking for sendfile64() ... found
 checking for sys/prctl.h ... found
 checking for prctl(PR_SET_DUMPABLE) ... found
 checking for prctl(PR_SET_KEEPCAPS) ... found
 checking for capabilities ... found
 checking for crypt_r() ... found
 checking for sys/vfs.h ... found
 checking for BPF sockhash ... found
 checking for SO_COOKIE ... found
 checking for UDP_SEGMENT ... found
 checking for nobody group ... found
 checking for poll() ... found
 checking for /dev/poll ... not found
 checking for kqueue ... not found
 checking for crypt() ... not found
 checking for crypt() in libcrypt ... found
 checking for F_READAHEAD ... not found
 checking for posix_fadvise() ... found
 checking for O_DIRECT ... found
 checking for F_NOCACHE ... not found
 checking for directio() ... not found
 checking for statfs() ... found
 checking for statvfs() ... found
 checking for dlopen() ... found
 checking for sched_yield() ... found
 checking for sched_setaffinity() ... found
 checking for SO_SETFIB ... not found
 checking for SO_REUSEPORT ... found
 checking for SO_ACCEPTFILTER ... not found
 checking for SO_BINDANY ... not found
 checking for IP_TRANSPARENT ... found
 checking for IP_BINDANY ... not found
 checking for IP_BIND_ADDRESS_NO_PORT ... found
 checking for IP_RECVDSTADDR ... not found
 checking for IP_SENDSRCADDR ... not found
 checking for IP_PKTINFO ... found
 checking for IPV6_RECVPKTINFO ... found
 checking for IP_MTU_DISCOVER ... found
 checking for IPV6_MTU_DISCOVER ... found
 checking for IP_DONTFRAG ... not found
 checking for IPV6_DONTFRAG ... found
 checking for TCP_DEFER_ACCEPT ... found
 checking for TCP_KEEPIDLE ... found
 checking for TCP_FASTOPEN ... found
 checking for TCP_INFO ... found
 checking for accept4() ... found
 checking for int size ... 4 bytes
 checking for long size ... 8 bytes
 checking for long long size ... 8 bytes
 checking for void * size ... 8 bytes
 checking for uint32_t ... found
 checking for uint64_t ... found
 checking for sig_atomic_t ... found
 checking for sig_atomic_t size ... 4 bytes
 checking for socklen_t ... found
 checking for in_addr_t ... found
 checking for in_port_t ... found
 checking for rlim_t ... found
 checking for uintptr_t ... uintptr_t found
 checking for system byte ordering ... little endian
 checking for size_t size ... 8 bytes
 checking for off_t size ... 8 bytes
 checking for time_t size ... 8 bytes
 checking for AF_INET6 ... found
 checking for setproctitle() ... not found
 checking for pread() ... found
 checking for pwrite() ... found
 checking for pwritev() ... found
 checking for strerrordesc_np() ... found
 checking for localtime_r() ... found
 checking for clock_gettime(CLOCK_MONOTONIC) ... found
 checking for posix_memalign() ... found
 checking for memalign() ... found
 checking for mmap(MAP_ANON|MAP_SHARED) ... found
 checking for mmap("/dev/zero", MAP_SHARED) ... found
 checking for System V shared memory ... found
 checking for POSIX semaphores ... found
 checking for struct msghdr.msg_control ... found
 checking for ioctl(FIONBIO) ... found
 checking for ioctl(FIONREAD) ... found
 checking for struct tm.tm_gmtoff ... found
 checking for struct dirent.d_namlen ... not found
 checking for struct dirent.d_type ... found
 checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
 checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
 checking for openat(), fstatat() ... found
 checking for getaddrinfo() ... found
 checking for PCRE2 library ... not found
 checking for PCRE library ... found
 checking for PCRE JIT support ... found
 checking for zlib library ... found
 creating objs/Makefile
 ​
 Configuration summary
   + using system PCRE library
   + OpenSSL library is not used
   + using system zlib library
 ​
   nginx path prefix: "/usr/local/nginx"
   nginx binary file: "/usr/local/nginx/sbin/nginx"
   nginx modules path: "/usr/local/nginx/modules"
   nginx configuration prefix: "/usr/local/nginx/conf"
   nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
   nginx pid file: "/usr/local/nginx/logs/nginx.pid"
   nginx error log file: "/usr/local/nginx/logs/error.log"
   nginx http access log file: "/usr/local/nginx/logs/access.log"
   nginx http client request body temporary files: "client_body_temp"
   nginx http proxy temporary files: "proxy_temp"
   nginx http fastcgi temporary files: "fastcgi_temp"
   nginx http uwsgi temporary files: "uwsgi_temp"
   nginx http scgi temporary files: "scgi_temp"
 [root@bogon nginx-1.28.0]# ls
 auto        CODE_OF_CONDUCT.md  contrib          LICENSE   objs         src
 CHANGES     conf                CONTRIBUTING.md  Makefile  README.md
 CHANGES.ru  configure           html             man       SECURITY.md
 #配置完成后
 #在源码包下生成Makefile文件
 #进行编译
 [root@bogon nginx-1.28.0]# make
 make -f objs/Makefile
 make[1]: 进入目录“/usr/local/nginx-1.28.0”
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
         -o objs/src/core/nginx.o \
         src/core/nginx.c
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
         -o objs/src/core/ngx_log.o \
         src/core/ngx_log.c
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
         -o objs/src/core/ngx_palloc.o \
         src/core/ngx_palloc.c
         #中间省略
 -lcrypt -lpcre -lz \
 -Wl,-E
 sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
         -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
         -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
         -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
         < man/nginx.8 > objs/nginx.8
 make[1]: 离开目录“/usr/local/nginx-1.28.0” #编译成功
 ​
 #安装
 [root@bogon nginx-1.28.0]# make install
 make -f objs/Makefile install
 make[1]: 进入目录“/usr/local/nginx-1.28.0”
 test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
 test -d '/usr/local/nginx/sbin' \
         || mkdir -p '/usr/local/nginx/sbin'
 test ! -f '/usr/local/nginx/sbin/nginx' \
         || mv '/usr/local/nginx/sbin/nginx' \
                 '/usr/local/nginx/sbin/nginx.old'
 cp objs/nginx '/usr/local/nginx/sbin/nginx'
 test -d '/usr/local/nginx/conf' \
         || mkdir -p '/usr/local/nginx/conf'
 cp conf/koi-win '/usr/local/nginx/conf'
 cp conf/koi-utf '/usr/local/nginx/conf'
 cp conf/win-utf '/usr/local/nginx/conf'
 test -f '/usr/local/nginx/conf/mime.types' \
         || cp conf/mime.types '/usr/local/nginx/conf'
 cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
 test -f '/usr/local/nginx/conf/fastcgi_params' \
         || cp conf/fastcgi_params '/usr/local/nginx/conf'
 cp conf/fastcgi_params \
         '/usr/local/nginx/conf/fastcgi_params.default'
 test -f '/usr/local/nginx/conf/fastcgi.conf' \
         || cp conf/fastcgi.conf '/usr/local/nginx/conf'
 cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
 test -f '/usr/local/nginx/conf/uwsgi_params' \
         || cp conf/uwsgi_params '/usr/local/nginx/conf'
 cp conf/uwsgi_params \
         '/usr/local/nginx/conf/uwsgi_params.default'
 test -f '/usr/local/nginx/conf/scgi_params' \
         || cp conf/scgi_params '/usr/local/nginx/conf'
 cp conf/scgi_params \
         '/usr/local/nginx/conf/scgi_params.default'
 test -f '/usr/local/nginx/conf/nginx.conf' \
         || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
 cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
 test -d '/usr/local/nginx/logs' \
         || mkdir -p '/usr/local/nginx/logs'
 test -d '/usr/local/nginx/logs' \
         || mkdir -p '/usr/local/nginx/logs'
 test -d '/usr/local/nginx/html' \
         || cp -R html '/usr/local/nginx'
 test -d '/usr/local/nginx/logs' \
         || mkdir -p '/usr/local/nginx/logs'
 make[1]: 离开目录“/usr/local/nginx-1.28.0”
 #可以合并命令 ./configure --prefix=/usr/local/nginx18  && make  && make install
 #验证
 [root@bogon nginx-1.28.0]# cd /usr/local/nginx
 [root@bogon nginx]# ls
 conf  html  logs  sbin
 [root@bogon nginx]# cd sbin/
 [root@bogon sbin]# ls
 nginx
 #虽然已经安装成功但是命令还不能用
 #命令优化
 [root@bogon sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
 #编译安装完成的软件默认不被systemd管理
 /usr/lib/systemd/system/
 #修改配置即可被systemd管理
 ​
 #卸载只需要将源码包删除即可
 [root@bogon local]# ls
 bin  games    lib    libexec  #nginx-1.28.0  
 share
 etc  include  lib64  #nginx  
 sbin          src
 [root@bogon local] pwd
 ​


 [root@localhost backup]# yum grouplist
 上次元数据过期检查:0:24:50 前,执行于 2025年05月27日 星期二 21时20分46秒。
 可用环境组:
    服务器
    工作站
    虚拟化主机
 已安装的环境组:
    带 GUI 的服务器
 已安装组:
    容器管理
    无头系统管理
 可用组:
    控制台互联网工具
    开发工具
    .NET Development
    图形管理工具
    网络服务器
    RPM 开发工具
    科学记数法支持
    安全性工具
    智能卡支持
    系统工具

七、总结

重点
rpm 安装及指令
yum 安装
源码包安装前提条件及安装
Linux开机流程
systend机制 及运行级别

你可能感兴趣的:(linux,java,服务器,程序管理)