内网下Yum仓库搭建配置

1、实验环境

2、实验步骤

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

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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
###省略###
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
mkdir -p /var/ftp/pub/Packages --------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@m01 /mnt]# mkdir -p /var/ftp/pub/Packages
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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
###省略###
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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.
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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 完毕!
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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:修改配置文件(客户端)

--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
mv bak/*M* .
#(注意后面的点) ls --------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@web01 /etc/yum.repos.d]# mv bak/*M* .
[root@web01 /etc/yum.repos.d]# ls
bak CentOS-Media.repo
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
vim CentOS-Media.repo
#(需要会使用vim编辑器,若不会,使用下面一种方法) cat >CentOS-Media.repo <<EOF
[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 cat CentOS-Media.repo --------------------------------------------------------------
==>演示如下<==
--------------------------------------------------------------
[root@web01 /etc/yum.repos.d]# cat >CentOS-Media.repo <<EOF
> [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
--------------------------------------------------------------
==>命令如下<==
--------------------------------------------------------------
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
04-04 17:26