1.yum簡介
yum( Yellow dog Updater, Modified)是一個在 Fedora 和 RedHat 以及 SUSE 中的 Shell 前端軟件包管理器。
基於 RPM 包管理,能夠從指定的服務器自動下載 RPM 包並且安裝,可以自動處理依賴性關系,並且一次安裝所有依賴的軟件包,無須繁瑣地一次次下載、安裝。
yum 提供了查找、安裝、刪除某一個、一組甚至全部軟件包的命令,而且命令簡潔而又好記。
2.應用場景
yum本地倉庫搭建是為了當無法連接外網時,通過內網或本地的倉庫完成軟件的安裝與相關的依賴性解決。本地倉庫的搭建需要有一個yum源,或者一個系統鏡像(一般系統鏡像中有部分可安裝的軟件,這些軟件在選擇最小化安裝的時候,不會安裝到系統當中)。
以下實驗使用的均為系統鏡像源
3.本地yum倉庫搭建
3.1流程
3.2實操
1.掛載鏡像
[root@localhost ~]# mount /dev/sr0 /mnt ##/dev/sr0 是光驅設備
mount: /dev/sr0 is write-protected, mounting read-only
2.備份原yum
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost 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@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak ##移動原repo文件至bak中
[root@localhost yum.repos.d]# ls
bak
3.創建本地repo文件
[root@localhost yum.repos.d]# touch local.repo
[root@localhost yum.repos.d]# vim local.repo
[local] ##注釋
name=local ##配置名稱
baseurl=file:///mnt ##倉庫地址
gpgcheck=0 ##不檢查完整性
4.清緩存,簡歷元數據
[root@localhost yum.repos.d]# yum clean all ##情況緩存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: local
Cleaning up list of fastest mirrors
Other repos take up 161 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache ##建立元數據
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
local | 3.6 kB 00:00:00
(1/4): local/group_gz | 166 kB 00:00:00
(2/4): local/filelists_db | 3.2 MB 00:00:00
(3/4): local/primary_db | 3.1 MB 00:00:00
(4/4): local/other_db | 1.3 MB 00:00:00
Metadata Cache Created
5.測試安裝tree
[root@localhost yum.repos.d]# tree
bash: tree: command not found...
[root@localhost yum.repos.d]# yum install tree -y
…………
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@localhost yum.repos.d]# tree
.
├── bak
│ ├── CentOS-Base.repo
│ ├── CentOS-CR.repo
│ ├── CentOS-Debuginfo.repo
│ ├── CentOS-fasttrack.repo
│ ├── CentOS-Media.repo
│ ├── CentOS-Sources.repo
│ └── CentOS-Vault.repo
└── local.repo
1 directory, 8 files
3.利用HTTP服務搭建內網yum倉庫
3.1流程
為確保實驗成功,需要關閉防火牆和selinux。
服務端:
客戶端:
3.2 服務端配置
關閉防火牆與selinux確保正常通信
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
1.下載http服務
[root@localhost ~]# yum install httpd -y
…………
Installed:
httpd.x86_64 0:2.4.6-97.el7.centos.4
Dependency Installed:
apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-97.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7
Complete!
2.掛載鏡像
[root@localhost ~]# cd /var/www/html
[root@localhost html]# mkdir centos7
[root@localhost html]# ls
centos7
[root@localhost html]# mount /dev/sr0 centos7
mount: /dev/sr0 is write-protected, mounting read-only
3.啟動服務,測試服務是否正常
[root@localhost html]# systemctl start httpd
啟動過后,在實機中使用http服務訪問虛擬機對應目錄,應該可以正常查看掛載的內容。
3.3 客戶端配置
1.備份原yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak
2.創建本地repo文件
[root@localhost yum.repos.d]# touch http.repo
[root@localhost yum.repos.d]# vim http.repo
[http.repo]
name=http
baseurl=http://192.168.186.5/centos7
gpgcheck=0
3.清空緩存,建立元數據
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: http.repo
Cleaning up list of fastest mirrors
Other repos take up 129 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
http.repo | 3.6 kB 00:00:00
(1/4): http.repo/group_gz | 166 kB 00:00:00
(2/4): http.repo/filelists_db | 3.2 MB 00:00:00
(3/4): http.repo/primary_db | 3.1 MB 00:00:00
(4/4): http.repo/other_db | 1.3 MB 00:00:00
Metadata Cache Created
4.測試安裝
[root@localhost yum.repos.d]# tree
bash: tree: command not found...
[root@localhost yum.repos.d]# yum install tree -y
…………
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@localhost yum.repos.d]# tree
.
├── bak
│ ├── CentOS-Base.repo
│ ├── CentOS-CR.repo
│ ├── CentOS-Debuginfo.repo
│ ├── CentOS-fasttrack.repo
│ ├── CentOS-Media.repo
│ ├── CentOS-Sources.repo
│ └── CentOS-Vault.repo
└── http.repo
4.利用FTP服務搭建內網yum倉庫
4.1 流程
為確保實驗正常完成,關閉服務端的防火牆與selinux
服務端:
客戶端:
4.2 服務端配置
關閉防火牆與selinux
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
1.下載安裝FTP服務。
服務端使用vsftp軟件,進行安全傳輸(相對的安全)。
[root@localhost ~]# yum install vsftpd -y
…………
Installed:
vsftpd.x86_64 0:3.0.2-29.el7_9
Complete!
2.掛載鏡像
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# mount /dev/sr0 centos7
mount: /dev/sr0 is write-protected, mounting read-only
3.開啟服務
[root@localhost ftp]# systemctl start vsftpd
4.3 客戶端配置
1.客戶端直接安裝ftp即可
[root@localhost ~]# yum install ftp -y
…………
Installed:
ftp.x86_64 0:0.17-67.el7
Complete!
2.測試連接
[root@localhost ~]# ftp 192.168.186.5 ## 填寫服務端的ip
Connected to 192.168.186.5 (192.168.186.5).
220 (vsFTPd 3.0.2)
Name (192.168.186.5:root): ftp ## 使用匿名用戶ftp
331 Please specify the password.
Password: ## 直接回車即可
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,186,5,71,83).
150 Here comes the directory listing.
drwxrwxr-x 8 0 0 2048 Nov 25 2018 centos7
drwxr-xr-x 2 0 0 6 Jun 09 2021 pub
226 Directory send OK.
ftp> quit
221 Goodbye
3.剩下步驟與 3.3 步驟相同,注意配置本地repo配置如下。
[root@localhost yum.repos.d]# vim ftp.repo
[ftp.repo]
name=ftp
baserul=ftp://192.168.186.5/centos7
gpgcheck=0
清空緩存,建立元數據
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: ftp.repo
Cleaning up list of fastest mirrors
Other repos take up 130 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
ftp.repo | 3.6 kB 00:00:00
(1/4): ftp.repo/group_gz | 166 kB 00:00:00
(2/4): ftp.repo/filelists_db | 3.2 MB 00:00:00
(3/4): ftp.repo/primary_db | 3.1 MB 00:00:00
(4/4): ftp.repo/other_db | 1.3 MB 00:00:00
Metadata Cache Created
4.測試
[root@localhost yum.repos.d]# yum install tree -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 ftp.repo 46 k
Transaction Summary
==================================================================================================================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@localhost yum.repos.d]# tree
.
├── bak
│ ├── CentOS-Base.repo
│ ├── CentOS-CR.repo
│ ├── CentOS-Debuginfo.repo
│ ├── CentOS-fasttrack.repo
│ ├── CentOS-Media.repo
│ ├── CentOS-Sources.repo
│ └── CentOS-Vault.repo
└── ftp.repo
1 directory, 8 files