CentOS7.9搭建局域网yum源

一、搭建本地yum源

1、将系统镜像复制到空间较大的目录

[root@localhost ~]# mv CentOS-7.9-x86_64-DVD-2009.iso /home/

2、创建挂载目录并挂载系统镜像

[root@localhost ~]# cd /home

[root@localhost home]# mkdir /mnt/iso

[root@localhost home]# mount -o loop CentOS-7.9-x86_64-DVD-2009.iso /mnt/iso

mount: /dev/loop0 写保护,将以只读方式挂载

[root@localhost home]# ls /mnt/iso

CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL

3、备份原有的yum源信息并修改配置本地yum源信息

[root@localhost home]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# mkdir ./bak

[root@localhost yum.repos.d]# mv ./*.repo ./bak/

[root@localhost yum.repos.d]# cp ./bak/CentOS-Media.repo .

[root@localhost yum.repos.d]# vi CentOS-Media.repo

# CentOS-Media.repo

#  This repo can be used with mounted DVD media, verify the mount point for

#  CentOS-7.  You can use this repo and yum to install items directly off the

#  DVD ISO that we release.

# To use this repo, put in your DVD and use it with the other repos too:

#  yum --enablerepo=c7-media [command]

# or for ONLY the media repo, do this:

#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]

name=CentOS-$releasever - Media

baseurl=file:///media/CentOS/

file:///mnt/iso <--此处修改为镜像挂载路径

file:///media/cdrecorder/

gpgcheck=1

enabled=1 <--此处将0改为1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

4、清理并重新读取yum源信息

[root@localhost yum.repos.d]# yum clean all

已加载插件:fastestmirror, langpacks

正在清理软件源: c7-media

Cleaning up list of fastest mirrors

[root@localhost yum.repos.d]# yum repolist

二、搭建局域网yum源

1、安装Http服务和xml生成工具,由于安装系统时已经顺便安装了相应的安装包,所以此处无须再进行安装。

[root@localhost ~]# yum install -y httpd createrepo

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

* c7-media:

file:///mnt/iso/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/iso/repodata/repomd.xml"

正在尝试其它镜像。

file:///media/cdrecorder/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /media/cdrecorder/repodata/repomd.xml"

正在尝试其它镜像。

file:///media/CentOS/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /media/CentOS/repodata/repomd.xml"

正在尝试其它镜像。

软件包 httpd-2.4.6-95.el7.centos.x86_64 已安装并且是最新版本

软件包 createrepo-0.9.9-28.el7.noarch 已安装并且是最新版本

无须任何处理

2、新建存放yum源文件的目录并将相关文件复制进去

[root@localhost ~]# mkdir -p /home/data/yum.repo/centos/7/os/x86_64/Packages

[root@localhost ~]# mkdir -p /home/data/yum.repo/centos/7/updates/x86_64/Packages

[root@localhost ~]# mkdir -p /home/data/yum.repo/tools/

[root@localhost ~]# cp -R /mnt/iso/Packages/* /home/data/yum.repo/centos/7/os/x86_64/Packages/

[root@localhost ~]# cp -R /mnt/iso/repodata /home/data/yum.repo/centos/7/os/x86_64

[root@localhost ~]# cp -R /mnt/iso/repodata /home/data/yum.repo/centos/7/updates/x86_64

[root@localhost ~]# cp -R /mnt/iso/repodata /home/data/yum.repo/tools

[root@localhost ~]# cp -R /mnt/iso/RPM-GPG-KEY-CentOS-7 /home/data/yum.repo/

3、http服务调整

查看httpd服务状态

[root@localhost home]# service httpd status

Redirecting to /bin/systemctl status httpd.service

● httpd.service - The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)

Active: inactive (dead)

Docs: man:httpd(8)

man:apachectl(8)

删除默认的html文件夹

[root@localhost home]# rm -rf /var/www/html

创建yum源文件目录到网站目录的软链接

[root@localhost home]# ln -s /home/data/yum.repo /var/www/html

启动http服务并查看服务状态

[root@localhost home]# service httpd start

Redirecting to /bin/systemctl start httpd.service

[root@localhost home]# service httpd status

Redirecting to /bin/systemctl status httpd.service

● httpd.service - The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)

Active: active (running) since 五 2022-02-25 11:02:04 CST; 14s ago

Docs: man:httpd(8)

man:apachectl(8)

Main PID: 16291 (httpd)

Status: "Total requests: 0; Current requests/sec: 0; Current traffic:  0 B/sec"

Tasks: 7

CGroup: /system.slice/httpd.service

├─16291 /usr/sbin/httpd -DFOREGROUND

├─16294 /usr/sbin/httpd -DFOREGROUND

├─16295 /usr/sbin/httpd -DFOREGROUND

├─16296 /usr/sbin/httpd -DFOREGROUND

├─16297 /usr/sbin/httpd -DFOREGROUND

├─16298 /usr/sbin/httpd -DFOREGROUND

└─16299 /usr/sbin/httpd -DFOREGROUND

2月 25 11:02:04 localhost.localdomain systemd[1]: Starting The Apache HTTP S...

2月 25 11:02:04 localhost.localdomain httpd[16291]: AH00558: httpd: Could no...

2月 25 11:02:04 localhost.localdomain systemd[1]: Started The Apache HTTP Se...

Hint: Some lines were ellipsized, use -l to show in full.

发现网页端无法打开,将网站端口添加到防火墙规则里并重启防火墙

[root@localhost home]# firewall-cmd --add-port=80/tcp --permanent

success

[root@localhost home]# systemctl restart firewalld.service

[root@localhost home]# firewall-cmd --list-all

public (active)

target: default

icmp-block-inversion: no

interfaces: eno1

sources:

services: dhcpv6-client ssh

ports: 5901-5905/tcp 80/tcp

protocols:

masquerade: no

forward-ports:

source-ports:

icmp-blocks:

rich rules:

设置http服务开机启动

[root@localhost ~]# systemctl enable httpd

4、配置客户端yum源配置

[root@localhost home]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# cp ./bak/CentOS-Base.repo .

[root@localhost yum.repos.d]# vi CentOS-Base.repo

# CentOS-Base.repo

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

[base]

name=CentOS-$releasever - Base

baseurl=http://10.2.192.111/centos/$releasever/os/$basearch/

gpgcheck=1

enabled=1

gpgkey=http://RPM-GPG-KEY-CentOS-7

#released updates

[updates]

name=CentOS-$releasever - Updates

baseurl=http://10.2.192.111/centos/$releasever/updates/$basearch/

gpgcheck=1

enabled=1

gpgkey=http://10.2.192.111/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

baseurl=http://10.2.192.111/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://10.2.192.111/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

baseurl=http://10.2.192.111/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://10.2.192.111/RPM-GPG-KEY-CentOS-7

[root@localhost yum.repos.d]# vi CentOS-Tools.repo

[base]

name=CentOS-$releasever - Base

baseurl=http://10.2.192.111/tools/

gpgcheck=0

enabled=1

你可能感兴趣的:(CentOS7.9搭建局域网yum源)