1. 程式人生 > 實用技巧 >RPM軟體包相關

RPM軟體包相關

RPM軟體包


Redhat Package Manager 軟體包管理


windows .exe

Linux .rpm


軟體包的含義

ant-antunit-1.2-10.el7.noarch.rpm

antlr-C++-2.7.7-30.el7.x86_64.rpm


ant-antunit #軟體包名稱

1.2 #軟體的版本

10 #軟體包編譯釋出的次數

el7 #適用於7系列的作業系統

el6 #適用於6系列作業系統

noarch #適用於任何cpu架構


x86_64 #硬體平臺 位數

.rpm #包的字尾名


軟體包的安裝方式


rpm包 預先編譯好的,安裝簡單 版本過低

原始碼包 手動編譯,安裝繁瑣 版本隨意

二進位制包 綠色軟體 解壓即用 無法修改原始碼


軟體包的獲取方式

本地的ISO映象 需要掛載使用

聯網下載

倉庫獲取 yum源

rpm軟體包管理工具


rpm 命令 #管理軟體包
選項 :
-ivh #安裝

-Uvh #升級

-e #解除安裝

-q #查詢指定軟體包

-qa #查詢所有已經安裝的軟體包

-qi #查詢軟體包本身相關資訊

-ql #查詢軟體包列表資訊

-qc #查詢軟體包相關檔案

-qf #查詢命令屬於哪個軟體包 必須是絕對路徑 前提本地要已經存在這個軟體包


