离线yum源搭建

一.使用iso镜像挂载
1.下载iso镜像文件,(选择Everything版本)
https://mirrors.ustc.edu.cn/centos-vault/7.9.2009/isos/x86 64/Cent0S-7-x86 64-Everything-2009.iso

2.将原有的repo文件进行备份
操作前需要先下载一个工具yum install yum-utils -y
 

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo          epel.repo.rpmnew
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo  epel-testing.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel.repo
[root@localhost yum.repos.d]# mkdir back
[root@localhost yum.repos.d]# mv * back/
mv: 无法将目录"back" 移动至自身的子目录"back/back" 下
[root@localhost yum.repos.d]# ls
back
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror
Determining fastest mirrors
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@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
[root@localhost yum.repos.d]# 


挂载

[root@localhost yum.repos.d]# cd /mnt/centos/
[root@localhost centos]# ls
CentOS-7-x86_64-Everything-2009.iso
[root@localhost centos]# 
[root@localhost centos]# mount -o loop CentOS-7-x86_64-Everything-2009.iso /mnt/
mount: /dev/loop0 写保护,将以只读方式挂载
[root@localhost centos]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 962M     0  962M    0% /dev
tmpfs                    975M     0  975M    0% /dev/shm
tmpfs                    975M  8.9M  966M    1% /run
tmpfs                    975M     0  975M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G   12G  5.1G   71% /
/dev/sda1               1014M  194M  821M   20% /boot
tmpfs                    195M     0  195M    0% /run/user/0
/dev/loop0               9.5G  9.5G     0  100% /mnt
[root@localhost centos]# 
[root@localhost mnt]# yum-config-manager --add file:///mnt

已加载插件:fastestmirror
adding repo from: file:///mnt

[mnt]
name=added from: file://mnt
baseurl=file:///mnt
enabled=1


[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: mnt
Cleaning up list of fastest mirrors
Other repos take up 261 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
mnt                                                                         | 3.6 kB  00:00:00     
(1/2): mnt/group_gz                                                         | 153 kB  00:00:00     
(2/2): mnt/primary_db                                                       | 6.1 MB  00:00:00     
源标识                                源名称                                                 状态
mnt                                   added from: file://mnt                                 10,072
repolist: 10,072
[root@localhost yum.repos.d]# 
#可以看的成功了

二.提前下载好准备的三万rpm包
1.单机部署
提前下载准备好3万个RPM包,然后上传服务器到/home
需要下载好依赖yum install yum-utils
yum install createrepo
 

[root@localhost RPM]# ls
base  docker-ce-stable  epel  extras  updates
#这个RPM文件包里面就是准备好的3万个
[root@localhost RPM]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                         源名称                                                        状态
base/7/x86_64                  CentOS-7 - Base - mirrors.aliyun.com                          10,072
epel/x86_64                    Extra Packages for Enterprise Linux 7 - x86_64                13,791
extras/7/x86_64                CentOS-7 - Extras - mirrors.aliyun.com                           526
updates/7/x86_64               CentOS-7 - Updates - mirrors.aliyun.com                        6,173
repolist: 30,562
[root@localhost RPM]# createrepo /home/RPM
Spawning worker 0 with 6458 pkgs
Spawning worker 1 with 6458 pkgs
Spawning worker 2 with 6458 pkgs
Spawning worker 3 with 6457 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost RPM]# vi /etc/yum.repos.d/local.repo
[root@localhost RPM]# cat /etc/yum.repos.d/local.repo
[local]
name=Local YUM Repository
baseurl=file:///home/RPM
enabled=1
gpgcheck=0
[root@localhost RPM]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras local updates
Cleaning up list of fastest mirrors
[root@localhost RPM]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                        | 3.6 kB  00:00:00     
epel                                                                        | 4.3 kB  00:00:00     
extras                                                                      | 2.9 kB  00:00:00     
local                                                                       | 2.9 kB  00:00:00     
updates                                                                     | 2.9 kB  00:00:00     
(1/8): epel/x86_64/updateinfo                                               | 1.0 MB  00:00:00     
(2/8): base/7/x86_64/group_gz                                               | 153 kB  00:00:00     
(3/8): local/primary_db                                                     |  15 MB  00:00:00     
(4/8): epel/x86_64/group                                                    | 399 kB  00:00:00     
(5/8): extras/7/x86_64/primary_db                                           | 253 kB  00:00:00     
(6/8): base/7/x86_64/primary_db                                             | 6.1 MB  00:00:00     
(7/8): epel/x86_64/primary_db                                               | 8.7 MB  00:00:00     
(8/8): updates/7/x86_64/primary_db                                          |  27 MB  00:00:01     
源标识                         源名称                                                        状态
base/7/x86_64                  CentOS-7 - Base - mirrors.aliyun.com                          10,072
epel/x86_64                    Extra Packages for Enterprise Linux 7 - x86_64                13,791
extras/7/x86_64                CentOS-7 - Extras - mirrors.aliyun.com                           526
local                          Local YUM Repository                                          25,831
updates/7/x86_64               CentOS-7 - Updates - mirrors.aliyun.com                        6,173
repolist: 56,393
[root@localhost RPM]# 


