Linux 挂载光盘镜像配置本地 yum 源安装软件 您所在的位置:网站首页 linux挂载安装包 Linux 挂载光盘镜像配置本地 yum 源安装软件

Linux 挂载光盘镜像配置本地 yum 源安装软件

2023-10-21 04:21| 来源: 网络整理| 查看: 265

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 ResolutionCentOS 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,021SUSE 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://[email protected]/suse/suse12sp4s390x suse Adding repository 'suse' .....................................................................................[done] Repository 'suse' successfully added URI : ftp://[email protected]/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://[email protected]/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%



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有