centos6.x-8.x无法上网(互联网),如何使用yum

本文介绍在离线环境下如何搭建YUM源,包括使用操作系统ISO文件和通过可上网电脑制作YUM包两种场景。详细步骤涵盖配置、缓存、安装软件等,适用于解决服务器软件安装依赖问题。

  • 场景1:
    客户现场服务器没有条件上互联网,然而安装rpm软件需要解决各种rpm包依赖问题,当所需要的rpm依赖包都可以从操作系统iso中获取时,可以通过iso文件搭建本服务器的yum源解决软件安装依赖问题。
    iso文件下载链接https://mirrors.huaweicloud.com/centos/6.10/isos/x86_64/CentOS-6.10-x86_64-bin-DVD1.iso
  • 场景2:
    客户现场服务器没有条件上互联网,然而安装rpm软件需要解决各种rpm包依赖问题,当所需要的rpm依赖包无法从操作系统iso中获取时,可以通过能上网的电脑或者虚拟机,yum安装所需软件,同时缓存rpm文件,然后备份rpm缓存目录,拷贝到不能上网的目标服务器搭建本地yum源解决依赖问题。

场景1、使用操作系统iso文件作为本地yum源

  1. 将/etc/yum.repos.d/下所有文件备份后删除并创建abc.repo (6.0以下有红帽rhel-debuginfo.repo文件)或者可以在xxx-base最后加【local】。
[root@RAC yum.repos.d]mkdir bak
[root@RAC yum.repos.d]move * bak
[root@RAC yum.repos.d]touch abc.repo
[root@RAC yum.repos.d]# ls
abc.repo bak
  1. vi编辑abc.repo 添加如下内容
#注意centos 6.0以下包路径为:/DVD/Server
#注意centos 6.x包路径为:/DVD
[base]
name = abc
baseurl =file:///DVD  
enabled =1
gpgcheck = 0

注意centos 8.0以上需要增加俩个路径(BaseOS和AppStream)

[base]
name = abcbase
baseurl =file:///DVD/BaseOS  
enabled =1
gpgcheck = 0
[app]
name = abcapp
baseurl =file:///DVD/AppStream
enabled =1
gpgcheck = 0
  1. yum repolist查看可用源
[root@RAC yum.repos.d] yum repolist
Loading mirror speeds from cached hostfile
源标识                                                                                    源名称                                                                                    状态
!base                                                                                     abcyum                                                                                    10,070


  1. 挂在ISO光盘到/DVD目录
[root@RAC yum.repos.d]# mkdir /DVD
[root@RAC yum.repos.d]# mount /dev/cdrom /DVD
mount: /dev/sr0 写保护,将以只读方式挂载
[root@RAC yum.repos.d]# ls /DVD
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  
.......
  1. 清理缓存并 安装软件vsftp测试
[root@RAC yum.repos.d]# yum clean all
正在清理软件源: base
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

[root@RAC yum.repos.d]# yum install vsftpd
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-25.el7 将被 安装
--> 解决依赖关系完成
  正在安装    : vsftpd-3.0.2-25.el7.x86_64                                                                                                                                                                1/1 
  验证中      : vsftpd-3.0.2-25.el7.x86_64                                                                                                                                                                1/1 
已安装:
  vsftpd.x86_64 0:3.0.2-25.el7                                                                                                                                                                                
完毕!

  1. 列出源包情况
[root@RAC yum.repos.d]# yum groups list  hidden
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
可用的环境分组:
   最小安装
   GNOME 桌面
可用组:
   Anaconda 工具
   CentOS Linux Client product core
   FTP 服务器
   开发工具
  。。。。。。。
  1. 安装源包的套件安装方法(如:开发工具)
yum  groupinstall "开发工具"

场景2、通过可以上网的电脑制作yum包,拷贝到目标服务器搭建本地yum源。

1、可以上网的Linux缓存所需各种rpm依赖包(centos7)
  1. 安装所需工具包
    yum install -y createrepo
  2. 编辑yum安装配置文件,启用keepcache=1
 vi /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
  1. 通过网络安装所需软件(比如docker容器)
    yum install -y docker --nogpgcheck
[root@RAC 7]#  yum install -y docker --nogpgcheck
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker.x86_64.2.1.13.1-161.git64e9980.el7_8 将被 安装
--> 解决依赖关系完成  
警告:RPM 数据库已被非 yum 程序修改。
 正在安装    : 2:docker-1.13.1-161.git64e9980.el7_8.x86_64                                                                                                                                               1/1 
 验证中      : 2:docker-1.13.1-161.git64e9980.el7_8.x86_64                                                                                                                                               1/1 
已安装:
 docker.x86_64 2:1.13.1-161.git64e9980.el7_8           
  1. cd切换目录到rpm缓存目录,查看缓存
