内网下Yum仓库搭建配置

1、实验环境

虚拟机环境:

  • VMware 12 版本虚拟机

网络环境:

  • 内网 IP 段:172.16.1.0
  • 外网 iP 段(模拟):10.0.0.0

实验基础:(能够上网,有原本yum源)

  • m01:外网 IP 10.0.0.61;内网 IP :172.16.1.61
  • web01:外网 IP 10.0.0.7;内网 IP :172.16.1.7

Linux版本:

  • CentOS Linux release 7.6.1810
  • 3.10.0-957.10.1.el7.x86_64

提示:本无需外网,因个人原因而添加,真实环境只需内网即可,有本地yum仓库的可认为是服务端,其他主机作为同样也能像本案例中的web01一样作为客户端

2、实验步骤

2.1、m01:制作本地yum(服务端)

1)将CentOS 7 的镜像装入CD/DVD中,如下图所示:

image

2)将/mnt目录作为挂载点,挂载(也可挂载其他目录中)然后查看里面的文件

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
mount /dev/cdrom /mnt/

df -h|grep 'mnt'

cd /mnt/

ll

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载

[root@m01 ~]# df -h|grep 'mnt'
/dev/sr0        4.3G  4.3G     0  100% /mnt

[root@m01 ~]# cd /mnt/
[root@m01 /mnt]# 
[root@m01 /mnt]# ll
总用量 686
-rw-rw-r-- 1 root root     14 11月 26 00:01 CentOS_BuildTag
drwxr-xr-x 3 root root   2048 11月 26 00:20 EFI
###省略###

3)创建安装包存放的目录

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
mkdir -p /var/ftp/pub/Packages

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /mnt]# mkdir -p /var/ftp/pub/Packages

4)复制ISO中的所有文件(时间比较久,需要等待一段时间)完成后查看确认

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
cp -a /mnt/* /var/ftp/pub

cd /var/ftp/pub/ 

ls -rtlh

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /mnt]# cp -a /mnt/* /var/ftp/pub
[root@m01 /mnt]# cd /var/ftp/pub/ 
[root@m01 /var/ftp/pub]# ls -rtlh
总用量 320K
-rw-rw-r-- 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-rw-rw-r-- 1 root root 1.7K 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root  18K 12月 10 2015 GPL
###省略###

5)安装vsftp服务,启动和设置开机启动

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
yum install -y vsftpd

systemctl start vsftpd

systemctl enable vsftpd

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /var/ftp/pub]# yum install -y vsftpd
###省略###
已安装:
  vsftpd.x86_64 0:3.0.2-25.el7                                                                                                                     

完毕!
[root@m01 /var/ftp/pub]# systemctl start vsftpd
[root@m01 /var/ftp/pub]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

6)安装createrepo软件包

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
cd /var/ftp/pub/Packages

yum install -y createrepo

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /var/ftp/pub]# cd /var/ftp/pub/Packages
[root@m01 /var/ftp/pub/Packages]# yum install -y createrepo
###省略###
已安装:
  createrepo.noarch 0:0.9.9-28.el7                                                                                                                 

作为依赖被安装:
  deltarpm.x86_64 0:3.6-3.el7                                          python-deltarpm.x86_64 0:3.6-3.el7                                         

完毕!

7)上传并拷贝安装的软件所需要的相关文件到Packges包下(例如oracle安装所需依赖包、docker安装所需依赖包等,这里不需要,可直接跳过)

8)创建Yum仓库(执行过程可能需要很长时间的等待)

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
cd /var/ftp/pub 

createrepo .
#(注意后面的点)

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /var/ftp/pub/Packages]# cd /var/ftp/pub 
[root@m01 /var/ftp/pub]# createrepo .
Spawning worker 0 with 4021 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

9)清除原有配置缓存,然后缓存yum源(需要一段时间)

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
yum clean all

yum makecache

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /var/ftp/pub]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras updates
Cleaning up list of fastest mirrors
[root@m01 /var/ftp/pub]# yum makecache
###省略###
(15/18): updates/7/x86_64/primary_db                                         | 3.4 MB  00:00:15     
(16/18): updates/7/x86_64/other_db                                             | 488 kB  00:00:01     
(17/18): updates/7/x86_64/filelists_db                                           | 3.0 MB  00:00:23     
元数据缓存已建立

2.2、web01:修改配置文件(客户端)

1)更改Yum配置文件,将不需要的yum配置文件放入备份文件夹中

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
cd /etc/yum.repos.d/

mkdir bak

ls

 mv *repo* bak/

ls

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@web01 ~]# cd /etc/yum.repos.d/
[root@web01 /etc/yum.repos.d]# mkdir bak
[root@web01 /etc/yum.repos.d]# ls
bak                    CentOS7-Base-163.repo.1  CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo
CentOS7-Base-163.repo  CentOS-Base.repo.backup  CentOS-Debuginfo.repo  CentOS-Media.repo      CentOS-Vault.repo
[root@web01 /etc/yum.repos.d]# mv *repo* bak/
[root@web01 /etc/yum.repos.d]# ls
bak

2)只保留CentOS-Media.repo配置文件

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
mv bak/*M* .
#(注意后面的点)

ls

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@web01 /etc/yum.repos.d]# mv bak/*M* .
[root@web01 /etc/yum.repos.d]# ls
bak  CentOS-Media.repo

3)修改CentOS-Media.repo配置文件

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
vim CentOS-Media.repo
#(需要会使用vim编辑器,若不会,使用下面一种方法)

cat >CentOS-Media.repo <演示如下<==
--------------------------------------------------------------
[root@web01 /etc/yum.repos.d]# cat >CentOS-Media.repo < [c7-media]
> name=CentOS-$releasever - Media
> baseurl=ftp://172.16.1.61/pub
> gpgcheck=0
> enabled=1
> gpgkey=ftp://172.16.1.61/pub/RPM-GPG-KEY-CentOS-7
> EOF
[root@web01 /etc/yum.repos.d]# cat CentOS-Media.repo 
[c7-media]
name=CentOS- - Media
baseurl=ftp://172.16.1.61/pub
gpgcheck=0
enabled=1
gpgkey=ftp://172.16.1.61/pub/RPM-GPG-KEY-CentOS-7

4)测试Yum仓库

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
yum search docker

--------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@web01 /etc/yum.repos.d]# yum search docker
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
================================================================== 匹配:docker ===================================================================
virt-what.x86_64 : Detect if we are running in a virtual machine

至此,内网下Yum仓库搭建配置结束了.

你可能感兴趣的:(内网下Yum仓库搭建配置)