目录
一、程序管理
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语言(高级语言中最底层的语言,一般结合汇编进行驱动编写)编写,安装前需要编译为二进制包;配置【如,安装路径,配置文件路径,运行用户,运行组,功能模块】--->编译--->安装;文件比较集中,便于后期进行维护与管理。
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
缓存保存路径
/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 #生成元数据缓存
-
命令选项
-y:非交互
交互式安装:yum install 软件名
Is this ok? y 安装 n 不下载不安装
非交互式安装:yum -y install 软件名
6、源码包(编译)安装
需要依赖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
-
案例
我们安装的时候发现下载数据元失败
[root@localhost ~]# yum install -y nginx local 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository 'local': - Curl error (37): Couldn't read a file:// file for file:///mnt/AppStream/repodata/repomd.xml [Couldn't open file /mnt/AppStream/repodata/repomd.xml] 错误:为仓库 'local' 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
所以我们得从外面下载源代码
访问Guthub(开源代码的网站)在右上方搜索栏搜索我们要下载的源(nginx),点击第一个我们要找的源。

进去之后文件为该源的源代码文件,此刻我们点击右下方的Release-1.28.0(最新版本)

拉到最下方,点击下载nginx-1.28.0.tar.gz

下载完成后直接拖入外部连接(Windterm)的文件管理夹中

之后我们发现在/下可以找到这个未解压的文件了,对它进行解压
[root@localhost ~]# ls 公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg nginx-1.28.0.tar.gz
解压到home目录下的logal(自行创建) [root@localhost ~]# [root@localhost ~]# tar xf nginx-1.28.0.tar.gz -C /home/logal/
解压完成之后内容如下
[root@localhost logal]# cd nginx-1.28.0/ [root@localhost nginx-1.28.0]# ls auto CHANGES.ru conf contrib html man SECURITY.md CHANGES CODE_OF_CONDUCT.md configure CONTRIBUTING.md LICENSE README.md src
设置安装目录
./configure --prefix=/home/logal/nginx(此目录不用创建) 如报错后,下载gcc 和 make环境 yum install -y gcc make #如没有报错,最后一行显示为缺少 PCRE 的库。我们继续下载 ./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=<path> option. 下载pcre-devel [root@localhost ~]# yum install -y pcre-devel 再次尝试 [root@localhost nginx-1.28.0]# ./configure --prefix=/home/logal/nginx 进行编译,输入make命令(必须在当前目录) 编译完成后输入make install 开始安装
给nginx设置软连接,使其直接可以使用
ln -s /home/logal/nginx/sbin/nginx /usr/sbin/nginx
7、二进制安装
只需要运行bin文件
-
案例
jdk-6u14-linux-x64.bin ./jdk-6u14-linux-x64.bin 根据提示进行操作即可
二、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 -
核心任务:
-
解析
/etc/systemd/system/default.target(默认运行级别) -
并行启动服务单元(Unit)
-
激活
sysinit.target(系统初始化)、basic.target(基础服务)
-
-
-
vim /etc/systemd/system/default.target # SPDX-License-Identifier: LGPL-2.1-or-later # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Graphical Interface Documentation=man:systemd.special(7) Requires=multi-user.target (多用户级别) Wants=display-manager.service Conflicts=rescue.service rescue.target After=multi-user.target rescue.service rescue.target display-manager.service (带图形的多用户) AllowIsolate=yes
-
关键操作命令
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会话
-
三、systemd管理机制
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 | 重新启动,使用该级别时将会重启主机 |
查看运行级别
[root@localhost ~]# runlevel N 5 (说明是图形界面)
切换运行级别
init + 运行级别数字(2-6,0为关机状态,不能为1)
查看默认运行级别
[root@localhost ~]# systemctl get-default graphical.target(图形界面)
设置默认运行级别
systemctl set-default runlevel+数字(2-6) target
2、systemctl命令的使用
语法结构:
systemctl 服务控制类型 服务名称[.service]
服务控制类型
start:启动 Active: active (running) stop:停止 Active: inactive (dead) restart:重启 会停止服务 reload:重载 不停止服务,加载配置文件 优雅的重启 status:查看状态 enable:开机自启动 is-enabled:查看是否开机自启动 disabled 关闭开机自启动 enabled 开启开机自启动 disable:开机不进行自启动 --now 配合enable与disable使用;在进行开机自启或不自启的同时进行打开或关闭指定服务
-
选项
-t 指定unit类型 Unit Commands list-units 列出所有unit,一般与-t结合
案例
systemctl list-units -t service systemctl daemon-reload #当改变unit的脚本文件后,需要进行重新识别
1663

被折叠的 条评论
为什么被折叠?



