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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章