搭建本地源

搭建本地yum源:以下是以centos7为例子 


1)首先需要安装 createrepo(需要一个可以使用源的机器,可以访问互联网)
安装方法可以使用yum
安装epel源

1 yum -y install epel-release
2 yum clean all && yum makecache fast

安装 createrepo

 https://files.cnblogs.com/files/gaoguangjun/createrepo.tar

1 yum install -y createrepo

一般包含以下rpm包: (会附带)
createrepo-0.9.9-28.el7.noarch.rpm   
deltarpm-3.6-3.el7.x86_64.rpm             
libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
python-deltarpm-3.6-3.el7.x86_64.rpm

现在就可以创建自己的源了!!!

2) 我们需要一个目录(存放yum源的文件的rpm信息等)以 test_repo (/home/admin/test_repo/)为例:

1 mkdir test_repo

3)把 文件夹变成源

1 creatrepo test_repo

4) 接下来就可以自由的存放自己的rpm文件了
5)写自己的repo文件,放到 /etc/yum.repos.d/即可

cat test_repo.repo

1 [test_repo]
2 name=test_repo
3 baseurl=file:///home/admin/test_repo/
4 gpgcheck=0

脚本:

 1 #!/bin/bash
 2 cd /data/
 3 
 4 yum install createrepo
 5 read -p "请输入源名称:" REPO_NAME
 6 #创建目录
 7 mkdir $REPO_NAME
 8 #创建源
 9 creatrepo $REPO_NAME
10 
11 cat << EOF >> $REPO_NAME.repo
12 [${REPO_NAME}]
13 name=${REPO_NAME}
14 baseurl=file:///data/${REPO_NAME}/
15 gpgcheck=0
16 EOF
原文地址:https://www.cnblogs.com/gaoguangjun/p/10401412.html