Centos 7建立本地内网源


建立一台YUM源服务器,同步163base源及阿里epel源,通过nginx发布出去,为企业PC提供yum服务。

一、环境

服务端:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# ifconfig|grep inet
        inet 192.168.1.111  netmask 255.255.255.0  broadcast 192.168.1.255

客户端PC:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# ifconfig|grep inet
        inet 192.168.1.107  netmask 255.255.255.0  broadcast 192.168.1.255

二、先配置163base源及阿里epel源

安装yum支持环境

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

备份base源文件

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.bakup}

下载reop文件

163base源
[root@localhost ~]# wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo 
阿里epel源
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

清缓存

[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

查看源列表

[root@localhost ~]# yum repolist

能看到base与epel源ID、name及包数量

三、建立本地仓库localbase、localepel

新建仓库目录localbase、localepel

[root@localhost ~]# mkdir -p /data/localrepo/localbase
[root@localhost ~]# mkdir -p /data/localrepo/localepel

同步base源

[root@localhost ~]# reposync -r base -p /data/localrepo/localbase

同步epel源

[root@localhost ~]# reposync -r epel -p /data/localrepo/localepel

创建仓库repodata目录,每次有新包都得运行此命令加载一次

base
[root@localhost ~]# createrepo /data/localrepo/localbase
Spawning worker 0 with 5035 pkgs
Spawning worker 1 with 5035 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

epel
[root@localhost ~]# createrepo /data/localrepo/localepel/
Spawning worker 0 with 6635 pkgs
Spawning worker 1 with 6634 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

下载base源gpgkey文件(epel gpgkey文件不用下载)

保存至/data/localrepo/localbase/
[root@localhost~]#wget -P /data/localrepo/localbase/ http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

备份base与epel源配置文件

[root@localhost ~]# mv /etc/yum.repos.d/CentOS7-Base-163.repo{,.bakup}
[root@localhost ~]# mv /etc/yum.repos.d/epel.repo{,.bakup}

新建base与epel本地源配置文件

[root@localhost ~]# vim /etc/yum.repos.d/localbase.repo
[base]
name=centos7 local base_163
baseurl=file:///data/localrepo/localbase/
gpgcheck=1
gpgkey=file:///data/localrepo/localbase/RPM-GPG-KEY-CentOS-7

[root@localhost ~]# vim /etc/yum.repos.d/localepel.repo
[epel]
name=centos7 local epel
baseurl=file:///data/localrepo/localepel/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

清缓存

[root@localhost ~]# yum clean all  
[root@localhost ~]# yum makecache

查看仓库列表yum repolist
在这里插入图片描述

四、通过nginx将发布源站

安装nginx

[root@localhost ~]# yum install nginx -y

编译nginx配置文件

[root@localhost ~]# vim /etc/nginx/nginx.conf
42         autoindex on;            #开启目录访问功能
43         root         /data/localrepo;    #路径
[root@localhost ~]# systemctl restart nginx       启动nginx
[root@localhost ~]# systemctl stop firewalld      临时关闭防火墙,也可以开启端口,这里就不说明了
[root@localhost ~]# setenforce 0                 关闭selinux
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled

打开浏览器输入IP即可
在这里插入图片描述
可以看到base与epel源,点击进入,里面也有文件,与163官网类似
在这里插入图片描述

五、客户端使用192.168.1.111的base及epel源

[root@localhost ~]# vim /etc/yum.repos.d/localbase.repo
[base]
name=centos7 local base_163
baseurl=http://192.168.1.111/localbase/
gpgcheck=1
gpgkey=http://192.168.1.111/localbase/RPM-GPG-KEY-CentOS-7

[root@localhost ~]# vim /etc/yum.repos.d/localepel.repo
[epel]
name=centos7 local repo
baseurl=http://192.168.1.111/localepel/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

#也可以使用yum-config-manager来添加

[root@localhost ~]# yum-config-manager --add-repo=http://192.168.1.111/localbase/

将旧的base改名备份

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.bakup}
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                     repo name                                   status
base                        centos7 local base_163                    10,070
epel                        centos7 local repo                          13,269
repolist: 23,339

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

------------------end

原创文章 4 获赞 4 访问量 261

猜你喜欢

转载自blog.csdn.net/oToyix/article/details/106170701