9.软件包管理

1.软件管理

1.1 软件的编译和运行

  • C语言的运行和编译

    源文件`--预处理--`预处理文件`--编译--`汇编文件`--汇编--`目标文件`--链接--`可执行文件
    
    #分步骤编译运行
    gcc -E hello.c -o hello.i
    gcc -S hello.i -o hello.s
    gcc -c hello.s -o hello.o
    gcc hello.o -o hello
    #一步实现编译过程
    gcc hello.c -o hello
    

1.2 统计文件个数及总行数

  • 统计Linux内核文件个数

    [root@centos linux-5.6.2]find -name "*.c" |  wc -l
    28271
    
  • 统计Linux内核c文件总行数

    [root@centos linux-5.6.2]cat `find -name "*.c"` |  wc -l
    19324149
    
    # 错误统计,统计总行数准确
    [root@centos linux-5.6.2]find -name "*.c" | xargs wc -l
    

1.3 库文件

  • 查看命令所依赖的库文件ldd /PATH/ZHILING

    # 查看
    [root@centos ~]# ldd /bin/cat
    
    #显示本机已经缓存的所有可用库文件名及文件路径映射关系
    [root@centos ~]# /sbin/ldconfig -p
    
  • 范例:查看指令所依赖的库文件

    [root@centos ~]# ls /bin/cat
    /bin/cat
    [root@centos ~]# ls /bin/ls
    /bin/ls
    [root@centos ~]# ldd /bin/cat
            linux-vdso.so.1 =>  (0x00007ffd9f3f2000)
            libc.so.6 => /lib64/libc.so.6 (0x00007f01b62fa000)
            /lib64/ld-linux-x86-64.so.2 (0x000056035c985000)
    [root@centos ~]# ldd /bin/ls
            linux-vdso.so.1 =>  (0x00007ffd092aa000)
            libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb8f8496000)
            libcap.so.2 => /lib64/libcap.so.2 (0x00007fb8f8291000)
            libacl.so.1 => /lib64/libacl.so.1 (0x00007fb8f8087000)
            libc.so.6 => /lib64/libc.so.6 (0x00007fb8f7cc4000)
            libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb8f7a62000)
            libdl.so.2 => /lib64/libdl.so.2 (0x00007fb8f785d000)
            /lib64/ld-linux-x86-64.so.2 (0x0000560becbdf000)
            libattr.so.1 => /lib64/libattr.so.1 (0x00007fb8f7658000)
            libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb8f743c000)
    
  • 移动库文件后的回复操作

    # 把库文件移动到其他目录
    [root@centos ~]# mv /lib64/libc.so.6 /data
    # 移动该库文件后,该主机无法使用sftp传输文件,且无法接收其他主机scp传输的文件
    1、重启主机,再进度条页面按Esc进入Boot Menu,
    2、选择3 CD-ROM Drive
    3、选择Troubleshooting
    4、选择Rescue a CentOS Linux system
    5、输入1回车continue
    6、再次回车,把系统挂载到/mnt/sysimage下
    7、此时的/mnt/sysimage就代表该主机的根目录
    8、cp /mnt/sysimage/data/libc.so.6 /mnt/sysimage/lib64/
    9、重启即可
    
  • 查看库文件大小

    # 查看库文件大小
    [root@centos ~]# du -sh /usr/lib*
    368M    /usr/lib
    123M    /usr/lib64
    3.5M    /usr/libexec
    
    # 查看二进制程序超链接大小
    [root@centos ~]# du -sh /bin /sbin/
    0       /bin
    37M     /sbin/
    # 超链接大小
    [root@centos ~]# ll -d /bin /sbin
    lrwxrwxrwx. 1 root root 7 Aug  4  2020 /bin -> usr/bin
    lrwxrwxrwx. 1 root root 8 Aug  4  2020 /sbin -> usr/sbin
    # 二进制程序实际大小
    [root@centos ~]# du -sh /usr/bin /usr/sbin/
    59M     /usr/bin
    37M     /usr/sbin/
    

2. 软件包介绍

2.1 准备:挂载ISO盘

  • 安装与启动autofs

    # 安装autofs
    yum -y install autofs
    # 查看并没有misc目录
    [root@centos ~]# ls /
    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    
    # 启动autofs
    [root@centos ~]# systemctl start autofs
    # 查看已有misc目录
    [root@centos ~]# ls /
    bin  boot  dev  etc  home  lib  lib64  media  misc  mnt  net  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    
    # 由于没有ISO光盘,故没有挂载
    [root@centos ~]# cd /misc/cd
    -bash: cd: /misc/cd: No such file or directory
    [root@centos ~]# df
    Filesystem              1K-blocks    Used Available Use% Mounted on
    /dev/mapper/centos-root  12568576 1141548  11427028  10% /
    devtmpfs                  1013500       0   1013500   0% /dev
    tmpfs                     1024372       0   1024372   0% /dev/shm
    tmpfs                     1024372    8636   1015736   1% /run
    tmpfs                     1024372       0   1024372   0% /sys/fs/cgroup
    /dev/sda2                 1038336  127032    911304  13% /boot
    tmpfs                      204876       0    204876   0% /run/user/0
    
  • 虚拟机选择ISO光盘

    image-20220710123540592

  • 查看是否自动挂载

    # 查看是否挂载
    [root@centos cd]# df
    Filesystem              1K-blocks    Used Available Use% Mounted on
    /dev/mapper/centos-root  12568576 1141000  11427576  10% /
    devtmpfs                  1013500       0   1013500   0% /dev
    tmpfs                     1024372       0   1024372   0% /dev/shm
    tmpfs                     1024372    8636   1015736   1% /run
    tmpfs                     1024372       0   1024372   0% /sys/fs/cgroup
    /dev/sda2                 1038336  127032    911304  13% /boot
    tmpfs                      204876       0    204876   0% /run/user/0
    /dev/sr0                  4414592 4414592         0 100% /misc/cd
    [root@centos cd]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   15G  0 disk
    ├─sda1            8:1    0    2M  0 part
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0   14G  0 part
      ├─centos-root 253:0    0   12G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sr0              11:0    1  4.2G  0 rom  /misc/cd
    
    [root@centos ~]# cd /misc/cd
    [root@centos cd]# ls
    CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
    
  • 范例:查看包数量与分类

    # 查看数量
    [root@centos Packages]# cd /misc/cd/Packages/
    [root@centos Packages]# ls *.rpm |wc -l
    3894
    
    # 统计分类,方式一
    [root@centos Packages]# ls *.rpm | sed -nr 's/.*\.(.*)\.rpm/\1/p' |sort |uniq -c
       1348 noarch
       2546 x86_64
    # 统计分类,方式二
    [root@centos Packages]# ls *.rpm |rev |cut -d '.' -f 2 |rev |sort |uniq -c
       1348 noarch
       2546 x86_64
    

