美文网首页
Redhat7更换yum源

Redhat7更换yum源

作者: liurongming | 来源:发表于2022-09-26 19:24 被阅读0次

安装redhat系统,在不能上网时,需要临时挂在本地yum源。

一、环境介绍

采用rhel-server-7.9-x86_64-dvd.iso最小化操作系统安装。
1、查看内核版本

[root@oracle19c ~]#  cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
[root@oracle19c ~]#

2、 yum检查

[root@oracle19c yum.repos.d]# yum --version
3.4.3
  Installed: rpm-4.11.3-45.el7.x86_64 at 2022-09-05 16:10
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2020-06-02 12:11
  Committed: Michal Domonkos <mdomonko@redhat.com> at 2020-06-02

  Installed: subscription-manager-1.24.42-1.el7.x86_64 at 2022-09-05 16:10
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2020-06-20 03:47
  Committed: Christopher Snyder <csnyder@redhat.com> at 2020-06-19

  Installed: yum-3.4.3-168.el7.noarch at 2022-09-05 16:10
  Built    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2020-04-16 06:17
  Committed: Pavla Kratochvilova <pkratoch@redhat.com> at 2020-04-16
[root@oracle19c yum.repos.d]#

3、查看使用repo

[root@oracle19c yum.repos.d]# cat redhat.repo
#
# Certificate-Based Repositories
# Managed by (rhsm) subscription-manager
#
# *** This file is auto-generated.  Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
#
# If this file is empty and this system is subscribed consider
# a "yum repolist" to refresh available repos
#
[root@oracle19c yum.repos.d]#

4、尝试安装vim

[root@oracle19c yum.repos.d]# yum install -y vim
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>
[root@oracle19c yum.repos.d]#

5、统计yum安装包数量

[root@oracle19c yum.repos.d]# yum list | wc -l
356
[root@oracle19c yum.repos.d]#

二、使用本地yum源

挂在本地yum源比较简单。
1、查看挂在情况

[root@oracle19c yum.repos.d]# df -hT
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                 tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                 tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                 tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs        36G  1.3G   34G   4% /
/dev/sda1             xfs      1014M  150M  865M  15% /boot
tmpfs                 tmpfs     378M     0  378M   0% /run/user/0
[root@oracle19c yum.repos.d]#

2、挂在iso到指定目录(目录可以自己定,一般放/mnt下)

# 创建挂在目录
mkdir -p  /mnt/cdrom

# 挂载方式一:mount /dev/cdrom /mnt/cdrom
[root@oracle19c dev]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@oracle19c dev]#

# 挂载方式二 :mount /dev/sr0 /mnt/cdrom/
root@oracle19c dev]# mount /dev/sr0 /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oracle19c dev]#

# 如果要卸载
# umount /mnt/cdrom/

# 查看挂载
[root@oracle19c cdrom]# df -hT
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                 tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                 tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                 tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs        36G  1.3G   34G   4% /
/dev/sda1             xfs      1014M  150M  865M  15% /boot
tmpfs                 tmpfs     378M     0  378M   0% /run/user/0
/dev/sr0              iso9660   4.3G  4.3G     0 100% /mnt/cdrom
[root@oracle19c cdrom]#

# 进入目录查看内容
[root@oracle19c dev]# cd /mnt/cdrom/
[root@oracle19c cdrom]# ll
total 974
dr-xr-xr-x. 4 root root   2048 Sep 18  2020 addons
dr-xr-xr-x. 3 root root   2048 Sep 18  2020 EFI
-r--r--r--. 1 root root   8266 Sep 18  2020 EULA
-r--r--r--. 1 root root   1455 Sep 18  2020 extra_files.json
-r--r--r--. 1 root root  18092 Sep 18  2020 GPL
dr-xr-xr-x. 3 root root   2048 Sep 18  2020 images
dr-xr-xr-x. 2 root root   2048 Sep 18  2020 isolinux
dr-xr-xr-x. 2 root root   2048 Sep 18  2020 LiveOS
-r--r--r--. 1 root root    114 Sep 18  2020 media.repo
dr-xr-xr-x. 2 root root 946176 Sep 18  2020 Packages
dr-xr-xr-x. 2 root root   2048 Sep 18  2020 repodata
-r--r--r--. 1 root root   3375 Jul 14  2020 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root   3211 Jul 14  2020 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root   1796 Sep 18  2020 TRANS.TBL
[root@oracle19c cdrom]#

3、创建本地repo文件

# 进入目录
cd /etc/yum.repos.d
# 创建文件
touch base.repo
# 编辑内容
vi base.repo
[root@oracle19c yum.repos.d]# cat base.repo
[local] # yum仓库名,可自定义
name=CentOS-$releasever-Media # yum仓库的描述信息
baseurl=file:///mnt/cdrom # yum源的访问地址。注意是///不是//
enabled=1 # 启用仓库
gpgcheck=0  # 不进行红帽标签检查

4、检查是否成功

