制作离线的YUM源

hostname

ip

yum

192.168.41.137

ha1

192.168.41.138

1,准备基础源,准备docker 源,epel源和docker源

base

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 

docekr-ce


[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

epel-release

[root@yum yum.repos.d]# cat epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

2,yum服务器安装所需软件包

yum -y install createrepo yum-utils httpd reposync

3,同步软件包到本地

mkdir -p /var/www/html/yumrepos

reposync -p /var/www/html/yumrepos/ #这是下载所有yum中的包到本地,时间很长且占网络。

 reposync -n --repoid=base --repoid=updates -p /var/www/html/yumrepos/  #建议直接指定名称同步

4,使用createrepo 命令生成本地索引文件


## 4,使用createrepo 命令生成本地索引文件

[root@yum yumrepos]# cd base/
[root@yum base]# createrepo  .
Spawning worker 0 with 2518 pkgs
Spawning worker 1 with 2518 pkgs
Spawning worker 2 with 2518 pkgs
Spawning worker 3 with 2518 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

5,可以定期更新,命令如下

5.1 同步远端仓库

reposync -n --repoid=base -p /var/www/html/yumrepos/

5.2 从新生成索引文件

cd /var/www/html/yumrepos/base

createrepo --update . #这里的. 表示当前目录,,可直接使用createrepo --update /var/www/html/yumrepos/base

6,其他使用当前yum 源。自己的仓库地址。

[base]

name=centos-$releasever-base

baseurl=http://192.168.41.137/yumrepos/base/

gpgcheck=0

enabled=1

[epel]

name=centos-$releasever-epel

baseurl=http://192.168.41.137/yumrepos/epel/

gpgcheck=0

enabled=1

7,测试一下

[root@ha1 yum.repos.d]# yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                           repo name                                                     status
base                                              CentOS-7 - Base                                               10,072
docker-ce                                         CentOS-7 - docker-ce                                             263
epel                                              CentOS-7 - epel                                               13,767
repolist: 24,102
文章作者: emporer
本文链接:
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Emporer-Linux
linux linux-服务
喜欢就支持一下吧