#掛載映象
[root@qls ~]# ll /dev/sr0
brw-rw---- 1 root cdrom 11, 0 Jul 27 16:29 /dev/sr0
[root@qls ~]# ll /dev/cdrom
lrwxrwxrwx 1 root root 3 Jul 27 16:29 /dev/cdrom -> sr0
[root@qls ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@qls ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 98G 1.5G 97G 2% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt

[root@qls ~]# ll /mnt/Packages/ | wc -l
4023


#安裝

-i #安裝

-v #顯示安裝的過程

-h #顯示安裝的進度條

-ivh

[root@qls ~]# rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tree-1.6.0-10.el7 ################################# [100%]


#刪除 移除一個軟體包

[root@qls ~]# rpm -e tree


#rpm安裝太需要依賴了,不會自動尋找依賴,需要手動下載依賴 不建議使用

#安裝httpd 報錯
[root@qls ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm
error: Failed dependencies:
/etc/mime.types is needed by httpd-2.4.6-88.el7.centos.x86_64
httpd-tools = 2.4.6-88.el7.centos is needed by httpd-2.4.6-88.el7.centos.x86_64
libapr-1.so.0()(64bit) is needed by httpd-2.4.6-88.el7.centos.x86_64
libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-88.el7.centos.x86_64

#根據提示安裝相關依賴 報錯
[root@qls ~]# rpm -ivh /mnt/Packages/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm
error: Failed dependencies:
libapr-1.so.0()(64bit) is needed by httpd-tools-2.4.6-88.el7.centos.x86_64
libaprutil-1.so.0()(64bit) is needed by httpd-tools-2.4.6-88.el7.centos.x86_64

#查詢相關依賴包

[root@qls ~]# ll /mnt/Packages/ | grep apr
-rw-rw-r-- 1 root root 105728 Nov 29 2017 apr-1.4.8-3.el7_4.1.x86_64.rpm
-rw-rw-r-- 1 root root 192652 Nov 29 2017 apr-devel-1.4.8-3.el7_4.1.x86_64.rpm
-rw-rw-r-- 1 root root 94132 Jul 4 2014 apr-util-1.5.2-6.el7.x86_64.rpm
-rw-rw-r-- 1 root root 78072 Jul 4 2014 apr-util-devel-1.5.2-6.el7.x86_64.rpm
-rw-rw-r-- 1 root root 854420 Nov 12 2018 haproxy-1.5.18-8.el7.x86_64.rpm

#安裝相關依賴
[root@qls ~]# rpm -ivh /mnt/Packages/apr-1.4.8-3.el7_4.1.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:apr-1.4.8-3.el7_4.1 ################################# [100%]
[root@qls ~]# rpm -ivh /mnt/Packages/apr-util-1.5.2-6.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:apr-util-1.5.2-6.el7 ################################# [100%]

#嘗試安裝httpd-tools

[root@qls ~]# rpm -ivh /mnt/Packages/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:httpd-tools-2.4.6-88.el7.centos ################################# [100%]

#再次安裝httpd 報錯
[root@qls ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm
error: Failed dependencies:
/etc/mime.types is needed by httpd-2.4.6-88.el7.centos.x86_64


#搜尋相關檔案的依賴包
[root@qls ~]# yum provides /etc/mime.types
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* epel: fedora.cs.nctu.edu.tw
* extras: mirrors.aliyun.com
* updates: mirrors.ustc.edu.cn
mailcap-2.1.41-2.el7.noarch : Helper application and MIME type associations for file types
Repo : base
Matched from:
Filename : /etc/mime.types

#安裝依賴包
[root@qls ~]# rpm -ivh /mnt/Packages/mailcap-2.1.41-2.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mailcap-2.1.41-2.el7 ################################# [100%]

#最終安裝成功

[root@qls ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:httpd-2.4.6-88.el7.centos ################################# [100%]
[root@qls ~]#



#聯網安裝軟體包

[root@qls ~]# rpm -ivh https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tree-1.6.0-10.el7 ################################# [100%]


#升級安裝

-U #升級

[root@qls ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.jseg5b: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-agent-4.0.0-2.el7 ################################# [100%]

[root@qls ~]# zabbix_agentd -V
zabbix_agentd (daemon) (Zabbix) 4.0.0
Revision 85308 1 October 2018, compilation time: Oct 1 2018 08:41:36

Copyright (C) 2018 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

#升級安裝
[root@qls ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.0-1.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.0-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.e9rZWk: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-agent-4.4.0-1.el7 ################################# [ 50%]
Cleaning up / removing...
2:zabbix-agent-4.0.0-2.el7 ################################# [100%]
[root@qls ~]# zabbix_agentd -V
zabbix_agentd (daemon) (Zabbix) 4.4.0
Revision cfac660b25 7 October 2019, compilation time: Oct 7 2019 11:26:17

Copyright (C) 2019 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 1.0.1e-fips 11 Feb 2013
Running with OpenSSL 1.0.1e-fips 11 Feb 2013

#查詢指定的軟體包是否安裝

[root@qls ~]# rpm -q tree
tree-1.6.0-10.el7.x86_64
[root@qls ~]# rpm -q ifconfig
package ifconfig is not installed
[root@qls ~]# rpm -q net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64

#顯示所有已經安裝的軟體包

[root@qls ~]# rpm -qa | grep tree
tree-1.6.0-10.el7.x86_64


#查詢軟體包列表資訊
[root@qls ~]# rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf

#查詢相關配置檔案資訊
[root@qls ~]# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd

#查詢軟體包本身資訊

[root@qls ~]# rpm -qi httpd
Name : httpd
Version : 2.4.6
Release : 88.el7.centos
Architecture: x86_64
Install Date: Thu 30 Jul 2020 09:03:08 AM CST
Group : System Environment/Daemons
Size : 9817309
License : ASL 2.0
Signature : RSA/SHA256, Mon 12 Nov 2018 10:28:53 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : httpd-2.4.6-88.el7.centos.src.rpm
Build Date : Mon 05 Nov 2018 09:48:57 AM CST
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://httpd.apache.org/
Summary : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

#使用絕對路徑查詢命令屬於哪個軟體包 前提系統已經安裝這個軟體

[root@qls ~]# rpm -qf `which ping`
iputils-20160308-10.el7.x86_64
[root@qls ~]# which ping
/usr/bin/ping
[root@qls ~]# rpm -qf /usr/bin/ping
iputils-20160308-10.el7.x86_64


yum管理工具


yum源 yum倉庫

選項 :
repolist #針對倉庫操作

all #顯示所有

list #顯示所有可安裝的軟體包

installed #顯示已經安裝的

updates #顯示可更新的

check-update #顯示可更新的

update #更新

install #安裝

localinstall #本地安裝

reinstall #重新安裝

remove #解除安裝

erase #解除安裝

info #顯示軟體包資訊

search #搜尋

provides #查詢命令屬於哪個軟體包

groups #組包管理

install #安裝

remove #移除

clean #清空

all #清空所有

packages #清空軟體包

plugins #清空外掛

makecahce #生成快取

history #歷史記錄

list all #顯示所有

info ID #顯示某次記錄的資訊

undo ID #回滾這次的操作


yum-config-manager #yum倉庫管理工具

--disable #禁用倉庫

--enable #啟用倉庫


[root@qls ~]# ll /etc/yum.repos.d/
total 40
-rw-r--r-- 1 root root 1664 Nov 23 2018 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 Nov 23 2018 CentOS-CR.repo
-rw-r--r-- 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Nov 23 2018 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Nov 23 2018 CentOS-Sources.repo
-rw-r--r-- 1 root root 5701 Nov 23 2018 CentOS-Vault.repo
-rw-r--r-- 1 root root 951 Oct 3 2017 epel.repo
-rw-r--r-- 1 root root 1050 Oct 3 2017 epel-testing.repo


怎麼獲取yum源

本地的ISO映象

yum源倉庫

聯網的方式下載

本地yum倉庫


yum的種類

base #基礎源

epel #擴充套件源

軟體官方源 # nginx zabbix docker



阿里源

清華源

中科大

163源


#更新源
[root@qls ~]# rm -rf /etc/yum.repos.d/*

[root@qls ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo


[root@qls ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo



[root@qls ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 2523 Jul 30 09:51 CentOS-Base.repo
-rw-r--r-- 1 root root 664 May 11 2018 epel.repo


#顯示可用的yum倉庫
[root@qls ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
!base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070
!epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,422
!extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 412
!updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 900
repolist: 24,804


#顯示所有的
[root@qls ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
!base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 10,070
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,422
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: 412
!updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 900
repolist: 24,804


[root@qls ~]# yum install -y yum-utils


[root@qls ~]# yum-config-manager --disable epel


[root@qls ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 10,070
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 disabled
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: 412
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 900
repolist: 11,382

[root@qls ~]# yum-config-manager --enable epel



#軟體包管理

#顯示所有可安裝的包
[root@qls ~]# yum list


#顯示系統中已經安裝的包
[root@qls ~]# yum list installed


[root@qls ~]# yum list | grep ^tree
tree.x86_64 1.6.0-10.el7 @base
treelayout.noarch 1.0.3-4.el7 epel
treelayout-demo.noarch 1.0.3-4.el7 epel
treelayout-javadoc.noarch 1.0.3-4.el7 epel


#顯示可更新的包
[root@qls ~]# yum check-update

[root@qls ~]# yum list updates


[root@qls ~]# rpm -qa httpd
httpd-2.4.6-88.el7.centos.x86_64


#更新某個軟體包
[root@qls ~]# yum update httpd -y


[root@qls ~]# rpm -qa httpd
httpd-2.4.6-93.el7.centos.x86_64


#安裝軟體包
[root@qls ~]# yum install tree #互動式 麻煩


[root@qls ~]# yum install tree -y #免互動


#解除安裝
[root@qls ~]# yum remove tree -y

[root@qls ~]# yum erase tree -y


#聯網安裝軟體包
[root@qls ~]# yum install -y https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm


#本地安裝
[root@qls ~]# yum localinstall -y /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm



[root@qls ~]# systemctl start httpd
[root@qls ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2020-07-30 10:36:26 CST; 6s ago


[root@qls ~]# rm -f /etc/httpd/conf/httpd.conf
[root@qls ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

#重新安裝
[root@qls ~]# yum reinstall -y httpd


#搜尋
[root@qls ~]# yum search ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
================================================= N/S matched: ifconfig =================================================
python36-ifcfg.noarch : Python cross-platform network interface discovery (ifconfig/ipconfig/ip)

Name and summary matches only, use "search all" for everything.


#聯網搜尋命令屬於哪個軟體包
[root@qls ~]# yum provides ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
epel/x86_64/filelists_db | 12 MB 00:00:04
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : @base
Matched from:
Filename : /usr/sbin/ifconfig


#檢視軟體包相關資訊
[root@qls ~]# yum info tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
Name : tree
Arch : x86_64
Version : 1.6.0
Release : 10.el7
Size : 87 k
Repo : installed
Summary : File system tree viewer
URL : http://mama.indstate.edu/users/ice/tree/
License : GPLv2+
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@qls ~]# yum groups install Python


#組包的解除安裝
[root@qls ~]# yum groups remove Python

#yum快取

#清除包的快取
[root@qls ~]# yum clean packages
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
0 package files removed

#清除外掛的快取
[root@qls ~]# yum clean plugins
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors


#清除所有快取
[root@qls ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates

#生成快取
[root@qls ~]# yum makecache


#yum 歷史記錄
[root@qls ~]# yum history
Loaded plugins: fastestmirror
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
27 | reinstall -y httpd | 2020-07-30 10:37 | Reinstall | 1
26 | localinstall -y /mnt/Pac | 2020-07-30 10:11 | Install | 1
25 | erase tree -y | 2020-07-30 10:10 | Erase | 1
24 | install -y https://mirro | 2020-07-30 10:09 | Install | 1

#顯示所有歷史記錄
[root@qls ~]# yum history list all
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
27 | root <root> | 2020-07-30 10:37 | Reinstall | 1
26 | root <root> | 2020-07-30 10:11 | Install | 1
25 | root <root> | 2020-07-30 10:10 | Erase | 1
24 | root <root> | 2020-07-30 10:09 | Install | 1
23 | root <root> | 2020-07-30 10:08 | Erase | 1
22 | root <root> | 2020-07-30 10:08 | Install | 1


#檢視某個ID的歷史資訊
[root@qls ~]# yum history info 15
Loaded plugins: fastestmirror
Transaction ID : 15
Begin time : Wed Jul 22 08:51:56 2020
Begin rpmdb : 372:6b59857cbbb441dc1cf9e1a96ab23013fd830365
End time : (0 seconds)
End rpmdb : 373:c16ad60498e5079097783959293418aeedfc68b5
User : root <root>
Return-Code : Success
Command Line : install -y psmisc
Transaction performed with:
Installed rpm-4.11.3-35.el7.x86_64 @anaconda
Installed yum-3.4.3-161.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda
Packages Altered:
Install psmisc-22.20-16.el7.x86_64 @base
history info


#回滾歷史ID為10的操作
[root@qls ~]# yum history undo 10 -y


[root@qls ~]# yum --setopt=history_list_view=commands history list all
Loaded plugins: fastestmirror
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
28 | history undo 10 | 2020-07-30 10:49 | Erase | 21
27 | reinstall -y httpd | 2020-07-30 10:37 | Reinstall | 1
26 | localinstall -y /mnt/Pac | 2020-07-30 10:11 | Install | 1
25 | erase tree -y | 2020-07-30 10:10 | Erase | 1
24 | install -y https://mirro | 2020-07-30 10:09 | Install | 1
23 | erase tree -y | 2020-07-30 10:08 | Erase | 1
22 | install tree -y | 2020-07-30 10:08 | Install | 1
21 | remove tree -y | 2020-07-30 10:08 | Erase | 1



[root@qls ~]# ll /etc/yum.conf


#只下載 不安裝 指定下載的路徑
[root@qls ~]# yum install -y --downloadonly --downloaddir=/opt nginx


[root@qls ~]# ll /opt/
total 4380
-rw-r--r-- 1 root root 93872 Jul 4 2014 centos-indexhtml-7-9.el7.centos.noarch.rpm
-rw-r--r-- 1 root root 65788 Jul 4 2014 dejavu-fonts-common-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root 1482820 Jul 4 2014 dejavu-sans-fonts-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root 260512 Nov 12 2018 fontconfig-2.13.0-4.3.el7.x86_64.rpm
-rw-r--r-- 1 root root 10116 Jul 4 2014 fontpackages-filesystem-1.44-8.el7.noarch.rpm
-rw-r--r-- 1 root root 149492 Jul 4 2014 gd-2.0.35-26.el7.x86_64.rpm
-rw-r--r-- 1 root root 278636 Apr 25 2018 gperftools-libs-2.6.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 137752 Aug 23 2019 libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
-rw-r--r-- 1 root root 621364 Aug 23 2019 libX11-1.6.7-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 168172 Aug 23 2019 libX11-common-1.6.7-2.el7.noarch.rpm
-rw-r--r-- 1 root root 29784 Jul 4 2014 libXau-1.0.8-2.1.el7.x86_64.rpm
-rw-r--r-- 1 root root 218900 Nov 12 2018 libxcb-1.13-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 56800 Aug 11 2017 libXpm-3.5.12-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 575413 Oct 4 2019 nginx-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 19857 Oct 4 2019 nginx-all-modules-1.16.1-1.el7.noarch.rpm
-rw-r--r-- 1 root root 21089 Oct 4 2019 nginx-filesystem-1.16.1-1.el7.noarch.rpm
-rw-r--r-- 1 root root 30445 Oct 4 2019 nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 39849 Oct 4 2019 nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 29613 Oct 4 2019 nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 58301 Oct 4 2019 nginx-mod-mail-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 86465 Oct 4 2019 nginx-mod-stream-1.16.1-1.el7.x86_64.rpm

[root@qls ~]# cat /etc/yum.conf
[main]
#cachedir=/var/cache/yum/$basearch/$releasever
cachedir=/opt#指定下載儲存路徑
keepcache=1#開啟快取


[root@qls ~]# yum install -y nginx


[root@qls ~]# ll /opt/
total 12
drwxr-xr-x 4 root root 256 Jul 30 11:03 base
drwxr-xr-x 4 root root 4096 Jul 30 11:03 epel
drwxr-xr-x 4 root root 161 Jul 30 11:03 extras
-rw-r--r-- 1 root root 117 Jul 30 11:04 timedhosts
-rw-r--r-- 1 root root 107 Jul 30 11:03 timedhosts.txt
drwxr-xr-x 4 root root 161 Jul 30 11:03 updates
[root@qls ~]# find /opt/ -name "*.rpm"
/opt/base/packages/centos-indexhtml-7-9.el7.centos.noarch.rpm
/opt/base/packages/dejavu-fonts-common-2.33-6.el7.noarch.rpm
/opt/base/packages/fontconfig-2.13.0-4.3.el7.x86_64.rpm
/opt/base/packages/dejavu-sans-fonts-2.33-6.el7.noarch.rpm
/opt/base/packages/fontpackages-filesystem-1.44-8.el7.noarch.rpm
/opt/base/packages/gd-2.0.35-26.el7.x86_64.rpm
/opt/base/packages/gperftools-libs-2.6.1-1.el7.x86_64.rpm
/opt/base/packages/libX11-1.6.7-2.el7.x86_64.rpm
/opt/base/packages/libX11-common-1.6.7-2.el7.noarch.rpm
/opt/base/packages/libXau-1.0.8-2.1.el7.x86_64.rpm
/opt/base/packages/libXpm-3.5.12-1.el7.x86_64.rpm
/opt/base/packages/libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
/opt/base/packages/libxcb-1.13-1.el7.x86_64.rpm
/opt/epel/packages/nginx-all-modules-1.16.1-1.el7.noarch.rpm
/opt/epel/packages/nginx-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-filesystem-1.16.1-1.el7.noarch.rpm
/opt/epel/packages/nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-mail-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-stream-1.16.1-1.el7.x86_64.rpm

搭建本地yum倉庫



#把之前的倉庫全部將其失效

[root@qls ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 2523 Jul 30 09:51 CentOS-Base.repo
-rw-r--r-- 1 root root 664 Jul 30 09:57 epel.repo
[root@qls ~]# gzip /etc/yum.repos.d/*
[root@qls ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 601 Jul 30 09:51 CentOS-Base.repo.gz
-rw-r--r-- 1 root root 254 Jul 30 09:57 epel.repo.gz

#掛載映象源

[root@qls ~]# mount /dev/sr0 /mnt/

[root@qls ~]# df -h | grep mnt
/dev/sr0 4.3G 4.3G 0 100% /mnt




file:// #本地

ftp:// #檔案傳輸地址

http:// #網路協議地址

https:// #網路協議地址


#編寫yum原始檔
[root@qls ~]# cat /etc/yum.repos.d/lcoal.repo
[qls] #倉庫名稱 不能有空格
name=this is local repo #倉庫說明資訊
baseurl=file:///mnt #倉庫地址
enabled=1 #啟用倉庫
gpgcheck=0 #不檢查其合法性


#測試是否可用
[root@qls ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: qls
Cleaning up list of fastest mirrors
Other repos take up 309 M of disk space (use --verbose for details)


[root@qls ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
qls | 3.6 kB 00:00:00
(1/4): qls/group_gz | 166 kB 00:00:00
(2/4): qls/filelists_db | 3.2 MB 00:00:00
(3/4): qls/primary_db | 3.1 MB 00:00:00
(4/4): qls/other_db | 1.3 MB 00:00:00
Metadata Cache Created


[root@qls ~]# yum install -y tree

將本地倉庫共享給其他主機



10.0.0.100 #本地倉庫地址 服務端


10.0.0.101 #客戶端

#客戶端修改主機名
[root@qls ~]# hostnamectl set-hostname client





# 在10.0.0.100 主機上面操作

[root@qls ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@qls ~]# df -h | grep mnt
/dev/sr0 4.3G 4.3G 0 100% /mnt

#安裝檔案傳輸工具
[root@qls ~]# yum install -y vsftpd

#啟動
[root@qls ~]# systemctl start vsftpd
[root@qls ~]# systemctl enable vsftpd

#關閉防火牆
[root@qls ~]# systemctl stop firewalld

#關閉Selinux
[root@qls ~]# setenforce 0


#測試

#瀏覽器輸出
ftp://10.0.0.100/


#訪問的是這個目錄
[root@qls ~]# ll /var/ftp/
total 0
drwxr-xr-x 2 root root 6 Oct 31 2018 pub


[root@qls ~]# mkdir /var/ftp/local-base
[root@qls ~]# ll /var/ftp/
total 0
drwxr-xr-x 2 root root 6 Jul 30 19:55 local-base
drwxr-xr-x 2 root root 6 Oct 31 2018 pub
[root@qls ~]# cp -rp /mnt/Packages/* /var/ftp/local-base/

#下載管理工具
[root@qls ~]# yum install -y createrepo


#告訴系統,這是個映象yum源倉庫
[root@qls ~]# createrepo /var/ftp/local-base/
Spawning worker 0 with 4021 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete


#修改yum配置檔案
[root@qls ~]# cat /etc/yum.repos.d/lcoal.repo
[qls]
name=this is local repo
baseurl=ftp://10.0.0.100/local-base/
enabled=1
gpgcheck=0


[root@qls ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
qls this is local repo 4,021
repolist: 4,021





#讓其他主機使用這個倉庫
在10.0.0.101主機上面操作


[root@client ~]# systemctl stop firewalld
[root@client ~]# setenforce 0



[root@client ~]# gzip /etc/yum.repos.d/*
[root@client ~]# ll /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 549 Nov 23 2018 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Nov 23 2018 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Nov 23 2018 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Nov 23 2018 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Nov 23 2018 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Nov 23 2018 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 633 Nov 23 2018 CentOS-Vault.repo.gz


#編寫yum源配置檔案
[root@client ~]# cat /etc/yum.repos.d/lcoal.repo
[qls]
name=this is local repo
baseurl=ftp://10.0.0.100/local-base/
enabled=1
gpgcheck=0



#測試
[root@client ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: qls
[root@client ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
qls | 2.9 kB 00:00:00
(1/3): qls/filelists_db | 3.2 MB 00:00:00
(2/3): qls/primary_db | 3.2 MB 00:00:00
(3/3): qls/other_db | 1.3 MB 00:00:00
Metadata Cache Created


[root@client ~]# yum install vim -y