2.共享其他内网机器

[root@localhost home]# yum install -y nfs-utils nfs yum-utils
[root@localhost RPM]# vim /etc/exports
[root@localhost RPM]# cat /etc/exports
/home/RPM *(rw)
[root@localhost RPM]#  systemctl restart nfs-server
[root@localhost RPM]# showmount -e 127.0.0.1
Export list for 127.0.0.1:
/home/RPM *
[root@localhost RPM]# 


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#然后去另外一台内网机器的客户端操作
[root@localhost ~]# yum install -y nfs-utils nfs yum-utils
[root@localhost ~]# systemctl restart nfs-server
[root@localhost ~]# mount -t nfs 192.168.227.133:/home/RPM /mnt/
[root@localhost ~]# df -hT
文件系统                  类型      容量  已用  可用 已用% 挂载点
devtmpfs                  devtmpfs  962M     0  962M    0% /dev
tmpfs                     tmpfs     975M   16K  975M    1% /dev/shm
tmpfs                     tmpfs     975M  8.8M  966M    1% /run
tmpfs                     tmpfs     975M     0  975M    0% /sys/fs/cgroup
/dev/mapper/centos-root   xfs        17G  4.6G   13G   27% /
/dev/sda1                 xfs      1014M  194M  821M   20% /boot
tmpfs                     tmpfs     195M     0  195M    0% /run/user/0
192.168.227.133:/home/RPM nfs4       47G   31G   17G   65% /mnt
[root@localhost ~]# 
[root@localhost ~]# yum-config-manager --add file:///mnt
已加载插件:fastestmirror
adding repo from: file:///mnt

[mnt]
name=added from: file:///mnt
baseurl=file:///mnt
enabled=1


[root@localhost ~]# 
[root@localhost ~]# echo gpgcheck=0 >> /etc/yum.repos.d/
CentOS-Base.repo           CentOS-Media.repo          epel.repo
CentOS-CR.repo             CentOS-Sources.repo        epel.repo.rpmnew
CentOS-Debuginfo.repo      CentOS-Vault.repo          epel-testing.repo
CentOS-fasttrack.repo      CentOS-x86_64-kernel.repo  mnt.repo
[root@localhost ~]# echo gpgcheck=0 >> /etc/yum.repos.d/mnt.repo 
[root@localhost ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras mnt updates
Cleaning up list of fastest mirrors

[root@localhost ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
mnt                                                                         | 2.9 kB  00:00:00     
mnt/primary_db                                                              |  15 MB  00:00:00     
源标识                        源名称                                                       状态
base/7/x86_64                 CentOS-7 - Base - mirrors.aliyun.com                         10,070+2
epel/x86_64                   Extra Packages for Enterprise Linux 7 - x86_64               13,789+2
extras/7/x86_64               CentOS-7 - Extras - mirrors.aliyun.com                            526
mnt                           added from: file:///mnt                                      25,826+5
updates/7/x86_64              CentOS-7 - Updates - mirrors.aliyun.com                      6,161+12
repolist: 56,372
[root@localhost ~]# 
#成功!然后可以下载自己想要的包了

[root@localhost ~]# yum install -y nginx
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2024-11-22 13:36:53 CST; 8s ago
  Process: 4325 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 4322 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 4320 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 4327 (nginx)
   CGroup: /system.slice/nginx.service
           ├─4327 nginx: master process /usr/sbin/nginx
           ├─4328 nginx: worker process
           ├─4329 nginx: worker process
           ├─4330 nginx: worker process
           └─4331 nginx: worker process

11月 22 13:36:53 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy .....
11月 22 13:36:53 localhost.localdomain nginx[4322]: nginx: the configuration file /etc/nginx/...ok
11月 22 13:36:53 localhost.localdomain nginx[4322]: nginx: configuration file /etc/nginx/ngin...ul
11月 22 13:36:53 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy s...r.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值