Linux 掛載光碟鏡像配置本地 yum 源安裝軟體
- 2019 年 10 月 4 日
- 筆記
Yum(全稱為 Yellowdog Updater, Modified)是一個在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端軟體包管理器。CentOS 和 Redhat 版本的 Linux 一般安裝軟體包選擇 rpm 和 yum 安裝方式,這也是比較常見的方式。不過 rpm 安裝時如果有其他依賴的包則需要先安裝依賴包,比較麻煩, yum 則可以解決依賴關係,也可同時安裝多個 rpm 包。當然 deb 軟體包安裝以及源碼方式安裝也有使用。deb 軟體包一般以 .deb 後綴結尾,dpkg -i 包名即可安裝。源碼方式的包一般都以.tar.gz 或者 .tar.bz2 結尾,下載後校檢md5值,解壓後經過配置(./configure)、編譯(make)、安裝(make install)便可以完成。
一般傳統行業的公司的生產環境均是內網環境,是沒有辦法上網的,故網路 yum 源就不用考慮了,大公司基本上會使用區域網內的 FTP 伺服器,配置 ftp 方式的 yum 源,通過區域網安裝軟體,也可掛載光碟鏡像。個人學習使用或小公司基本上會配置本地 yum 源,以後有時間可以說說網路 yum 源,下面就先說說配置本地 yum 源以及安裝軟體的方式。
本次演示使用 Oracle VM VirtualBox 下的 Redhat6.4 以及 VMware Workstation Pro 下的 CentOS 7.6 以及簡略說明 linuxone 下的 suse12sp4 環境。
- Redhat6.4 下配置 yum 源
一、插入光碟鏡像
圖形化介面上能夠看到新增光碟圖標,默認自動彈出窗口顯示光碟中文件
二、 查看光碟對應路徑
切換到光碟目錄,使用 Tab 補齊的方法進入,便可以看到很多軟體包,但由於默認路徑有空格,不方便配置 yum 源,故需要重新掛載光碟。
[root@JiekeXu ~]# cd /media/RHEL_6.4 x86_64 Disc 1/ [root@JiekeXu RHEL_6.4 x86_64 Disc 1]# ls
三、創建目錄
光碟載入到光碟機後默認掛載點(訪問入口)為 /media/RHEL_6.4 x86_64 Disc 1 路徑中包含空格,不方便使用。
創建目錄 作為新掛載點 (訪問光碟的入口)
[root@JiekeXu ~]# mkdir /mnt/dvd [root@JiekeXu ~]# ls -ld /mnt/dvd
四、重新掛載
df -Th 查看光碟對應設備名稱 /dev/sr0
掛載光碟到新建的掛載點
[root@JiekeXu ~]# mount /dev/sr0 /mnt/dvd [root@JiekeXu ~]# df -Th
使用新掛載點即可訪問光碟中文件
[root@JiekeXu ~]# ls /mnt/dvd
/mnt/dvd/Server 是配置 yum 倉庫要用到的路徑
五、修改配置文件配置 yum 源
[root@JiekeXu ~]# cd /etc/yum.repos.d/ [root@JiekeXu yum.repos.d]# ll total 16K -r--r--r-- 1 root root 114 Jul 2 2015 packagekit-media.repo -rw-r--r--. 1 root root 358 Oct 19 2017 redhat.repo -rw-r--r-- 1 root root 656 Oct 20 2017 rhel64.repo -rw-r--r--. 1 root root 529 Jun 12 2015 rhel-source.repo [root@JiekeXu yum.repos.d]#
配置文件目錄 /etc/yum.repos.d/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release 表示公鑰文件地址
編輯配置文件,在最後追加寫入內容 baseurl 中 file:// 表示本地文件,第三個 / 表示 根目錄
[root@JiekeXu yum.repos.d]# cp rhel-source.repo rhel-source.repo.bak [root@JiekeXu yum.repos.d]# vi rhel-source.repo [rhel64] name=rhel64 repo baseurl=file:///mnt/dvd/Server gpgcheck=0 [root@JiekeXu yum.repos.d]# tail -5 rhel-source.repo
六、yum 基本操作
清除快取
[root@JiekeXu yum.repos.d]# yum clean all Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Repository rhel-source is listed more than once in the configuration Repository rhel-source-beta is listed more than once in the configuration Cleaning repos: InstallMedia rhel67 rhel67rpm Cleaning up Everything
列出軟體包
[root@JiekeXu yum.repos.d]# yum list Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. [root@JiekeXu yum.repos.d]# yum list | grep zsh Repository rhel-source is listed more than once in the configuration Repository rhel-source-beta is listed more than once in the configuration zsh.x86_64 4.3.11-4.el6 @rhel64
yum 安裝、查看、刪除軟體包
[root@JiekeXu yum.repos.d]# yum install zsh [root@JiekeXu yum.repos.d]# yum info zsh [root@JiekeXu yum.repos.d]# yum remove zsh
七、 yum install XXX 安裝其他的包
本地鏡像源內的 rpm 包便可以自由安裝了,使用 -y 則不用提示直接安裝。
[root@JiekeXu yum.repos.d]# yum install vim* -y [root@JiekeXu yum.repos.d]# yum install x11* Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Repository rhel-source is listed more than once in the configuration Repository rhel-source-beta is listed more than once in the configuration Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package xorg-x11-apps.x86_64 0:7.7-6.el6 will be installed --> Finished Dependency Resolution
- CentOS 7.6 下配置 yum 源
CentOS 系列的 Linux 作業系統目前市場上使用的還是比較多的,而且很多公司也都陸陸續續使用 7 系列版本,那麼本次將使用 CentOS 7.6 作為演示版本。
一、關閉防火牆
- 臨時關閉防火牆 systemctl stop firewalld
- 永久防火牆開機自關閉 systemctl disable firewalld
- 臨時打開防火牆 systemctl start firewalld
- 防火牆開機啟動 systemctl enable firewalld
- 查看防火牆狀態 systemctl status firewalld
[root@JiekeXu ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since 六 2019-09-07 08:33:48 CST; 18h ago Docs: man:firewalld(1) Main PID: 8220 (firewalld) Tasks: 2 CGroup: /system.slice/firewalld.service └─8220 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 9月 07 08:33:40 JiekeXu systemd[1]: Starting firewalld - dynamic firewall daemon... 9月 07 08:33:48 JiekeXu systemd[1]: Started firewalld - dynamic firewall daemon. 9月 07 08:33:55 JiekeXu firewalld[8220]: WARNING: /etc/sysconfig/network-scripts/ifcfg-ens32: Duplicate option definition: 'BOO...tatic"' Hint: Some lines were ellipsized, use -l to show in full. [root@JiekeXu ~]# [root@JiekeXu ~]# systemctl stop firewalld [root@JiekeXu ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since 日 2019-09-08 03:19:50 CST; 3s ago Docs: man:firewalld(1) Process: 8220 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 8220 (code=exited, status=0/SUCCESS) 9月 07 08:33:40 JiekeXu systemd[1]: Starting firewalld - dynamic firewall daemon... 9月 07 08:33:48 JiekeXu systemd[1]: Started firewalld - dynamic firewall daemon. 9月 07 08:33:55 JiekeXu firewalld[8220]: WARNING: /etc/sysconfig/network-scripts/ifcfg-ens32: Duplicate option definition: 'BOO...tatic"' 9月 08 03:19:46 JiekeXu systemd[1]: Stopping firewalld - dynamic firewall daemon... 9月 08 03:19:50 JiekeXu systemd[1]: Stopped firewalld - dynamic firewall daemon. Hint: Some lines were ellipsized, use -l to show in full. [root@JiekeXu ~]# [root@JiekeXu ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@JiekeXu ~]# [root@JiekeXu ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) 9月 07 08:33:40 JiekeXu systemd[1]: Starting firewalld - dynamic firewall daemon... 9月 07 08:33:48 JiekeXu systemd[1]: Started firewalld - dynamic firewall daemon. 9月 07 08:33:55 JiekeXu firewalld[8220]: WARNING: /etc/sysconfig/network-scripts/ifcfg-ens32: Duplicate option definition: 'BOO...tatic"' 9月 08 03:19:46 JiekeXu systemd[1]: Stopping firewalld - dynamic firewall daemon... 9月 08 03:19:50 JiekeXu systemd[1]: Stopped firewalld - dynamic firewall daemon. Hint: Some lines were ellipsized, use -l to show in full.
二、關閉 SELINUX
編輯 /etc/selinux/config 文件,將其設置為 disabled,注意編輯 /etc/sysconfig/selinux 文件也可。
[root@JiekeXu sysconfig]# pwd /etc/sysconfig [root@JiekeXu sysconfig]# ls -l selinux lrwxrwxrwx. 1 root root 17 7月 4 02:03 selinux -> ../selinux/config [root@JiekeXu ~]# cat /etc/sysconfig/selinux [root@JiekeXu ~]# more /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
四、設置域名解析
[root@JiekeXu ~]# vi /etc/resolv.conf # Generated by NetworkManager nameserver 192.168.32.1 nameserver 192.168.32.0 nameserver 8.8.8.8 nameserver 114.114.114.114
五、掛載鏡像
首先插入光碟鏡像
六、建立目錄,掛載鏡像,將其寫入開機自啟動文件
mkdir /mnt/centos mount -t iso9660 -o loop /dev/sr0 /mnt/centos vim /etc/fstab
添加如下一行
/dev/cdrom /mnt/contos iso9660 defaults 0 0 0 0 [root@JiekeXu sysconfig]# cat /etc/fstab # /etc/fstab # Created by anaconda on Thu Jul 4 01:57:56 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=d40ff30e-48ce-4286-8e3f-bc9e30f3a6bb /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults,size=1024M 0 0 /dev/cdrom /mnt/centos iso9660 defaults 0 0 0 0
七、配置 yum 源
進入/etc/yum.repos.d 目錄修改CentOS-Media.repo文件
mv CentOS-Base.repo CentOS-Base.repo_bak vi CentOS-Media.repo [local] //id:local 表示本地 name=CentOS-$releasever - local baseurl=file:///mnt/centos //掛載鏡像的文件夾路徑 gpgcheck=0 //設置此源是否檢驗文件,1為校驗,0為不校驗 enabled=1 //啟用該yum源 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7//公鑰文件地址
注意:如果沒有注釋掉 CentOS-Base.repo 則會出現如下未知錯誤。
[root@JiekeXu yum.repos.d]# yum clean all; 已載入插件:fastestmirror, langpacks 正在清理軟體源:base extras local updates Cleaning up list of fastest mirrors [root@JiekeXu yum.repos.d]# yum repolist 已載入插件:fastestmirror, langpacks Determining fastest mirrors Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的錯誤" Loading mirror speeds from cached hostfile Loading mirror speeds from cached hostfile Loading mirror speeds from cached hostfile Loading mirror speeds from cached hostfile 源標識 源名稱 狀態 base/7/x86_64 CentOS-7 - Base 0 extras/7/x86_64 CentOS-7 - Extras 0 local CentOS-7 - local 0 updates/7/x86_64 CentOS-7 - Updates 0 repolist: 0
八、簡單應用
清空快取 yum clean all 查看可用 yum 源 yum repolist [root@JiekeXu yum.repos.d]# yum clean all; 已載入插件:fastestmirror, langpacks 正在清理軟體源:local Cleaning up list of fastest mirrors [root@JiekeXu yum.repos.d]# yum repolist 已載入插件:fastestmirror, langpacks Determining fastest mirrors local | 3.6 kB 00:00:00 (1/2): local/group_gz | 166 kB 00:00:00 (2/2): local/primary_db | 3.1 MB 00:00:00 源標識 源名稱 狀態 local CentOS-7 - local 4,021 repolist: 4,021
- SUSE 12sp4 環境下 zypper 源配置
1. zypper 的幾個重要選項:
選項 |
說明 |
---|---|
repos, lr |
列出庫 |
sl |
列出庫(目的是與rug兼容) |
addrepo, ar |
添加庫 |
sa |
添加庫(目的是與rug兼容) |
renamerepo, nr |
重命名指定的安裝源 |
modifyrepo, mr |
修改指定的安裝源 |
refresh, ref |
刷新所有安裝源 |
clean |
清除本地快取 |
2. zypper 軟體管理:
選項 |
說明 |
---|---|
install, in |
安裝軟體包 |
remove, rm |
刪除軟體包 |
verify, ve |
檢驗軟體包依賴關係的完整性 |
update, up |
更新已安裝的軟體包到新的版本 |
dist-upgrade, dup |
整個系統的升級 |
source-install, si |
安裝源程式碼軟體包和它們的編譯依賴 |
3. zypper 的查詢選項:
選項 |
說明 |
---|---|
search, se |
安裝軟體包 |
packages, pa |
列出所有可用的軟體包 |
patterns, pt |
列出所有可用的模式 |
products, pd |
列出所有可用的產品 |
what-provides, wp |
列出能夠提供指定功能的軟體包 |
下面實操說明配置 zypper 源
JiekeXu2:~ # zypper clean All repositories have been cleaned up. JiekeXu2:~ # zypper clean all Repository 'all' not found by its alias, number, or URI. Use 'zypper repos' to get the list of defined repositories. Could not clean the repositories because of errors. JiekeXu2:~ # cat /etc/issue Welcome to SUSE Linux Enterprise Server 12 SP4 (s390x) - Kernel r (l). JiekeXu2:~ # zypper rr 1 Removing repository 'SLES12-SP4 12.4-0' ......................................................................[done] Repository 'SLES12-SP4 12.4-0' has been removed. JiekeXu2:~ # zypper rr 1 Repository '1' not found by alias, number or URI. JiekeXu2:~ # zypper rr 1 Repository '1' not found by alias, number or URI. JiekeXu2:~ # zypper ar ftp://ftp@10.18.127.222/suse/suse12sp4s390x suse Adding repository 'suse' .....................................................................................[done] Repository 'suse' successfully added URI : ftp://ftp@10.18.127.222/suse/suse12sp4s390x Enabled : Yes GPG Check : Yes Autorefresh : No Priority : 99 (default priority) Repository priorities are without effect. All enabled repositories share the same priority. JiekeXu2:~ # zypper lr Repository priorities are without effect. All enabled repositories share the same priority. # | Alias | Name | Enabled | GPG Check | Refresh --+-------+------+---------+-----------+-------- 1 | suse | suse | Yes | ( p) Yes | No JiekeXu2:~ # zypper ref Retrieving repository 'suse' metadata ---------------------------------------------------------------------------[] Authentication required for 'ftp://ftp@10.18.127.222/suse/suse12sp4s390x' User Name: ftpuser Password: Retrieving repository 'suse' metadata ........................................................................[done] Building repository 'suse' cache .............................................................................[done] All repositories have been refreshed. JiekeXu2:~ # zypper -n in libaio-devel Loading repository data... Reading installed packages... Resolving package dependencies... The following NEW package is going to be installed: libaio-devel 1 new package to install. Overall download size: 6.5 KiB. Already cached: 0 B. After the operation, additional 9.1 KiB will be used. m | 9.43-8.1 | s390x | s390 | SLES12-SP4 12.4-0 | hfsutils | 3.2.6-1240.71 | s390x | SLES12-SP4 12.4-0 | gnome-session-lang | 3.20.2-19.2 | noari | SLES12-SP4 12.4-0 | hicolor-icon-theme | 0.15-4.1 | noarch | SLES12-SP4 12.4-0 | gnome-settings-daemon | 3.20.1-50.5.8 | s390 | SLES12-SP4 12.4-0 | hmaccalc | 0.9.13-2.3 | s390x | SLES12-SP4 12.4-0 | gnome-settings-daemon-lang | 3.20.1-50.5.8 | noar | SLES12-SP4 12.4-0 | hostinfo | 1.0-17.12 | noarch | SLES12-SP4 12.4-0 | gnome-shell | 3.20.4-77.17.1 | s390 | SLES12-SP4 12.4-0 | hplip | 3.16.11-1.33 | s390x | SLES12-SP4 12.4-0 | gnome-shell-browser-plugin | 3.20.4-77.17.1 | s390 | SLES12-SP4 12.4-0 | hplip-hpijs | 3.16.11-1.33 | s390x | SLES12-SP4 12.4-0 | gnome-shell-classic | 3.20.1-24.27.44 | noar | SLES12-SP4 12.4-0 | hplip-sane | 3.16.11-1.33 | s390x | SLES12-SP4 12.4-0 | gnome-shell-extensions-common | 3.20.1-24.27.44 | noari | SLES12-SP4 12.4-0 | hunspell | 1.3.2-18.1 | s390x | SLES12-SP4 12.4-0 | gnome-shell-extensions-common-lang | 3.20.1-24.27.44 | noar | SLES12-SP4 12.4-0 | hunspell-32bit | 1.3.2-18.1 | s390x | SLES12-SP4 12.4-0 | gnome-shell-lang | 3.20.4-77.17.1 | noari | SLES12-SP4 12.4-0 | hunspell-tools | 1.3.2-18.1 | s390x | SLES12-SP4 12.4-0 | gnome-shell-search-provider-gnome-terminal | 3.20.2-8.62 | s390Continue? [y/n/...? shows all options] (y): y Retrieving package libaio-devel-0.3.109-17.15.s390x (1/1), 6.5 KiB ( 9.1 KiB unpacked) Retrieving: libaio-devel-0.3.109-17.15.s390x.rpm .............................................................[done] Checking for file conflicts: .................................................................................[done] (1/1) Installing: libaio-devel-0.3.109-17.15.s390x ...........................................................[done]
當然,區域網也有不通的時候,那麼我們只要掛載光碟鏡像或者上傳鏡像到系統某個目錄下,如下 5 步也很方便配置 zypper 源,還等什麼,趕快來試試吧。
1、首先建立掛載目錄
mkdir /mnt/iso
2、上傳光碟鏡像到 /app 目錄,並掛載鏡像
mount -t iso9660 /app/SLES-11-SP4-DVD-x86_64-GM-DVD1.iso /mnt/iso
3、添加庫,配置本地 repo
zypper ar file:///mnt/iso ss
4、查看列出本地庫
zypper lr
JiekeXu2:/app/oracle # zypper lr Repository priorities are without effect. All enabled repositories share the same priority. # | Alias | Name | Enabled | GPG Check | Refresh --+-----------+-----------+---------+-----------+-------- 1 | suse12sp4 | suse12sp4 | Yes | (r ) Yes | No
5、 zypper install 或者 zypper in xxx 安裝包
zypper in binutils-2.19
80%