CentOS 7 如何搭建本地局域网私有仓库?

1.服务端进行yum仓库的搭建准备工作:关闭防火墙、selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0(修改配置文件/etc/selinux/config 里的SELINUX=disabled)
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
2.使用什么传输方式协议提供仓库ftp或http
#方法1:
yum -y install httpd
systemctl start httpd
#方法2:
mkdir /var/www/html -p
cd /var/www/html
#模拟一个http服务
python -m SimpleHTTPServer 80 &>/dev/null &
3.安装ftp传输工具
yum install vsftpd -y
systemctl start vsftpd
netstat -lntup|grep vsftpd
#浏览器测试
ftp://10.0.0.128/
4.开启yum缓存功能
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
grep keepcache /etc/yum.conf
keepcache=1
yum clean all
5.创建yum仓库本地目录,并创建元数据以及拷贝rpm软件包
mkdir /var/ftp/centos7 -p
yum -y install createrepo
createrepo /var/ftp/centos7/
#拷贝rpm包
mount /dev/cdrom /mnt
cp -rp /mnt/Packages/*.rpm /var/ftp/centos7/
#安装ftp客户端工具
yum install lftp -y
lftp 10.0.0.128
1)去其他网站,找到rpm包放这里
2)源码==编译rpm包,放这里

find /var/cache/yum/ -name "sl-*"
find /var/cache/yum/ -name "sl-*" -exec mv {} /var/ftp/centos7/ \;
ll /var/ftp/centos7/sl-*
createrepo --update /var/ftp/centos7/ #这个目录下有更新,就要执行
6.客户端配置yum源指向服务端
gzip /etc/yum.repos.d/*
cat >> /etc/yum.repos.d/centos7.repo <<EOF
[centos7]
name=centos7_base
baseurl=ftp://10.0.0.128/centos7
enabled=1
gpgcheck=0
EOF
7.测试
yum makecache
yum -y install sl

同步官方源到私有源

方法1:
rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/ /var/ftp/centos7/
#更新epel
rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/ /var/ftp/centos7/
#更新索引
createrepo --update /var/ftp/centos7/
方法2:
yum -y install yum-utils createrepo
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
reposync -r base -p /var/ftp/centos7/
#更新epel
reposync -r epel -p /var/ftp/centos7/   #-r 后面代表[仓库名称]
#更新索引
createrepo --update /var/ftp/centos7/
yum clean all && yum makecache
可以编写脚本,通过定时任务来定时更新