2.2 软件包相关概念

  • 软件保包中的文件

    二进制文件
    库文件
    配置文件
    帮助文件
    
  • 源码包命名规则

    格式:name-version.tar.gz
    样例:nginx-1.16.1.tar.gz
        包名:nginx
        版本:1.16.1
    注意:version=major.minor.release
    	major:大版本更新
    	minor:小版本更新
    	release:一般指修复次数
    
  • rpm包命名规则

    格式:name-version-release.arch.rpm
    样例:authd-1.4.3-42.el7.x86_64.rpm
    样例:autoconf-2.69-11.el7.noarch.rpm
    	包名name:  autoconf
    	版本version: 1.4.3
    	打包次数release: 42
    	运行平台arch: el7.x86_64
    常见运行平台
    	x86: i386, i486, i586, i686
    	x86_64: x64, x86_64, amd64
    	powerpc: ppc
    	跟平台无关:noarch
    
  • rpm包的拆分

    # 样例
    httpd-2.4.6-67.el7.centos.x86_64.rpm
    httpd-devel-2.4.6-67.el7.centos.x86_64.rpm
    httpd-manual-2.4.6-67.el7.centos.noarch.rpm
    httpd-tools-2.4.6-67.el7.centos.x86_64.rpm
    http-parser-2.7.1-1.el7.x86_64.rpm
    
    # 说明
    http-version:主包
    httpd-devel-verison:开发子包
    httpd-manual-verison:安装手册子包
    httpd-tools-verison:工具子包
    http-parser-verison:库文件子包
    
  • 包管理器分类

    rpm 包管理器:Redhat使用,管理rpm后缀文件

    dpkg 包管理器:Debian使用,管理deb后缀文件

  • 包管理器的前端工具

    yum:rpm包管理器的前端工具,可自动解决依赖问题

    apt:dpkg包管理器的前端工具,可自动解决依赖问题

  • 程序包管理器相关文件

    1. 包文件组成 (每个包独有)
        包内的文件
        元数据,如:包的名称,版本,依赖性,描述等
        可能会有包安装或卸载时运行的脚本
    2. 数据库(公共):/var/lib/rpm
        程序包名称及版本
        依赖关系
        功能说明
        包安装后生成的各文件路径及校验码信息
    
  • 利用 cpio工具查看包文件列表

    rpm2cpio 包文件|cpio –itv 预览包内文件
    rpm2cpio 包文件|cpio –id “*.conf” 释放包内文件
    
  • 常见包镜像网站

    CentOS镜像:
        https://www.centos.org/download/
        http://mirrors.aliyun.com
        http://mirrors.sohu.com
        http://mirrors.163.com
    
    Ubuntu 镜像:
        http://cdimage.ubuntu.com/releases/
        http://releases.ubuntu.com
    

2.3 查看系统信息

  • 查看操作系统版本

    # 查看版本
    [root@centos Packages]# cat /etc/os-release
    NAME="CentOS Linux"
    VERSION="7 (Core)"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="7"
    PRETTY_NAME="CentOS Linux 7 (Core)"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:centos:centos:7"
    HOME_URL="https://www.centos.org/"
    BUG_REPORT_URL="https://bugs.centos.org/"
    
    CENTOS_MANTISBT_PROJECT="CentOS-7"
    CENTOS_MANTISBT_PROJECT_VERSION="7"
    REDHAT_SUPPORT_PRODUCT="centos"
    REDHAT_SUPPORT_PRODUCT_VERSION="7"
    
    # 查看Redhat具体版本
    [root@centos Packages]# cat /etc/redhat-release
    CentOS Linux release 7.4.1708 (Core)
    
  • 查看内存

    [root@centos Packages]# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           2.0G         88M        1.6G        8.4M        316M        1.7G
    Swap:          2.0G          0B        2.0G
    
  • 查看硬盘

    [root@centos Packages]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   15G  0 disk
    ├─sda1            8:1    0    2M  0 part
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0   14G  0 part
      ├─centos-root 253:0    0   12G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sr0              11:0    1  4.2G  0 rom  /misc/cd
    
  • 查看cpu

    [root@centos Packages]# lscpu
    Architecture:          x86_64
    CPU op-mode(s):        32-bit, 64-bit
    Byte Order:            Little Endian
    CPU(s):                1
    On-line CPU(s) list:   0
    Thread(s) per core:    1
    Core(s) per socket:    1
    Socket(s):             1
    NUMA node(s):          1
    Vendor ID:             GenuineIntel
    CPU family:            6
    Model:                 158
    Model name:            Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Stepping:              11
    CPU MHz:               3599.945
    BogoMIPS:              7199.89
    Hypervisor vendor:     Innotek GmbH
    Virtualization type:   full
    L1d cache:             32K
    L1i cache:             32K
    L2 cache:              256K
    L3 cache:              6144K
    NUMA node0 CPU(s):     0
    Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase avx2 invpcid rdseed clflushopt
    

3. rpm包管理器

