所謂的腳本安裝包,就是把複雜的軟件包安裝過程寫成程序的腳本,初學者能夠執行程序腳本實現一鍵安裝。但實際安裝的仍是源碼包和二進制包。
光盤掛載html
- 插入光盤
- 創建掛載點
[root/dev]$mkdir /mnt/cdrom
- 掛載光盤
[root/dev]$mount /dev/cdrom /mnt/cdrom/ mount: /dev/sr0 is write-protected, mounting read-only
- 查看光盤下的RPM包
[root/dev]$cd /mnt/cdrom/ [root/mnt/cdrom]$ll total 109K -rw-rw-r-- 1 root root 14 May 2 11:28 CentOS_BuildTag -rw-r--r-- 1 root root 29 May 3 20:30 .discinfo drwxr-xr-x 3 root root 2.0K May 3 20:34 EFI/ -rw-rw-r-- 1 root root 227 Aug 30 2017 EULA -rw-rw-r-- 1 root root 18K Dec 9 2015 GPL drwxr-xr-x 3 root root 2.0K May 3 20:45 images/ drwxr-xr-x 2 root root 2.0K May 3 20:34 isolinux/ drwxr-xr-x 2 root root 2.0K May 3 20:34 LiveOS/ drwxrwxr-x 2 root root 70K May 3 21:03 Packages/ drwxrwxr-x 2 root root 4.0K May 3 21:06 repodata/ -rw-rw-r-- 1 root root 1.7K Dec 9 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r-- 1 root root 1.7K Dec 9 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r-- 1 root root 2.9K May 3 21:07 TRANS.TBL -rw-r--r-- 1 root root 354 May 3 20:34 .treeinfo [root/mnt/cdrom]$cd Packages/ [root/mnt/cdrom/Packages]$ll total 351M -rw-rw-r-- 1 root root 82K Apr 25 10:52 acl-2.2.51-14.el7.x86_64.rpm -rw-rw-r-- 1 root root 23K Jul 4 2014 aic94xx-firmware-30-6.el7.noarch.rpm -rw-rw-r-- 1 root root 134K Aug 10 2017 aide-0.15.1-13.el7.x86_64.rpm ...省略n行 -rw-rw-r-- 1 root root 1.3M Apr 25 11:52 yum-3.4.3-158.el7.centos.noarch.rpm -rw-rw-r-- 1 root root 28K Jul 4 2014 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm -rw-rw-r-- 1 root root 33K Apr 25 11:52 yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm -rw-rw-r-- 1 root root 260K Nov 20 2016 zip-3.0-11.el7.x86_64.rpm -rw-rw-r-- 1 root root 90K Nov 20 2016 zlib-1.2.7-17.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpmpython
- zip:軟件包名
- 3.0: 軟件版本
- 11: 軟件發佈的次數
- el7: 適合的Linux平臺
- x86_64: 適合的硬件平臺
- rpm: 擴展名
a -> b -> c
a -> b -> c -> a
模塊依賴查詢網站:www.rpmfind.net
包全名與包名mysql
- 包全名:操做的包是沒有安裝的軟件包時,使用包全名。並且要注意路徑。
- 包名:操做已經安裝的軟件包時,使用包名。其實是搜索
/var/lib/rpm/
中的數據庫。
rpm -ivh [包全名]
-i
:(install) 安裝
-v
:(verbose) 顯示詳細信息
-h
:(hash) 顯示進度
[root/mnt/cdrom/Packages]$rpm -ivh zip-3.0-11.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:zip-3.0-11.el7 ################################# [100%]
rpm -Uvh [包全名]
-U
:(upgrade) 升級
[root/mnt/cdrom/Packages]$rpm -Uvh tar-1.26-34.el7.x86_64.rpm Preparing... ################################# [100%] package tar-2:1.26-34.el7.x86_64 is already installed
rpm -e [包名]
-e
:(erase) 卸載
[root/mnt/cdrom/Packages]$rpm -Uvh tar-1.26-34.el7.x86_64.rpm Preparing... ################################# [100%] package tar-2:1.26-34.el7.x86_64 is already installed
rpm -q 包名
-q
:(query) 查詢
[root/mnt/cdrom/Packages]$rpm -q zip zip-3.0-11.el7.x86_64 [root/mnt/cdrom/Packages]$rpm -q mysql package mysql is not installed
rpm -qa
-a
:(all) 全部
[root ~]$rpm -qa nss-tools-3.34.0-4.el7.x86_64 fipscheck-1.4.1-6.el7.x86_64 curl-7.29.0-46.el7.x86_64 ...省略n行 libpipeline-1.2.3-3.el7.x86_64 linux-firmware-20180220-62.git6d51311.el7.noarch
[root ~]$rpm -qa | grep zip bzip2-1.0.6-13.el7.x86_64 bzip2-libs-1.0.6-13.el7.x86_64 bzip2-libs-1.0.6-13.el7.i686 zip-3.0-11.el7.x86_64 gzip-1.5-10.el7.x86_64
rpm -qi 包名 (查詢已安裝軟件包詳細信息) rpm -qip 包全名 (查詢未安裝軟件包詳細信息)
-i
:(infomation) 查詢軟件信息
-p
:(package) 查詢未安裝包信息
[root/mnt/cdrom/Packages]$rpm -qi zip Name : zip Version : 3.0 Release : 11.el7 Architecture: x86_64 Install Date: Tue 22 May 2018 03:13:50 AM UTC Group : Applications/Archiving Size : 815173 License : BSD Signature : RSA/SHA256, Sun 20 Nov 2016 09:04:58 PM UTC, Key ID 24c6a8a7f4a80eb5 Source RPM : zip-3.0-11.el7.src.rpm Build Date : Sat 05 Nov 2016 04:49:55 PM UTC Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://www.info-zip.org/Zip.html Summary : A file compression and packaging utility compatible with PKZIP Description : The zip program is a compression and file packaging utility. Zip is analogous to a combination of the UNIX tar and compress commands and is compatible with PKZIP (a compression and file packaging utility for MS-DOS systems). Install the zip package if you need to compress files using the zip program.
[root/mnt/cdrom/Packages]$rpm -qip json-c-0.11-4.el7_0.x86_64.rpm Name : json-c Version : 0.11 Release : 4.el7_0 Architecture: x86_64 Install Date: (not installed) Group : Development/Libraries Size : 65593 License : MIT Signature : RSA/SHA256, Sat 05 Jul 2014 03:25:00 PM UTC, Key ID 24c6a8a7f4a80eb5 Source RPM : json-c-0.11-4.el7_0.src.rpm Build Date : Tue 24 Jun 2014 12:18:58 PM UTC Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : https://github.com/json-c/json-c/wiki Summary : A JSON implementation in C Description : JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects.
rpm 包默認安裝位置由該軟件包的開發者決定rpm 包也能夠經過
--prefix=<dir>
選項指定安裝目錄linux
RPM包默認安裝位置(僅供參考)git
目錄 | 說明 |
---|---|
/etc/init.d/ |
啓動腳本所在目錄 |
/etc/sysconfig/ |
初始化環境配置文件目錄 |
/etc/ |
配置文件安裝目錄 |
/var/log/ |
日誌文件目錄 |
/usr/bin/ |
可執行的命令安裝目錄 |
/usr/lib/ |
程序所使用的函數庫保存目錄 |
/usr/share/doc/ |
基本的軟件使用手冊保存目錄 |
/usr/share/man/ |
幫助文件保存目錄 |
rpm -ql 包名 (查詢已安裝軟件包文件安裝位置) rpm -qlp 包全名 (查詢未安裝軟件包文件安裝位置)
-l
:(list) 文件列表
-p
:(package) 查詢未安裝包信息
[root/mnt/cdrom/Packages]$rpm -ql zip /usr/bin/zip /usr/bin/zipcloak /usr/bin/zipnote /usr/bin/zipsplit /usr/share/doc/zip-3.0 /usr/share/doc/zip-3.0/CHANGES /usr/share/doc/zip-3.0/LICENSE /usr/share/doc/zip-3.0/README /usr/share/doc/zip-3.0/README.CR /usr/share/doc/zip-3.0/TODO /usr/share/doc/zip-3.0/WHATSNEW /usr/share/doc/zip-3.0/WHERE /usr/share/doc/zip-3.0/algorith.txt /usr/share/man/man1/zip.1.gz /usr/share/man/man1/zipcloak.1.gz /usr/share/man/man1/zipnote.1.gz /usr/share/man/man1/zipsplit.1.gz
[root/mnt/cdrom/Packages]$rpm -qlp json-c-0.11-4.el7_0.x86_64.rpm /usr/lib64/libjson-c.so.2 /usr/lib64/libjson-c.so.2.0.1 /usr/lib64/libjson.so.0 /usr/lib64/libjson.so.0.1.0 /usr/share/doc/json-c-0.11 /usr/share/doc/json-c-0.11/AUTHORS /usr/share/doc/json-c-0.11/COPYING /usr/share/doc/json-c-0.11/ChangeLog /usr/share/doc/json-c-0.11/NEWS /usr/share/doc/json-c-0.11/README /usr/share/doc/json-c-0.11/README.html
rpm -qf [系統文件或目錄名]
-f
:(file) 查詢系統文件屬於哪一個軟件包
[root/mnt/cdrom/Packages]$rpm -qf /etc/python/ python-libs-2.7.5-68.el7.x86_64
rpm -qR 包名
-R
:(requires) 查詢軟件包的依賴性
-p
:(package) 查詢未安裝包信息
[root/mnt/cdrom/Packages]$rpm -qR zip libbz2.so.1()(64bit) libc.so.6()(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libc.so.6(GLIBC_2.7)(64bit) rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rtld(GNU_HASH) rpmlib(PayloadIsXz) <= 5.2-1
[root/mnt/cdrom/Packages]$rpm -qRp json-c-0.11-4.el7_0.x86_64.rpm /sbin/ldconfig /sbin/ldconfig libc.so.6()(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libc.so.6(GLIBC_2.8)(64bit) libjson-c.so.2()(64bit) rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rtld(GNU_HASH) rpmlib(PayloadIsXz) <= 5.2-1
rpm -V 已安裝的包名
-V
:(verify) 校驗指定的RPM包中的文件
[root/etc]$rpm -V sudo S.5....T. c /etc/sudoers
S.5....T. c /etc/sudoersgithub
- S:文件大小發生改變
- 5:文件內容發生改變
- T:文件的修改時間發生改變
- c:文件類型爲配置文件
\ | 說明 |
---|---|
S |
文件大小是否改變 |
M |
文件類型或權限(rwx)是否改變 |
5 |
文件MD5校驗和是否改變(能夠看出是文件內容是否改變) |
D |
設備的主從代碼是否改變 |
L |
文件路徑是否改變 |
U |
文件全部者是否改變 |
G |
文件所屬組是否改變 |
T |
文件的修改時間是否改變 |
\ | 說明 |
---|---|
c |
配置文件(config file) |
d |
普通文檔(documentation) |
g |
「鬼」文件(ghost file),不多見,就是該文件不該該被這個RPM包包含 |
L |
受權文件(license file) |
r |
描述文件(read me) |
主要用於恢復被誤刪的命令文件
rpm2cpio 包全名 | cpio -idv .文件絕對路徑
將RPM包轉換爲cpio格式的命令
是一個標準工具,用於建立軟件檔案文件和從檔案文件中提取文件
cpio [選項] < [文件|設備]
-i
:copy-in模式,還原
-d
:還原時自動新建目錄
-v
:顯示還原過程
/usr/bin/zip
命令屬於哪一個軟件包[root~]$rpm -qf /usr/bin/zip zip-3.0-11.el7.x86_64
/usr/bin/zip
命令被誤刪[root~]$mv /usr/bin/zip /tmp/ [root~]$zip bash: zip: command not found
/usr/bin/zip
命令到當前目錄的 usr/bin/zip
[root~]$rpm2cpio /mnt/cdrom/Packages/zip-3.0-11.el7.x86_64.rpm | cpio -idv ./usr/bin/zip ./usr/bin/zip 1598 blocks [root~]$ll total 52K drwxr-xr-x 3 root root 16 May 22 05:10 usr/
zip
命令複製回 /usr/bin/
目錄下,修復丟失的文件[root~]$cp usr/bin/zip /usr/bin/ [root~]$zip Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license. Zip 3.0 (July 5th 2008). Usage: zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list] The default action is to add or replace zipfile entries from list, which can include the special name - to compress standard input. If zipfile and list are omitted, zip compresses stdin to stdout. -f freshen: only changed files -u update: only changed or new files -d delete entries in zipfile -m move into zipfile (delete OS files) -r recurse into directories -j junk (don't record) directory names -0 store only -l convert LF to CR LF (-ll CR LF to LF) -1 compress faster -9 compress better -q quiet operation -v verbose operation/print version info -c add one-line comments -z add zipfile comment -@ read names from stdin -o make zipfile as old as latest entry -x exclude the following names -i include only the following names -F fix zipfile (-FF try harder) -D do not add directory entries -A adjust self-extracting exe -J junk zipfile prefix (unzipsfx) -T test zipfile integrity -X eXclude eXtra file attributes -y store symbolic links as the link instead of the referenced file -e encrypt -n don't compress these suffixes -h2 show more help