Linux初級:軟體包管理(差編譯安裝未整理)
軟體包管理
1、ABI:application binary interfac
應用程式二進位制介面,應用程式要在作業系統上執行必須符合作業系統的介面
Linux:ELF(Executable and Linkable Format)
Windows:PE(Portable Executable)
2、API:application programming interface
呼叫應用程式庫介面
3、程式原始碼-->預處理-->編譯-->彙編-->連結
連結主要作用是把各個模組之間相互引用的部分處理好,使得各個模組之間能夠正確地銜接,分為靜態連結和動態連結 1、靜態連結 把程式對應的依賴庫複製一份到包 libxxx.a 嵌入程式包 升級難,需重新編譯 佔用較多空間,遷移容易 2、動態連結 只把依賴加做一個動態連結 libxxx.so 連線指向 佔用較少空間,升級方便
4、程式包管理器
debian:deb檔案, dpkg包管理器
redhat:rpm檔案, rpm包管理器 rpm:RPM Package Manager(早期:RedhatPackage Manager)
5、包命名和工具
原始碼:name-VERSION.tar.gz|bz2|xz rpm: name-VERSION-release.arch.rpm 例: bash-4.2.46-19.el7.x86_64.rpm release:打包次數 arch:CPU架構 x86 : i386 i486 i586 i686 x86_64: x64 x86_64 amd64 通用:noarch
統計光碟內有多少個rpm安裝包
[[email protected] ~]#ls /run/media/root/CentOS\ 7\ x86_64/Packages/*.rpm |sed -r 's/.*\.([^.]+)\.rpm/\1/'|sort|uniq -c
2223 i686
3117 noarch
4571 x86_64
分類和拆包
Application-VERSION-ARCH.rpm: 主包
Application-devel-VERSION-ARCH.rpm開發子包
Application-utils-VERSION-ARHC.rpm其它子包
Application-libs-VERSION-ARHC.rpm其它子包
[[email protected] Packages]#ls httpd*
httpd-2.4.6-80.el7.centos.x86_64.rpm httpd-manual-2.4.6-80.el7.centos.noarch.rpm
httpd-devel-2.4.6-80.el7.centos.x86_64.rpm httpd-tools-2.4.6-80.el7.centos.x86_64.rpm
包之間可能存在依賴關係,甚至迴圈依賴
解決依賴包管理工具:
yum:rpm包管理器的前端工具
apt-get:deb包管理器前端工具
zypper: suse上的rpm前端管理工具
dnf: Fedora 18+ rpm包管理器前端管理工具
6、庫檔案
管理及檢視本機裝載的庫檔案
ldconfig載入庫檔案
顯示本機已經快取的所有可用庫檔名及檔案路徑對映關係
/sbin/ldconfig-p
配置檔案
/etc/ld.so.conf
/etc/ld.so.conf.d/*.conf
快取檔案
/etc/ld.so.cache
檢視二進位制程式所以來的庫檔案
ldd/PATH/TO/BINARY_FILE
[[email protected] lib64]#ldd /bin/ls
linux-vdso.so.1 => (0x00007ffe462fe000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f6636a7c000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f6636877000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f663666e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f66362a1000) 共同呼叫的庫
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f663603f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f6635e3b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6636ca3000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f6635c36000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6635a1a000)
[[email protected] lib64]#ldd /bin/cat
linux-vdso.so.1 => (0x00007fff973d8000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8055e22000) 共同呼叫的庫
/lib64/ld-linux-x86-64.so.2 (0x00007f80561ef000)
[[email protected] lib64]#ldd /bin/bash
linux-vdso.so.1 => (0x00007ffed23c7000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f4890fcb000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f4890dc7000)
libc.so.6 => /lib64/libc.so.6 (0x00007f48909fa000) 共同呼叫的庫
/lib64/ld-linux-x86-64.so.2 (0x00007f48911f5000)
丟失公用庫後無法啟動解決方法,進入修復模式
1、esc鍵盤
2、選擇CD-ROM
3、選擇troubleshooting
4、選擇Rescue a CentOS system
5、選擇1 (Continue)
6、進入系統開始修復
RPM
1、程式包管理器:
將編譯好的應用程式的各組成檔案打包一個或幾個程式包檔案,從而方便快捷地實現程式包的安裝、解除安裝、查詢、升級和校驗等管理操作。
資料庫:var/lib/rpm
程式包名稱及版本,依賴關係,功能說明,包安裝後生成的各檔案路徑及校驗碼資訊
執行程式:usr/bin/rpm
2、獲取程式包的途徑:
(1) 系統發版的光碟或官方的伺服器
CentOS映象:
https://www.centos.org/download/
http://mirrors.aliyun.com
http://mirrors.sohu.com
http://mirrors.163.com
(2) 專案官方站點
(3) 第三方組織:
Fedora-EPEL:Extra Packages for Enterprise Linux
https://mirrors.aliyun.com/
搜尋引擎:
http://pkgs.org
http://rpmfind.net
http://rpm.pbone.net
https://sourceforge.net/
3、CentOS系統上使用rpm命令管理程式包
rpm -ivh PACKAGE_file 常用安裝選項
-i 安裝等同--install
-v 顯示過程 verbose
-h 以#顯示程式包管理執行進度
[[email protected] ~]#rpm -ivh /mnt/Packages/dstat-0.7.2-12.el7.noarch.rpm
warning: /mnt/Packages/dstat-0.7.2-12.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:dstat-0.7.2-12.el7 ################################# [100%]
附加選項:
[install-options]
--test: 測試安裝,但不真正執行安裝,即dry run模式
--nodeps:忽略依賴關係
--replacepkgs| replacefiles
--nosignature: 不檢查來源合法性
--nodigest:不檢查包完整性
--noscripts:不執行程式包指令碼
%pre: 安裝前指令碼--nopre
%post: 安裝後腳本--nopost
%preun: 解除安裝前指令碼--nopreun
%postun: 解除安裝後腳本--nopostun
升級:
rpm {-U|--upgrade} [install-options] PACKAGE_FILE...
rpm {-F|--freshen} [install-options] PACKAGE_FILE...
upgrade:安裝有舊版程式包,則“升級”
如果不存在舊版程式包,則“安裝”
freshen:安裝有舊版程式包,則“升級”
如果不存在舊版程式包,則不執行升級操作
rpm -UvhPACKAGE_FILE ...
rpm -FvhPACKAGE_FILE ...
--oldpackage:降級
--force: 強制安裝
若不慎刪除/bin/rpm檔案,進入修復模式rpm -ivh /mnt/Packages/rmp-4.11.3-32.el7.X86_64.rpm --root=/mnt/sysimage/ --replacepkgs
或直接切根安裝rpm -ivh /mnt/Packages/rmp-4.11.3-32.el7.X86_64.rpm --replacepkgs
注意:
(1) 不要對核心做升級操作;Linux支援多核心版本並存,因此,對直接安裝新版本核心
(2) 如果原程式包的配置檔案安裝後曾被修改,升級時,新版本的提供的同一個配置檔案並不會直接覆蓋老版本的配置檔案,而把新版本的檔案重新命名(FILENAME.rpmnew)後保留
4、rpm -qf 查詢檔案來自哪個包
[[email protected] ~]#rpm -qf /usr/bin/rpm
rpm-4.11.3-32.el7.x86_64
5、rpm -qa 查詢所有的包
[[email protected] ~]#rpm -qa tre*
tree-1.6.0-10.el7.x86_64
[[email protected] ~]#rpm -qa |grep "^tre"
tree-1.6.0-10.el7.x86_64
7、檢查及匯入所需要公鑰
檢查包的完整性和簽名rpm -K|checksigrpmfile
[[email protected] ~]#rpm -K /mnt/Packages/memcached-1.4.15-10.el7_3.1.x86_64.rpm
/mnt/Packages/memcached-1.4.15-10.el7_3.1.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#f4a80eb5)
匯入公鑰rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[[email protected] ~]#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[[email protected] ~]#rpm --import /mnt/RPM-GPG-KEY-CentOS-7
檢視匯入的公鑰
[[email protected] ~]#rpm -qa 'gpg-pubkey*'
gpg-pubkey-f4a80eb5-53a7ff4b
[[email protected] ~]#rpm -qi gpg-pubkey-f4a80eb5-53a7ff4b
Name : gpg-pubkey
Version : f4a80eb5
Release : 53a7ff4b
Architecture: (none)
Install Date: Sat 22 Sep 2018 02:42:05 AM CST
Group : Public Keys
Size : 0
License : pubkey
Signature : (none)
Source RPM : (none)
Build Date : Mon 23 Jun 2014 06:19:55 PM CST
Build Host : localhost
Relocations : (not relocatable)
Packager : CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>
Summary : gpg(CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>)
Description :
...
8、rpm -e 包解除安裝
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
9、rpm -V 包校驗
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 mTimediffers
P capabilities differ
yum
YUM: YellowdogUpdate Modifier,rpm的前端程式,可解決軟體包相關依賴性,可在多個庫之間定位軟體包,up2date的替代工具
yum repository: yum repo,儲存了眾多rpm包,以及包的相關的元資料檔案(放置於特定目錄repodata下)
檔案伺服器:
http://
https://
ftp://
file://
1、yum客戶端配置檔案: yum repolist
檢視倉庫
1. /etc/yum.conf 為所有倉庫提供公共配置
[[email protected] ~]#vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever $basearch 架構 $releasever 版本號
keepcache=0 保留快取1,不保留0
debuglevel=2
logfile=/var/log/yum.log 日誌檔案
exactarch=1 是否檢查架構
obsoletes=1 過期包
gpgcheck=1 是否檢查
plugins=1 是否支援外掛
installonly_limit=5 同步並行安裝數量
...
2. /etc/yum.repos.d/*.repo 為倉庫的指向提供配置
[[email protected] ~]#vim /etc/yum.repos.d/base.repo
[cdrom]
baseurl=file:///mnt 路徑為repodata的父目錄
gpgcheck=0
name=cdrom repodb 描述資訊
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enabled=0 0禁用 1啟用
設定別名epel快速禁用
alias disepel=`sed -ri /enabled/s/enabled=0/enabled=1/ /etc/yum.repos.d/base.repo`
alias epel=`sed -ri /enabled/s/enabled=1/enabled=0/ /etc/yum.repos.d/base.repo`
2、yum源
阿里雲repo檔案:
http://mirrors.aliyun.com/repo/
CentOS系統的yum源
阿里雲:https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
清華大學:https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/x86_64/
EPEL的yum源:
阿里雲:https://mirrors.aliyun.com/epel/$releasever/x86_64
3、搭建http源
服務端:
[[email protected] mnt]#yum install httpd.x86_64
[[email protected] mnt]#systemctl stop firewalld.service
[[email protected] mnt]#systemctl start httpd
[[email protected] html]#mkdir centos/7/os/x86_64/ -pv
mkdir: created directory ‘centos’
mkdir: created directory ‘centos/7’
mkdir: created directory ‘centos/7/os’
mkdir: created directory ‘centos/7/os/x86_64/’
[[email protected] html]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
可掛載光碟或拷貝檔案直接到目錄
瀏覽器已經可以訪問了http://192.168.32.7/centos/7/os/x86_64/
客戶端:
[[email protected] ~]#vim /etc/yum.repos.d/http.repo
[centos]
name=http_repo
baseurl=http://192.168.32.7/centos/$releasever/os/$basearch
gpgkey=http://192.168.32.7/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever
yum如果出錯:1.檢查倉庫路徑,2.清空快取
4、其他常用命令
yum repolist 檢視倉庫
yum history 檢視歷史記錄
yum info history 檢視資訊
yum history undo 1 返回歷史1
yum hisyory redo 1 重做歷史1
yum groupinstall "packgrp file" 安裝包組
yum search libvirt 查詢
yum install samba -y -q 靜默安裝,自動yes,適合放在腳本里
yum clean all 清空快取
yum list installed 已安裝的包
yum list available 未安裝好的包 支援萬用字元
yum remove package1 解除安裝程式包 建議用返回歷史,解除安裝比較乾淨
yum erase package1 解除安裝程式包
[[email protected] ~]#cd /var/cache/yum/x86_64/7/
base/ cdrom/ centos6/ epel/ extras/ updates/
[[email protected] ~]# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
3 | root <root> | 2018-09-22 05:02 | Install | 6
2 | root <root> | 2018-09-22 03:46 | Install | 5 <
1 | System <unset> | 2018-07-10 22:00 | Install | 1362 >
history list
[[email protected] ~]#yum history info 3
Loaded plugins: fastestmirror, langpacks
Transaction ID : 3
Begin time : Sat Sep 22 05:02:08 2018
Begin rpmdb : 1369:53bc6bebfcb633c6707382975ec8db4085ee7c34
End time : 05:02:11 2018 (3 seconds)
End rpmdb : 1375:77a20561e51439092435be69d32430519d71a294
User : root <root>
Return-Code : Success
Command Line : install gcc
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
Packages Altered:
Dep-Install cpp-4.8.5-28.el7.x86_64 @centos6
Install gcc-4.8.5-28.el7.x86_64 @centos6
Dep-Install glibc-devel-2.17-222.el7.x86_64 @centos6
Dep-Install glibc-headers-2.17-222.el7.x86_64 @centos6
Dep-Install kernel-headers-3.10.0-862.el7.x86_64 @centos6
Dep-Install libmpc-1.0.1-3.el7.x86_64 @centos6
history info
[[email protected] ~]#yum history undo 3
Loaded plugins: fastestmirror, langpacks
Undoing transaction 3, from Sat Sep 22 05:02:08 2018
Dep-Install cpp-4.8.5-28.el7.x86_64 @centos6
Install gcc-4.8.5-28.el7.x86_64 @centos6
Dep-Install glibc-devel-2.17-222.el7.x86_64 @centos6
Dep-Install glibc-headers-2.17-222.el7.x86_64 @centos6
Dep-Install kernel-headers-3.10.0-862.el7.x86_64 @centos6
Dep-Install libmpc-1.0.1-3.el7.x86_64 @centos6
....
Complete!
查詢未安裝包內的檔案:基於yum倉庫
[[email protected] ~]#rpm -q yum-utils 首先安裝yun-utils
[[email protected] ~]#repoquery -ql vsftpd 可查詢未安裝包vsftpd內的檔案
製作自定義的倉庫
建立一個資料夾
createrpo /當前目錄
把檔案拷貝到當前目錄
[[email protected] app]#mkdir dadda
[[email protected] app]#createrepo ./dadda
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
虛擬機器掃描硬體:
[[email protected] ~]#echo '- - -' >/sys/class/ssi_host/host0/scan
[[email protected] ~]#echo '- - -' >/sys/class/ssi_host/host1/scan
[[email protected] ~]#echo '- - -' >/sys/class/ssi_host/host2/scan
虛擬機器虛擬網絡卡解除安裝
[[email protected] 7]#yum search libvirt
[[email protected] 7]#yum remove libvirt-daemon
基於yum源,需配好repo倉庫