#私藏项目实操分享# 自建yum仓库,分别为网络源和本地源

出于安全起见,有些企业内部服务器使用本地局域网而不连接外网,为了安装一些服务,就需要搭建本地的yum仓库;
在系统安装盘内,已经自带了大量必要linux是什么操作系统的安装包,可以用做本地yum仓库的源;
星门老鹰为yum仓库服务器的主机配置:
先把原来系统相关的配置centos7配置ip地址文件归置存放


[root@mini71 <sub>]#mkdir /etc/yum.repos.d/bak
[root@mini71 </sub>]#mv /etc/yum.repos.d/* /etc/yum.repos.d/bak/

然后编辑以光盘路径为yum源的配置文件

[root@mini71 ~]#cat /etc/yum.repos.d/base.repo 
[base]
name=cdrom
baseurl=file:///mnt/cdrom/
gpgcheck=0

配置epel源(作为扩展,可以不配置)

[root@mini71 ~]#cat /etc/yum.repos.d/epel.repo 
[aliyun.epel]
name=aliyun epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/(这里选择里阿里云的epel源,也可以选择其他的)
gpgcheck=0
enabled=1(通过修改此项为0,即可关闭epel源)

安装http服务,启动,并开机启动

[root@mini71 <sub>]#yum install httpd
[root@mini71 </sub>]#systemctl start httpd
[root@mini71 ~]#systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

将光盘挂载至h本地yum源ttpd路径下

[root@mini71 <sub>]#mkdir -p /var/www/html/centos/7/os/x86_64
[root@mini71 </sub>]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@mini71 ~]#ls /var/www/html/centos/7/os/x86_64/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL

清理yum缓存,linux是什么操作系统再查看yum源列表,出现本地源列表和epel源列表

[root@mini71 <sub>]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: aliyun.epel base
Cleaning up list of fastest mirrors
Other repos take up 48 M of disk space (use --verbose for details)
[root@mini71 </sub>]#yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
aliyun.epel | 4.7 kB 00:00:00
base | 3.6 kB 00:00:00
(1/5): aliyun.epel/group_gz | 95 kB 00:00:01
(2/5): base/group_gz | 166 kB 00:00:00
(3/5): aliyun.epel/updateinfo | 1.0 MB 00:00:01
(4/5): base/primary_db | 3.1 MB 00:00:00
(5/5): aliyun.epel/primary_db | 6.7 MB 00:00:03
repo id repo name status
aliyun.epel aliyun epel 13,217
base cdrom 4,021
repolist: 17,238

在浏览linux操作系统基础知识器输入网址,看到光盘内容即表示可以访问

配置其他主机
开启另外一台虚拟机,配置LAN区段内网,不启动外网和光盘


                                            #私藏项目实操分享# 自建yum仓库,分别为网络源和本地源

此时查看yum源列表没有任何可供安装的包

[root@mini73 ~]#yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
repo id repo name status
base cdrom 0
repolist: 0

配置以yum仓库路径的源

[root@mini73 ~]#cat /etc/yum.repos.d/base.repo
[base]
name=cdrom
baseurl=http://192.168.36.71/centos/7/os/x86_64/
gpgcheck=0

刷新yum源,出现可供喜马拉雅听书免费版官方下载安装的包列表

[root@mini73 ~]#yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
(1/2): base/group_gz | 166 kB 00:00:00
(2/2): base/primary_db | 3.1 MB 00:00:00
repo id repo name status
base cdrom 4,021
repolist: 4,021

测试安装服务,表示安装正常

[root@mini73 ~]#yum install httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
.
.
.
Installed:
httpd.x86_64 0:2.4.6-88.el7.centos

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7

Complete!