2020-04-10 軟件包管理

掛載光盤小技巧
確保設(shè)備狀態(tài)下的兩個選項已勾選如圖


image.png

[root@centos7 ~]# systemctl start autofs
[root@centos7 ~]# systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
[root@centos7 ~]# cd
[root@centos7 ~]# ls /misc
[root@centos7 ~]# cd /misc
[root@centos7 misc]# cd cd/ 進入系統(tǒng)光盤
[root@centos7 cd]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL

CentOS系統(tǒng)上使用rpm命令管理程序包:
安裝、卸載、升級、查詢、校驗、數(shù)據(jù)庫維護
安裝:
rpm {-i|--install} [install-options] PACKAGE_FILE…
-v: verbose
-vv:
-h: 以#顯示程序包管理執(zhí)行進度
rpm -ivh PACKAGE_FILE ...
[install-options]
--test: 測試安裝,但不真正執(zhí)行安裝,即dry run模式
--nodeps:忽略依賴關(guān)系
--replacepkgs | replacefiles
--nosignature: 不檢查來源合法性
--nodigest:不檢查包完整性
--noscripts:不執(zhí)行程序包腳本
%pre: 安裝前腳本 --nopre
%post: 安裝后腳本 --nopost
%preun: 卸載前腳本 --nopreun
%postun: 卸載后腳本 --nopostun
rpm包升級
升級:
rpm {-U|--upgrade} [install-options] PACKAGE_FILE...
rpm {-F|--freshen} [install-options] PACKAGE_FILE...
upgrade:安裝有舊版程序包,則“升級”
如果不存在舊版程序包,則“安裝”
freshen:安裝有舊版程序包,則“升級”
如果不存在舊版程序包,則不執(zhí)行升級操作
rpm -Uvh PACKAGE_FILE ...
rpm -Fvh PACKAGE_FILE ...
--oldpackage:降級
--force: 強制安裝
注意:
(1) 不要對內(nèi)核做升級操作;Linux支持多內(nèi)核版本并存,因此直接安裝新版本內(nèi)核
(2) 如果原程序包的配置文件安裝后曾被修改,升級時,新版本提供的同一個配置文件不會直接覆蓋老版本的配置文件,而把新版本文件重命名(FILENAME.rpmnew)后保留
[root@centos7 ~]# ldd /bin/cat 查看調(diào)用依賴的庫
linux-vdso.so.1 => (0x00007ffeb6ff4000)
libc.so.6 => /lib64/libc.so.6 (0x00007f34f324a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f34f3617000)
[root@centos7 Packages]# rpm -e tree 卸載包
[root@centos7 Packages]# tree
-bash: /usr/bin/tree: No such file or directory
[root@centos7 Packages]# rpm -qpi tree-1.6.0-10.el7.x86_64.rpm 查詢包信息
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: (not installed)
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.
[root@centos7 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@centos7 Packages]# rpm -qa "tr" 查詢安裝過的包 可模糊查詢 支持管道正則查詢
tree-1.6.0-10.el7.x86_64
traceroute-2.0.22-2.el7.x86_64
trousers-0.3.14-2.el7.x86_64
tracker-1.10.5-6.el7.x86_64
[root@centos7 Packages]# rpm -qf /usr/bin/tree 查詢文件來自哪個包
tree-1.6.0-10.el7.x86_64
[root@centos7 Packages]# rpm -e --nodeps tree 不考慮依賴性直接卸載
[root@centos7 cd]# rpm --import /misc/cd/RPM-GPG-KEY-CentOS-7 導(dǎo)入包驗證 光盤導(dǎo)入
[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 系統(tǒng)本地導(dǎo)入
[root@centos7 cd]# rpm -qa "gpg-pubkey
" 查看秘鑰
gpg-pubkey-f4a80eb5-53a7ff4b 秘鑰
[root@centos7 cd]# rpm -qi gpg-pubkey-f4a80eb5-53a7ff4b 查看秘鑰信息
Name : gpg-pubkey
Version : f4a80eb5
Release : 53a7ff4b
Architecture: (none)
Install Date: Thu 02 Apr 2020 05:22:08 PM CST
Group : Public Keys
[root@centos7 data]# ls
etc etc.tar fstab fstab.bak messages passwd shell tes tree-1.6.0-10.el7.x86_64.rpm t.sh
[root@centos7 data]# rpm -K tree-1.6.0-10.el7.x86_64.rpm
tree-1.6.0-10.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK 校驗包的完整安全性
/var/lib/rpm 包數(shù)據(jù)庫 必要時可備份 在包庫破損時恢復(fù)
rpm -ivh -e -qi -ql -qf -qpi rpmfile -qc -q --scripts -qa --force --nodeps 重點熟悉命令
yum

[root@centos7localdomain cd]# cd /etc/yum.repos.d/
[root@centos7localdomain yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@centos7localdomain yum.repos.d]# mkdir bak
[root@centos7localdomain yum.repos.d]# mv *.repo bak/ 將系統(tǒng)自帶的yum源剪切到bak文件夾中
[root@centos7localdomain yum.repos.d]# vim bash.repo
[root@centos7localdomain yum.repos.d]# cat bash.repo
[base] 基于光盤
name=cdrom base
baseurl=file:///misc/cd
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

校檢包的合法性

[epel]
name=aliyun epel 基于網(wǎng)絡(luò) 阿里云的epel
baseurl=https://mirrors.aliyun.com/epel/releasever/basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

1啟用 0 禁止

[root@centos7localdomain yum.repos.d]# ls /var/cache/yum//x86_64/7/
base extras timedhosts timedhosts.txt updates
[root@centos7localdomain yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@centos7localdomain yum.repos.d]# rm -rf /var/cache/yum/* 清空yum源緩存 用于更改yum源后的操作 確保舊的緩存清理干凈
[root@centos7localdomain yum.repos.d]# yum repolist 下載元數(shù)據(jù)
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
(1/5): base/group_gz | 166 kB 00:00:00
(2/5): base/primary_db | 3.1 MB 00:00:00
(3/5): epel/7/x86_64/group_gz | 95 kB 00:00:00
(4/5): epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
(5/5): epel/7/x86_64/primary_db | 6.8 MB 00:00:00
repo id repo name status
base cdrom base 4,021
epel/7/x86_64 aliyun epel 13,246
repolist: 17,267
[root@centos7localdomain yum.repos.d]#

yum clean all 清空yum源緩存
rm -rf /var/cache/yum/* 清空yum元緩存 保持環(huán)境干凈
yum repolist 下載元緩存

[root@centos7localdomain yum.repos.d]# yum remove httpd 卸載httpd包本身 不卸載依賴包

yum history undo 5 -y 卸載yum第五個
yum history redo 5 -y 重裝第五個

[root@centos7localdomain yum.repos.d]# yum history info 3 查看第三個yum命令
Loaded plugins: fastestmirror, langpacks
Transaction ID : 3
Begin time : Sat Apr 18 10:52:29 2020
Begin rpmdb : 1364:91cf775895ed404174076e9ffc54b9a134a778a9
End time : 10:52:44 2020 (15 seconds)
End rpmdb : 1369:37319588d001be7f5b11d0f21eb9950c525c16c0
User : root <root>
Return-Code : Success
Command Line : install httpd yum命令
Transaction performed with:
Installed rpm-4.11.3-32.el7.x86_64 @anaconda
Installed yum-3.4.3-158.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-45.el7.noarch @anaconda
yum install /misc/cd/Packages/下載包 可根據(jù)需求直接安裝依賴包

[root@centos7localdomain html]# echo '- - -' > /sys/class/scsi_host/host2/scan 掃描外接設(shè)備
[root@centos7localdomain html]# lsblk
[root@centos7localdomain html]# mount /dev/sr0 centos/7/os/x86_64/ 臨時掛載
mount: /dev/sr0 is write-protected, mounting read-only

編譯安裝
功能可定制
配好yum源后 下載安裝編譯器
yum install gcc
C語言源代碼編譯安裝三步驟:
1、./configure
(1) 通過選項傳遞參數(shù),指定啟用特性、安裝路徑等;執(zhí)行時會參考用戶的指定以及Makefile.in文件生成Makefile
(2) 檢查依賴到的外部環(huán)境,如依賴的軟件包
2、make 根據(jù)Makefile文件,構(gòu)建應(yīng)用程序
3、make install 復(fù)制文件到相應(yīng)路徑

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容