3.1 查询

  • rpm -q name:精确查找已安装包

    # 精确查找,包名不能拼写错误
    [root@centos Packages]# rpm -q vsftpd
    vsftpd-3.0.2-22.el7.x86_64
    
  • rpm -qa "*name*":模糊查找已安装包

    # 列出所有已安装包
    [root@centos Packages]# rpm -qa
    centos-release-7-4.1708.el7.centos.x86_64
    irqbalance-1.0.7-10.el7.x86_64
    [root@centos Packages]# rpm -qa | wc -l
    338
    
    # 模糊查找包
    [root@centos Packages]# rpm -qa "vsft*"
    vsftpd-3.0.2-22.el7.x86_64
    
    # 模糊查找包
    [root@centos Packages]# rpm -qa |grep vsft
    vsftpd-3.0.2-22.el7.x86_64
    
  • rpm -ql name:查看安装后文件列表

    # 查看已安装包生成的相关文件,不支持模糊包名
    [root@centos Packages]# rpm -ql tree
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    /usr/share/doc/tree-1.6.0/LICENSE
    /usr/share/doc/tree-1.6.0/README
    /usr/share/man/man1/tree.1.gz
    
  • rpm -qpl name:查看未安装的rpmfile安装后生成文件列表

    [root@centos Packages]# rpm -qpl tree-1.6.0-10.el7.x86_64.rpm
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    /usr/share/doc/tree-1.6.0/LICENSE
    /usr/share/doc/tree-1.6.0/README
    /usr/share/man/man1/tree.1.gz
    [root@centos Packages]# rpm -ql tree
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    /usr/share/doc/tree-1.6.0/LICENSE
    /usr/share/doc/tree-1.6.0/README
    /usr/share/man/man1/tree.1.gz
    [root@centos Packages]# rpm -e tree
    [root@centos Packages]# rpm -ql tree
    package tree is not installed
    
  • rpm -qf /path/file:查看指定文件所属包

    # /etc/issue 文件时centos包安装后产生的
    [root@centos Packages]# rpm -qf /etc/issue
    centos-release-7-4.1708.el7.centos.x86_64
    
    [root@centos Packages]# rpm -qf /usr/share/doc/tree-1.6.0/README
    tree-1.6.0-10.el7.x86_64
    
  • rpm -qi name:查看包信息

    [root@centos Packages]# rpm -qi tree
    Name        : tree
    Version     : 1.6.0
    Release     : 10.el7
    Architecture: x86_64
    Install Date: Sun 10 Jul 2022 11:43:27 PM CST
    Group       : Applications/File
    Size        : 89505
    License     : GPLv2+
    Signature   : RSA/SHA256, Fri 04 Jul 2014 01:36:46 PM CST, Key ID 24c6a8a7f4a80eb5
    Source RPM  : tree-1.6.0-10.el7.src.rpm
    Build Date  : Tue 10 Jun 2014 03:28:53 AM CST
    Build Host  : worker1.bsys.centos.org
    Relocations : (not relocatable)
    Packager    : CentOS BuildSystem <http://bugs.centos.org>
    Vendor      : CentOS
    URL         : http://mama.indstate.edu/users/ice/tree/
    Summary     : File system tree viewer
    Description :
    The tree utility recursively displays the contents of directories in a
    tree-like format.  Tree is basically a UNIX port of the DOS tree
    utility.	
    
  • rpm -qc name:列出包的配置文件

    [root@centos Packages]# rpm -qc bash
    /etc/skel/.bash_logout
    /etc/skel/.bash_profile
    /etc/skel/.bashrc
    
  • rpm -qd name:列出包的帮助文件

    [root@centos Packages]# rpm -qd bash
    /usr/share/doc/bash-4.2.46/COPYING
    /usr/share/info/bash.info.gz
    /usr/share/man/man1/..1.gz
    /usr/share/man/man1/:.1.gz
    /usr/share/man/man1/[.1.gz
    /usr/share/man/man1/alias.1.gz
    
  • 其他选项

    --scripts:程序包自带的脚本
    --whatprovides CAPABILITY:查询指定的CAPABILITY由哪个包所提供
    --whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖
    --changelog:查询rpm包的changelog
    --provides:列出指定程序包所提供的CAPABILITY
    -R:查询指定的程序包所依赖的CAPABILITY
    

3.2 安装

  • rpm -i name:默认安装

    [root@centos Packages]# rpm -i vsftpd-3.0.2-22.el7.x86_64.rpm
    [root@centos Packages]#
    
  • rpm -iv name:显示过程安装

    -v:显示详细安装过程

    [root@centos Packages]# rpm -iv vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing packages...
    vsftpd-3.0.2-22.el7.x86_64
    [root@centos Packages]#
    
  • rpm -ivh name:显示过程和进度安装

    -h:以#显示安装进度

    [root@centos Packages]# rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vsftpd-3.0.2-22.el7              ################################# [100%]
    [root@centos Packages]#
    
  • 范例:校验未安装时才进行安装

    # 校验已安装,则不进行安装
    [root@centos Packages]# rpm -q vsftpd > /dev/null || rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
    # 卸载
    [root@centos Packages]# rpm -e vsftpd
    # 校验未安装,则进行安装
    [root@centos Packages]# rpm -q vsftpd > /dev/null || rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vsftpd-3.0.2-22.el7              ################################# [100%]
    [root@centos Packages]#
    
  • --test:测试安装,不进行实际安装

    [root@centos Packages]# rpm -qa vsftpd
    [root@centos Packages]# rpm -ivh --test vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    [root@centos Packages]# rpm -qa vsftpd
    [root@centos Packages]# rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vsftpd-3.0.2-22.el7              ################################# [100%]
    [root@centos Packages]# rpm -ivh --test vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
            package vsftpd-3.0.2-22.el7.x86_64 is already installed
    [root@centos Packages]# rpm -qa vsftpd
    vsftpd-3.0.2-22.el7.x86_64
    
  • --nodeps:忽略依赖强制安装

    [root@centos Packages]# ls httpd*
    httpd-2.4.6-67.el7.centos.x86_64.rpm        httpd-manual-2.4.6-67.el7.centos.noarch.rpm
    httpd-devel-2.4.6-67.el7.centos.x86_64.rpm  httpd-tools-2.4.6-67.el7.centos.x86_64.rpm
    # 安装时有依赖报错
    [root@centos Packages]# rpm -ivh httpd-2.4.6-67.el7.centos.x86_64.rpm
    error: Failed dependencies:
            /etc/mime.types is needed by httpd-2.4.6-67.el7.centos.x86_64
            httpd-tools = 2.4.6-67.el7.centos is needed by httpd-2.4.6-67.el7.centos.x86_64
            libapr-1.so.0()(64bit) is needed by httpd-2.4.6-67.el7.centos.x86_64
            libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-67.el7.centos.x86_64
    
    # 忽略依赖安装
    [root@centos Packages]# rpm -ivh --nodeps httpd-2.4.6-67.el7.centos.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:httpd-2.4.6-67.el7.centos        ################################# [100%]
    [root@centos Packages]# rpm -qa httpd
    httpd-2.4.6-67.el7.centos.x86_64
    # 卸载
    [root@centos Packages]# rpm -e httpd
    [root@centos Packages]# rpm -qa httpd
    
  • --replacepkgs:覆盖原有包安装:--force

    # 尝试安装发现已经安装
    [root@centos Packages]# rpm -iv vsftpd-3.0.2-22.el7.x86_64.rpm
            package vsftpd-3.0.2-22.el7.x86_64 is already installed
    
    # 强制替换安装
    [root@centos Packages]# rpm -ivh --replacepkgs vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vsftpd-3.0.2-22.el7              ################################# [100%]
    
    # 强制替换安装
    [root@centos Packages]# rpm -ivh --force vsftpd-3.0.2-22.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vsftpd-3.0.2-22.el7              ################################# [100%]
    
  • --replacefiles:覆盖已有包文件安装

    [root@centos Packages]# rpm -ivh --replacefiles vsftpd-3.0.2-22.el7.x86_64.rpm
    
    
  • 其他选项

    --nosignature: 不检查来源合法性
    --nodigest:不检查包完整性
    --noscripts:不执行程序包脚本
    %pre: 安装前脚本 --nopre
    %post: 安装后脚本 --nopost
    %preun: 卸载前脚本 --nopreun
    %postun: 卸载后脚本 --nopostun
    

3.3 升级

  • rpm -U name:安装或升级(老版本不存在时直接安装)

  • rpm -F name:升级(老版本不存在时不进行安装)

    rpm -Uvh name
    rpm -Fvh name
    
    # --force,强制
    rpm -Uvh --force name
    

3.4 卸载

  • rpm -e name:卸载指定包

    # -e卸载时,不会删除配置文件
    [root@centos Packages]# rpm -e vsftpd
    
  • rpm -e --nodeps name:忽略依赖卸载

    [root@centos Packages]# rpm -e bash
    error: Failed dependencies:
            /bin/bash is needed by (installed) nss-softokn-freebl-3.28.3-6.el7.x86_64
            /bin/bash is needed by (installed) iproute-3.10.0-87.el7.x86_64
            /bin/bash is needed by (installed) grubby-8.28-23.el7.x86_64
            
    [root@centos Packages]# rpm -e --nodeps bash
    [root@centos Packages]# rpm -q bash
    package bash is not installed
    
    [root@centos Packages]# rpm -ivh bash-4.2.46-28.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:bash-4.2.46-28.el7               ################################# [100%]
    [root@centos Packages]# rpm -q bash
    bash-4.2.46-28.el7.x86_64
    

3.5 包校验

  • 在安装包时,系统也会检查包的来源是否是合法的

    检查包的完整性和签名
    rpm -K|checksig rpmfile
    
  • 在检查包的来源和完整性前,必须导入所需要公钥

    # 范例
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    rpm -qa “gpg-pubkey*”
    
  • 元数据

    软件在安装时,会记录包里的每个文件的元数据,可以用来检查包中的文件是否和当初安装时有所变化
    元数据:大小,权限,所有者,时间等
    rpm {-V|--verify} [select-options] [verify-options]
    S file Size differs
    M Mode differs (includes permissions and file type)
    5 digest (formerly MD5 sum) differs
    D Device major/minor number mismatch
    L readLink(2) path mismatch
    U User ownership differs
    G Group ownership differs
    T mTime differs
    P capabilities differ
    

3.6 数据库

  • 数据库路径

    # pm包安装时生成的信息,都放在rpm数据库中
    [root@centos Packages]# ls /var/lib/rpm
    Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
    Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername
    
  • 重建数据库

    rpm {--initdb|--rebuilddb}
    initdb: 初始化,如果事先不存在数据库,则新建之,否则,不执行任何操作
    rebuilddb:重建已安装的包头的数据库索引目录
    

4. yum管理器

4.1 yum工作原理

  • yum是基于C/S 模式

    服务端:rpm包、包的元数据库
    客户端:访问yum服务器进行安装或查询等
    
    yum服务器的仓库可以多种形式存在:
    file:// 本地路径
    http://
    https://
    ftp://
    

4.2 yum客户端配置文件

  • /etc/yum.conf:为所有仓库提供公共配置,客户端配置文件

    [root@localhost ~]# cat /etc/yum.conf
    [main]
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=0
    debuglevel=2
    logfile=/var/log/yum.log
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    installonly_limit=5
    bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
    distroverpkg=centos-release
    
    
    #  This is the default, if you make this bigger yum won't see if the metadata
    # is newer on the remote and so you'll "gain" the bandwidth of not having to
    # download the new metadata and "pay" for it by yum not having correct
    # information.
    #  It is esp. important, to have correct metadata, for distributions like
    # Fedora which don't keep old packages around. If you don't like this checking
    # interupting your command line usage, it's much better to have something
    # manually check the metadata once an hour (yum-updatesd will do this).
    # metadata_expire=90m
    
    # PUT YOUR REPOS HERE OR IN separate files named file.repo
    # in /etc/yum.repos.d
    
  • /etc/yum.repos.d/*.repo:为每个仓库的提供配置文件

    [repositoryID]
    name=Some name for this repository
    baseurl=url://path/to/repository/
    enabled={1|0}
    gpgcheck={1|0}
    gpgkey=URL
    enablegroups={1|0}
    failovermethod={roundrobin|priority}
        roundrobin:意为随机挑选,默认值
        priority:按顺序访问
    cost= 默认为1000
    
    例如:
    [base]
    name=CentOS-$releasever - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    

4.3 更改为阿里yum源

  • 范例:更改为阿里Base源

    cd /etc/yum.repos.d/
    mkdir backup
    mv *.repo backup/
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    # 删除aliyuncs和cloud.aliyuncs,只保留mirrors.aliyun.com
    sed -i '/.aliyuncs./d' CentOS-Base.repo
    # 官方给出的删除语句
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    
    # 重新生成缓存
    yum clean all
    yum makecache
    
    
    [root@localhost yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                                repo name                                                      status
    base/7/x86_64                          CentOS-7 - Base - mirrors.aliyun.com                           10,072
    extras/7/x86_64                        CentOS-7 - Extras - mirrors.aliyun.com                            512
    updates/7/x86_64                       CentOS-7 - Updates - mirrors.aliyun.com                         4,050
    repolist: 14,634
    
  • 范例:添加阿里epel源

    cd /etc/yum.repos.d/
    mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/backup
    curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum makecache
    
    
    [root@localhost yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                             repo name                                                         status
    base/7/x86_64                       CentOS-7 - Base - mirrors.aliyun.com                              10,072
    epel/x86_64                         Extra Packages for Enterprise Linux 7 - x86_64                    13,757
    extras/7/x86_64                     CentOS-7 - Extras - mirrors.aliyun.com                               512
    updates/7/x86_64                    CentOS-7 - Updates - mirrors.aliyun.com                            4,050
    repolist: 28,391
    
  • 范例:更改为本机IOS光盘yum源

    # 注意 repodata 的存放路径为/path/path/path/repodata
    [MyBase]
    name=MyBase
    failovermethod=priority
    baseurl=ftp:///path/path/path
    gpgcheck=0
    #gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    

4.4 yum安装卸载查询

4.4.1 显示仓库

  • yum repolist:显示可用仓库

    # yum repolist 显示可用仓库列表
    [root@localhost yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                             repo name                                                         status
    base/7/x86_64                       CentOS-7 - Base - mirrors.aliyun.com                              10,072
    epel/x86_64                         Extra Packages for Enterprise Linux 7 - x86_64                    13,757
    extras/7/x86_64                     CentOS-7 - Extras - mirrors.aliyun.com                               512
    updates/7/x86_64                    CentOS-7 - Updates - mirrors.aliyun.com                            4,050
    repolist: 28,391
    
  • yum repolist all:显示所有仓库

    # yum repolist all 显示所有仓库列表
    [root@localhost yum.repos.d]# yum repolist all
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                      repo name                                                       status
    base/7/x86_64                CentOS-7 - Base - mirrors.aliyun.com                            enabled: 10,072
    centosplus/7/x86_64          CentOS-7 - Plus - mirrors.aliyun.com                            disabled
    contrib/7/x86_64             CentOS-7 - Contrib - mirrors.aliyun.com                         disabled
    epel/x86_64                  Extra Packages for Enterprise Linux 7 - x86_64                  enabled: 13,757
    epel-debuginfo/x86_64        Extra Packages for Enterprise Linux 7 - x86_64 - Debug          disabled
    epel-source                  Extra Packages for Enterprise Linux 7 - x86_64 - Source         disabled
    extras/7/x86_64              CentOS-7 - Extras - mirrors.aliyun.com                          enabled:    512
    updates/7/x86_64             CentOS-7 - Updates - mirrors.aliyun.com                         enabled:  4,050
    repolist: 28,391
    
    # yum grouplist 显示所有包组
    [root@localhost ~]# yum grouplist
    Loaded plugins: fastestmirror
    Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Loading mirror speeds from cached hostfile
    Available Environment Groups:
       Minimal Install
       Compute Node
       Infrastructure Server
       File and Print Server
       Cinnamon Desktop
       MATE Desktop
       Basic Web Server
       Virtualization Host
       Server with GUI
       GNOME Desktop
       KDE Plasma Workspaces
       Development and Creative Workstation
    Available Groups:
       Cinnamon
       Compatibility Libraries
       Console Internet Tools
       Development Tools
       Educational Software
       Electronic Lab
       Fedora Packager
       General Purpose Desktop
       Graphical Administration Tools
       Haskell
       LXQt Desktop
       Legacy UNIX Compatibility
       MATE
       Milkymist
       Scientific Support
       Security Tools
       Smart Card Support
       System Administration Tools
       System Management
       TurboGears application framework
       Xfce
    Done
    

4.4.2 查找

  • yum list:查找所有安装包

    # yum list:     显示所有安装包
    # yum list all: 显示所有安装包
    
    [root@localhost yum.repos.d]# yum list |wc -l
    24765
    [root@localhost yum.repos.d]# yum list all |wc -l
    24765
    
    # 说明:@anaconda说明操作系统安装,@repository表示从哪个仓库安装,没有@表示未安装
    [root@localhost yum.repos.d]# yum list
    Installed Packages
    GeoIP.x86_64                                              1.5.0-11.el7                             @anaconda
    gpm-libs.x86_64                                           1.20.7-6.el7                             @base
    grep.x86_64                                               2.20-3.el7                               @anaconda
    grub2.x86_64  
    firefox-noscript.noarch                                   11.0.3-3.el7                             epel
    firewalld.noarch                                          0.6.3-13.el7_9                           updates
    firstboot.x86_64                                          19.12-1.el7                              base
    fish.x86_64                                               2.3.1-2.el7                              epel
    
  • yum list "*name*":查找指定安装包

    # yum list "*name*"     查找指定安装包
    # yum list |grep name   查找指定安装包,效率稍低
    
    [root@localhost yum.repos.d]# yum list "vsft*"
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Available Packages
    vsftpd.x86_64                                          3.0.2-29.el7_9                                  updates
    vsftpd-sysvinit.x86_64                                 3.0.2-29.el7_9                                  updates
    
    [root@localhost yum.repos.d]# yum list |grep vsft
    vsftpd.x86_64                            3.0.2-29.el7_9                updates
    vsftpd-sysvinit.x86_64                   3.0.2-29.el7_9                updates
    
  • yum info name:查询安装包详细信息

    [root@localhost yum.repos.d]# yum info httpd
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Available Packages
    Name        : httpd
    Arch        : x86_64
    Version     : 2.4.6
    Release     : 97.el7.centos.5
    Size        : 2.7 M
    Repo        : updates/7/x86_64
    Summary     : Apache HTTP Server
    URL         : http://httpd.apache.org/
    License     : ASL 2.0
    Description : The Apache HTTP Server is a powerful, efficient, and extensible
                : web server.
    
  • yum provides [feature]:查找特性所属安装包

    # [feature] 可以是文件或其他安装包中的特性
    
    [root@localhost yum.repos.d]# yum provides /etc/vsftpd/vsftpd.conf
    vsftpd-3.0.2-28.el7.x86_64 : Very Secure Ftp Daemon
    Repo        : base
    Matched from:
    Filename    : /etc/vsftpd/vsftpd.conf
    
    vsftpd-3.0.2-29.el7_9.x86_64 : Very Secure Ftp Daemon
    Repo        : updates
    Matched from:
    Filename    : /etc/vsftpd/vsftpd.conf
    
  • yum search [key]:查找包含关键字的安装包或安装包描述

    # [key],包名、即使描述信息中包含关键字也会搜索出来
    [root@localhost yum.repos.d]# yum search vsftp
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    ============================================= N/S matched: vsftp =============================================
    vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
    vsftpd.x86_64 : Very Secure Ftp Daemon
    
      Name and summary matches only, use "search all" for everything.
    

4.4.3 升级

  • yum升级

    # yum check-update  检查可升级软件
    [root@localhost 7]# yum check-update
    NetworkManager-wifi.x86_64                           1:1.18.8-2.el7_9                                updates
    acl.x86_64                                           2.2.51-15.el7                                   base
    alsa-lib.x86_64                                      1.1.8-1.el7                                     base
    
    # 升级指定软件
    [root@localhost 7]# yum update dnsmasq
    
    # 升级全部
    [root@localhost 7]# yum update
    

4.4.4 卸载

  • yum卸载

    yum remove name
    

4.4.5 安装

  • yum install httpd:默认安装

    # 默认安装,需要交互式确认
    yum install httpd
    
  • -y:无需确认安装

    yum install -y httpd
    
  • 其他选项

    -y: 自动回答为“yes”
    -q:静默模式
    --nogpgcheck:禁止进行gpg check
    --enablerepo=repoidglob:临时启用此处指定的repo,支持通配符,如:”*“
    --disablerepo=repoidglob:临时禁用此处指定的repo
    --noplugins:禁用所有插件
    

4.5 yum缓存

  • 缓存的路径

    # 缓存的路径配置在 /etc/yum.conf 文件中
    cachedir=/var/cache/yum/$basearch/$releasever
    # 对应本机的实际路径为
    /var/cache/yum/x86_64/7
    
    [root@localhost 7]# ls
    base  centosplus  contrib  epel  epel-debuginfo  epel-source  extras  timedhosts  timedhosts.txt  updates
    
  • 缓存相关指令

    # 清理缓存
    yum clean all
    
    # 加载缓存
    yum makecache
    

4.6 实现私有yum仓库

  • 配置信息说明

    #################  说明  #####################
    #  使用光盘中的rpm来模拟镜像仓库
    #  将光盘挂载到指定路径
    #  指定路径格式参考阿里yum仓库路径
    #  本地进配置BASE源
    #  网络通讯方式使用http
    #################  说明  #####################
    
    
    #  yum仓库主机IP
    172.32.115.12
    
    #yum仓库主机路径
    #http://mirrors.aliyun.com/centos/7.4/os/x86_64/Packages/
    #目前7.4路径下已经空了,所以使用7路径
    http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
    
    #yum仓库所使用光盘, 4.2G
    CentOS-7-x86_64-DVD-1708.iso
    
    # 使用私有仓库的主机IP
    172.32.115.11
    
  • 实现私有yum仓库的光盘实现

    # 安装http
    yum install -y httpd
    # 设置http立即启动且开机自启
    systemctl enable --now httpd
    # 作用等同于 systemctl start httpd && systemctl enable httpd
    
    # 禁用防火墙,禁止开机自启
    systemctl disable --now firewalld
    
    # 禁用SELinux
    [root@localhost yum.repos.d]# getenforce
    Enforcing
    [root@localhost yum.repos.d]# setenforce 0
    [root@localhost yum.repos.d]# getenforce
    Permissive
    
    # 创建目录,为什么非得在/var/www/html/路径下,且浏览器访问时不用输入此路径,在哪里设置的默认
    cd /var/www/html/
    mkdir -pv centos/7/os/x86_64
    
    # 确认vbox是否添加虚拟光盘,通过查看大小确认
    # 添加前
    [root@localhost html]# lsblk
    sr0              11:0    1 1024M  0 rom
    # 添加后
    [root@localhost html]# lsblk
    sr0              11:0    1  4.2G  0 rom
    
    # 挂载光盘到指定路径,有提示信息但是挂载是成功的
    [root@localhost html]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@localhost html]# lsblk
    sr0              11:0    1  4.2G  0 rom  /var/www/html/centos/7/os/x86_64
    
    # 浏览器访问即可显示仓库镜像信息
    http://172.32.115.12/centos/7/os/x86_64/
    
    # 配置172.32.115.11主机的镜像源指向私有仓库
    [12BASE]
    name=12BASE
    baseurl=http://172.32.115.12/centos/7/os/x86_64/
    gpgcheck=0
    
  • 实现私有yum源网络下载rpm包

    # 实现私有yum源中的epel源,epel源在光盘中没有,可以从网络上下载,放到主机指定路径,下载后的含义repodata元数据文件夹
    #CentOS 8 dnf 工具集成
    dnf reposync --repoid=REPOID --download-metadata -p /path
    dnf reposync --help #查看帮助
    #CentOS 7 以前版本,reposync工具来自于yum-utils包,需要先安装再执行以下命令
    reposync --repoid=REPOID --download-metadata -p /path
    
    # 自己下载rpm包放到myrpm文件夹,手动生成repodata文件夹做成私有yum仓库
    mv *.rpm /var/www/html/centos/myrpm
    createrepo /var/www/html/centos/myrpm
    ls /var/www/html/centos/myrpm/repodata
    

5. 源码编译安装

5.1 编译安装的优势

说明:编译安装使用的是make项目管理器,来编译C、C++源码项目

  • 1、安装路径可配置
  • 2、源码提供的功能特性可筛选

5.2 C源码编译原理与环境准备

  • 编译原理

    运行./configure命令参照Makefile.in模板,生成Makefile文件,模板只是大致参考,无需太多关注

    # 查看帮助
    ./configure --help
    
    # 相关配置文件来源
    autoconf: 生成configure脚本
    automake:生成Makefile.in
    
  • 环境准备

    开发工具: gcc、make
    开发环境:开发库(glibc:标准库),头文件,可安装开发包组 Development Tools
    其他依赖:特定软件相关依赖包
    
    建议安装以下包
    yum install gcc make gcc-c++ glibc glibc-devel pcre pcre-devel openssl
    openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget
    net-tools iotop bc bzip2 zip unzip nfs-utils man-pages
    

5.3 C源码编译过程

  • ./configure [option]:指定路径或可选特性

    # 指定安装路径
        --prefix=/PATH:指定默认安装位置,默认为/usr/local/
        --sysconfdir=/PATH:配置文件安装位置
        System types:支持交叉编译
    # 指定相关特性
        Optional Features: 可选特性
        --disable-FEATURE
        --enable-FEATURE[=ARG]
        Optional Packages: 可选包
        --with-PACKAGE[=ARG] 依赖包
        --without-PACKAGE 禁用依赖关系
    
  • make:根据Makefile文件,构建应用程序

  • make install:复制文件到相应路径

  • 安装后的其他可选配置

    # 1. 添加环境变量
    vim /etc/profile.d/NAME.sh
    export PATH=/PATH/TO/BIN:$PATH
    
    # 2. 相关用户及文件
    有些开源软件编译完成后,还需要创建相关的用户及文件
    
    # 3. 导入帮助手册
    编辑/etc/man.config|man_db.conf文件,添加一个MANPATH
    

5.4 编译实例-tree

  • 编译环境准备

    # 验证是否安装gcc与make
    gcc --version
    make --version
    
    
    # 安装gcc与make
    [root@localhost tree-2.0.4]# yum install gcc
    
    [root@localhost tree-2.0.4]# yum install make
    
    
    # 查看版本
    [root@localhost tree-2.0.4]# gcc --version
    gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
    
    [root@localhost tree-2.0.4]# make --version
    GNU Make 3.82
    
  • 编译安装tree

    # 上传源码包,并解压
    [root@localhost ~]# cd /usr/local/src
    [root@localhost src]# tar -zxvf tree-2.0.4.tgz
    [root@localhost src]# cd tree-2.0.4
    [root@localhost tree-2.0.4]# ls
    CHANGES  doc     filter.c  html.c  INSTALL  LICENSE  Makefile  strverscmp.c  tree.c  unix.c
    color.c  file.c  hash.c    info.c  json.c   list.c   README    TODO          tree.h  xml.c
    
    # 查看 README 与 INSTALL 参考安装方式
    cat README
    cat INSTALL
    
    # 修改makefile文件(执行安装路径)
    [root@localhost tree-2.0.4]# vim Makefile
    PREFIX=/apps/tree
    
    # 重命名版本号
    ## 查找版本号文件位置
    [root@localhost tree-2.0.4]# grep -R 'v2\.0\.4' *
    tree.c:char *version ="$Version: $ tree v2.0.4 (c) 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
    tree.c:char *hversion="\t\t tree v2.0.4 %s 1996 - 2022 by Steve Baker and Thomas Moore <br>\n"
    ## 修改版本号
    [root@localhost tree-2.0.4]# sed -n 's#v2\.0\.4#v2.00.40#p' tree.c
    char *version ="$Version: $ tree v2.00.40 (c) 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
    char *hversion="\t\t tree v2.00.40 %s 1996 - 2022 by Steve Baker and Thomas Moore <br>\n"
    [root@localhost tree-2.0.4]# sed -i 's#v2\.0\.4#v2.00.40#' tree.c
    ## 验证修改后的结果
    [root@localhost tree-2.0.4]# grep -R 'v2\.00\.40' *
    tree.c:char *version ="$Version: $ tree v2.00.40 (c) 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
    tree.c:char *hversion="\t\t tree v2.00.40 %s 1996 - 2022 by Steve Baker and Thomas Moore <br>\n"
    
    
    # 编译,编译成功后会生成名为tree文件
    [root@localhost tree-2.0.4]# make
    # 如果默认是c98编译,需要指定使用c99执行make命令
    [root@localhost tree-2.0.4]# make CFLAGS="-std=c99"
    gcc -std=c99 -c -o tree.o tree.c
    gcc -std=c99 -c -o list.o list.c
    gcc -std=c99 -c -o hash.o hash.c
    gcc -std=c99 -c -o color.o color.c
    gcc -std=c99 -c -o file.o file.c
    gcc -std=c99 -c -o filter.o filter.c
    gcc -std=c99 -c -o info.o info.c
    gcc -std=c99 -c -o unix.o unix.c
    gcc -std=c99 -c -o xml.o xml.c
    gcc -std=c99 -c -o json.o json.c
    gcc -std=c99 -c -o html.o html.c
    gcc -std=c99 -c -o strverscmp.o strverscmp.c
    gcc  -o tree tree.o list.o hash.o color.o file.o filter.o info.o unix.o xml.o json.o html.o strverscmp.o
    
    
    # 安装
    [root@localhost tree-2.0.4]# make install
    install -d /apps/tree/bin
    install -d /apps/tree/man/man1
    install tree /apps/tree/bin/tree; \
    install -m 644 doc/tree.1 /apps/tree/man/man1/tree.1
    
    
    # 修改环境变量
    [root@localhost tree-2.0.4]# cd /root
    [root@localhost ~]# echo 'PATH=/apps/tree/bin:$PATH' > /etc/profile.d/tree.sh
    [root@localhost ~]# . /etc/profile.d/tree.sh
    [root@localhost ~]# echo $PATH
    /apps/tree/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    # 验证环境变量是否成功
    tree --version
    
  • 问题记录

    # 使用make编译的时候,报错信息如下
    tree.c:670:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
       for(int i=0; i < ipattern; i++)
    # 报错分析
     因为gcc是基于c89标准,不能直接在for循环中初始化增量。而C99标准可以在for循环内定义变量
    
    # 解决方案一:执行make命令时,参数直接指定为c99
    make CFLAGS="-std=c99"
    # 解决方案二:修改makefile文件
    
    
    
    # make install安装之后,没有uninstall 要怎么卸载
    

5.5 编译实例-http

  • 编译安装http

    # 安装依赖包
    yum install gcc make apr-devel apr-util-devel openssl-devel yum install pcre-devel
    
    # 上传源码包,并解压
    [root@localhost ~]# cd /usr/local/src
    [root@localhost src]# tar -zxvf httpd-2.4.54.tar.gz
    [root@localhost src]# cd httpd-2.4.54
    [root@localhost httpd-2.4.54]# ls
    ABOUT_APACHE     BuildAll.dsp     configure     httpd.spec      libhttpd.mak   os                srclib
    acinclude.m4     BuildBin.dsp     configure.in  include         LICENSE        README            support
    Apache-apr2.dsw  buildconf        docs          INSTALL         Makefile.in    README.CHANGES    test
    Apache.dsw       CHANGES          emacs-style   InstallBin.dsp  Makefile.win   README.cmake      VERSIONING
    apache_probes.d  changes-entries  httpd.dep     LAYOUT          modules        README.platforms
    ap.d             CMakeLists.txt   httpd.dsp     libhttpd.dep    NOTICE         ROADMAP
    build            config.layout    httpd.mak     libhttpd.dsp    NWGNUmakefile  server
    
    
    # 查看 README 与 INSTALL 参考安装方式
    cat README
    cat INSTALL
    
    # 查看configure可选帮助
    [root@localhost httpd-2.4.54]# sh configure --help
    [root@localhost httpd-2.4.54]# ./configure --help
     --prefix=PREFIX
     --sysconfdir=DIR 
     --enable-so
     --enable-ssl
     --enable-http2
     
    
    # 生成makefile文件:指定安装路径与配置文件路径,开启so和ssl
    [root@local httpd-2.4.54]# ./configure --prefix=/apps/httpd24 --sysconfdir=/apps/httpd24/myconfigs --enable-ssl --enable-so
    [root@local httpd-2.4.54]# ls Makefile*
    Makefile  Makefile.in  Makefile.win
    
    # 如果默认是c98编译,需要指定使用c99执行make命令
    [root@localhost tree-2.0.4]# make CFLAGS="-std=c99"
    
    # 安装
    [root@localhost tree-2.0.4]# make install
    
    # 修改httpd.conf配置文件
    vim /apps/httpd24/myconfigs/httpd.conf
    # 放开该注释
    ServerName www.example.com:80
    
    # 启动(如果系统自带httpd服务,需要先停止,否则80端口已被占用)
    [root@rpm-manager bin]# /apps/httpd24/bin/apachectl start
    [root@rpm-manager bin]# ps -ef|grep httpd
    root     15680     1  0 21:34 ?        00:00:00 /apps/httpd24/bin/httpd -k start
    daemon   15681 15680  0 21:34 ?        00:00:00 /apps/httpd24/bin/httpd -k start
    daemon   15682 15680  0 21:34 ?        00:00:00 /apps/httpd24/bin/httpd -k start
    daemon   15683 15680  0 21:34 ?        00:00:00 /apps/httpd24/bin/httpd -k start
    root     15766 15584  0 21:34 pts/0    00:00:00 grep --color=auto httpd
    
    # 停止
    [root@rpm-manager bin]# /apps/httpd24/bin/apachectl stop
    [root@rpm-manager bin]# ps -ef|grep httpd
    root     15771 15584  0 21:34 pts/0    00:00:00 grep --color=auto httpd
    
    # 修改启动用户
    [root@rpm-manager bin]# vim /apps/httpd24/myconfigs/httpd.conf
    # 将以下两行
    User daemon
    Group daemon
    # 修改为
    User apache
    Group apache
    
    # 重新启动即可
    
  • 报错问题记录

    # ./configure生成makefile文件过程中报错
    ######  报错一:缺少APR依赖
    ######  configure: error: APR not found.  Please read the documentation.
    # 查找包
    [root@localhost httpd-2.4.54]# yum list available "*apr*"
    apr-devel.x86_64                                         1.4.8-7.el7                               base
    # 安装
    [root@localhost httpd-2.4.54]# yum install apr-devel
    
    ####### 报错二:缺少APR-util依赖
    ####### configure: error: APR-util not found.  Please read the documentation.
    [root@localhost httpd-2.4.54]# yum list available "*apr-util*"
    apr-util-devel.x86_64                                    1.5.2-6.el7                                  base
    [root@localhost httpd-2.4.54]# yum install apr-util-devel
    
    ####### 报错三:缺少PCRE依赖
    ####### configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/
    [root@localhost httpd-2.4.54]# yum list available "*pcre*"
    pcre-devel.x86_64                                         8.32-17.el7                                 base
    [root@localhost httpd-2.4.54]# yum install pcre-devel
    
    ###### 报错四:缺少OpenSSL依赖
    ###### configure: WARNING: OpenSSL version is too old
    [root@localhost httpd-2.4.54]# yum list available "*openssl*"
    openssl-devel.i686                                   1:1.0.2k-25.el7_9                             updates
    [root@localhost httpd-2.4.54]# yum install openssl-devel
    
    
    # 启动报错
    # AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
    # 修改httpd.conf配置文件
    vim /apps/httpd24/myconfigs/httpd.conf
    # 放开该注释
    ServerName www.example.com:80
    
    

6. Ubuntu软件管理

6.1 管理器介绍

Debian 软件包通常为预编译的二进制格式的扩展名“.deb”,类似于.rpm

  • dpkg:类似于rpm, package manager for Debian,dpkg是基于Debian的系统的包管理器。
  • apt:类似于yum,Advanced Packaging Tool,可以自动解决依赖

6.2 常用命令

  • dpkg 常见用法

    #安装包
    dpkg -i package.deb
    
    #删除包,不建议,不自动卸载依赖于它的包
    dpkg -r package
    
    #删除包(包括配置文件)
    dpkg -P package
    
    #列出当前已安装的包,类似rpm -qa
    dpkg -l
    
    #显示该包的简要说明,类似rpm –qi
    dpkg -l package
    
    #列出该包中所包含的文件,类似rpm –ql
    dpkg -L package
    
    #搜索包含pattern的包,类似rpm –qf, 搜索文件来自哪个包
    dpkg -S <pattern>
    # 查找/bin/bash来自哪个包
    dpkg -S /bin/bash
    
    #列出该包的状态,包括详细信息,类似rpm –qi
    dpkg -s package
    
    #配置包,-a 使用,配置所有没有配置的软件包
    dpkg --configure package
    
    #列出 deb 包的内容,类似rpm –qpl
    dpkg -c package.deb
    
    #解开 deb 包的内容
    dpkg --unpack package.deb
    
  • apt常见用法

    # 查找包
    apt list apache*
    # 查找包
    apt search apache
    
    # 安装包:
    apt install apache2
    
    # 卸载包:
    apt remove apache2
    # 卸载包并删除配置文件
    apt remove --purge apache2
    # 自动删除不需要的包
    apt autoremove
    
    # 更新包索引
    # 升级所有可升级的软件包
    apt update
    apt upgrade
    
    
    # APT包索引配置文件
    /etc/apt/sources.list
    /etc/apt/sources.list.d
    
posted @ 2022-08-31 00:28  人间丶迷走  阅读(42)  评论(0编辑  收藏  举报