root@oracle19c yum.repos.d]# yum clean all
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Cleaning repos: local
[root@oracle19c yum.repos.d]# yum makecache
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

local                                                                                                                                | 2.8 kB  00:00:00
(1/6): local/group                                                                                                                   | 628 kB  00:00:00
(2/6): local/primary                                                                                                                 | 2.1 MB  00:00:00
(3/6): local/other                                                                                                                   | 1.1 MB  00:00:00
(4/6): local/group_xz                                                                                                                |  95 kB  00:00:00
(5/6): local/productid                                                                                                               | 1.6 kB  00:00:00
(6/6): local/filelists                                                                                                               | 3.1 MB  00:00:00
local                                                                                                                                             5230/5230
local                                                                                                                                             5230/5230
local                                                                                                                                             5230/5230
Metadata Cache Created
[root@oracle19c yum.repos.d]#

[root@oracle19c yum.repos.d]# yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

repo id                                                             repo name                                                                         status
local                                                               CentOS-7Server-Media                                                              5,230
repolist: 5,230
[root@oracle19c yum.repos.d]#
# 再次查看可用包数量
[root@oracle19c yum.repos.d]# yum list | wc -l
5341

5、使用

[root@oracle19c yum.repos.d]# yum install -y wget
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================
 Package                          Arch                               Version                                        Repository                         Size
============================================================================================================================================================
Installing:
 wget                             x86_64                             1.14-18.el7_6.1                                local                             547 k

Transaction Summary
============================================================================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                                              1/1
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                                              1/1

Installed:
  wget.x86_64 0:1.14-18.el7_6.1

Complete!
[root@oracle19c yum.repos.d]#

至此,采用本地yum源安装完成。

二:配置本地网络yum源

配置本地网络yum源也相对比较简单。其原理就是要使用一台服务器把所需要的安装文件能使使用http协议网络访问。由于httpd安装比较简单可以直接使用。因此采用httpd即可。
1、安装并配置httpd

# 安装httpd软件。启动httpd服务并设置配置为开机启动。
# 命令:
yum install -y httpd
systemctl start httpd
systemctl enable httpd

# 开放防火墙
systemctl stop firewalld
systemctl disable firewalld

# 查看ip地址
ip a

浏览器输入 ip访问


image.png

httpd:默认配置在:/etc/httpd/conf/httpd.conf
从配置可以查看到:DocumentRoot "/var/www/html"
因此在/var/www/html下,软连接挂载文件即可

 ln -s /mnt/cdrom/ /var/www/html/pub

浏览器输入 ip/pub再次访问


image.png

2、配置yum源文件
更改:baseurl的值为:http://192.168.183.133/pub/即可
若使用centos的yum源头,前提是能上外网,也可以把地址改为:http://mirror.centos.org/centos/7.9.2009/os/x86_64/或阿里云的地址https://mirrors.aliyun.com/centos/7/os/x86_64/都可以使用。

[root@oracle19c yum.repos.d]# cat base.repo
[local]
name=CentOS-$releasever-Media
baseurl=http://192.168.183.133/pub/

enabled=1
gpgcheck=0

[root@oracle19c yum.repos.d]#

3、同本地yum源步骤

yum clean all
yum makecache

三、自建本地yum源仓库

1、直接安装

# 安装创建命令
yum install -y createrepo

2、先下载再安装

仅下载依赖包不安装
将createrepo及其依赖项下载至/home/test目录下(也可以建子目录,名称无所谓)
yum install -y createrepo --downloadonly --downloaddir /home/test
或进入目录执行:yumdownloader  

repotrack会下载所有依赖的包,不管系统是否已安装
yum -y install yum-utils
repotrack createrepo -p /home/test/

3、执行(createrepo ./)指令

cd /home 
createrepo ./
yum clean all
yum makecache 
[root@oracle19c test]# yum repolist
Loaded plugins: product-id, search-disabled-repos
repo id                                                             repo name                                                                         status
local                                                               CentOS-7Server-Media                                                              3
repolist: 3
[root@oracle19c test]#

此时,/data目录就成为yum源仓库目录。
当增减rpm包后,执行:createrepo --update ./

cd /home/test
rm net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
yum clean all
yum makecache
# 再次查看变成2
[root@oracle19c test]# yum repolist
Loaded plugins: product-id, search-disabled-repos
repo id                                                             repo name                                                                         status
local                                                               CentOS-7Server-Media                                                              2
repolist: 2
[root@oracle19c test]#

至此,搭建私有本地yum源完成,若使得网络访问,同上httpd配置即可。

附录:
提示错误:
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
处理方法:vim /etc/yum/pluginconf.d/subscription-manager.conf
注释:enabled=1

[root@oracle19c local]# cat /etc/yum/pluginconf.d/subscription-manager.conf
[main]
# enabled=1
[root@oracle19c local]#

相关文章

网友评论

      本文标题:Redhat7更换yum源

      本文链接:https://www.haomeiwen.com/subject/fhztartx.html