[root@RAC ~]# cd /var/cache/yum/x86_64/7/
[root@RAC 7]# ls  extras/packages/
docker-1.13.1-161.git64e9980.el7_8.x86_64.rpm 
  1. 当前目录制作yum包createrepo -v ./
[root@RAC 7]# createrepo -v ./
[root@RAC 7]# ls
base  extras  <font color=red>repodata</font> timedhosts  timedhosts.txt  updates
[root@RAC 7]# tar -zcvf yumdocker.tar.gz *
2、无法上网的操作系统Linux操作
  1. WinSCP拷贝yumdocker.tar.gz文件到新服务器/DVD里,并解压
[root@RAC DVD]# tar -zxvf yumdocker.tar.gz 
[root@RAC DVD]# ls
base  extras  repodata  timedhosts  timedhosts.txt  updates  yumdocker.tar.gz
  1. 配置本地yum
cd /etc/yum.repos.d/
[root@RAC yum.repos.d]mkdir bak
[root@RAC yum.repos.d]move * bak
[root@RAC yum.repos.d]touch local.repo
[root@RAC yum.repos.d]# ls
local.repo bak
[local]
name=local-repo
baseurl=file:///DVD
gpgcheck=0
enabled=1
  1. 安装所需软件包
[root@RAC yum.repos.d]#  yum install -y docker
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
正在安装:
 docker                                     x86_64                                     2:1.13.1-161.git64e9980.el7_8                                     local                                      18 M
安装  1 软件包
总下载量:18 M
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : 2:docker-1.13.1-161.git64e9980.el7_8.x86_64                                                                                                                                          1/1 
  验证中      : 2:docker-1.13.1-161.git64e9980.el7_8.x86_64                                                                                                                                          1/1 
已安装:
  docker.x86_64 2:1.13.1-161.git64e9980.el7_8                                                                                                                                                            
完毕!
[root@sjb2 sasl2]# ll 总用量 128 lrwxrwxrwx. 1 root root 21 3月 23 2019 libanonymous.so -> libanonymous.so.3.0.0 lrwxrwxrwx. 1 root root 21 3月 23 2019 libanonymous.so.3 -> libanonymous.so.3.0.0 -rwxr-xr-x. 1 root root 19968 4月 11 2018 libanonymous.so.3.0.0 lrwxrwxrwx. 1 root root 20 7月 27 2020 libgssapiv2.so -> libgssapiv2.so.3.0.0 lrwxrwxrwx. 1 root root 20 7月 27 2020 libgssapiv2.so.3 -> libgssapiv2.so.3.0.0 -rwxr-xr-x. 1 root root 36984 4月 11 2018 libgssapiv2.so.3.0.0 lrwxrwxrwx. 1 root root 17 7月 27 2020 liblogin.so -> liblogin.so.3.0.0 lrwxrwxrwx. 1 root root 17 7月 27 2020 liblogin.so.3 -> liblogin.so.3.0.0 -rwxr-xr-x. 1 root root 20000 4月 11 2018 liblogin.so.3.0.0 lrwxrwxrwx. 1 root root 17 7月 27 2020 libplain.so -> libplain.so.3.0.0 lrwxrwxrwx. 1 root root 17 7月 27 2020 libplain.so.3 -> libplain.so.3.0.0 -rwxr-xr-x. 1 root root 19992 4月 11 2018 libplain.so.3.0.0 lrwxrwxrwx. 1 root root 18 3月 23 2019 libsasldb.so -> libsasldb.so.3.0.0 lrwxrwxrwx. 1 root root 18 3月 23 2019 libsasldb.so.3 -> libsasldb.so.3.0.0 -rwxr-xr-x. 1 root root 28216 4月 11 2018 libsasldb.so.3.0.0 其中sjb3 [root@sjb3 sasl2]# ll 总用量 48 lrwxrwxrwx. 1 root root 21 12月 19 2022 libanonymous.so -> libanonymous.so.3.0.0 lrwxrwxrwx. 1 root root 21 12月 19 2022 libanonymous.so.3 -> libanonymous.so.3.0.0 -rwxr-xr-x. 1 root root 19976 2月 24 2022 libanonymous.so.3.0.0 lrwxrwxrwx. 1 root root 18 12月 19 2022 libsasldb.so -> libsasldb.so.3.0.0 lrwxrwxrwx. 1 root root 18 12月 19 2022 libsasldb.so.3 -> libsasldb.so.3.0.0 -rwxr-xr-x. 1 root root 28224 2月 24 2022 libsasldb.so.3.0.0
09-10
[root@localhost ~]# sudo yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils 已加载插件:fastestmirror Loading mirror speeds from cached hostfile One of the configured repositories failed (未知), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: centos-sclo-rh
最新发布
12-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值