创建本地yum仓库

Posted dinghc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建本地yum仓库相关的知识,希望对你有一定的参考价值。

目前有好几种办法可以用来同步yum仓库,但是都有其弊端,下面是我整理的几种yum仓库创建办法

1.使用rsync从清华源同步(缺点:平台有限制,想同步很难)

#同步c6和c7
rsync -zaP --exclude-from /usr/share/nginx/html/rsync_exclude2.txt rsync://rsync.mirrors.ustc.edu.cn/centos/7.4.1708 /usr/share/nginx/html/centos

rsync -zaP --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/centos/6.9 /usr/share/nginx/html/centos

rsync -zaP --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/

rsync -zaP --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64 /usr/share/nginx/html/epel/6/
#eclude内容
 cat /usr/share/nginx/html/rsync_exclude.txt

centosplus/

cloud/

contrib/

cr/

fasttrack/

isos/

sclo/

storage/

virt/

i386/

debug/

drpms/

centos7

[root@oldboyedu ~]# cat /usr/share/nginx/html/rsync_exclude2.txt

atomic/

centosplus/

cloud/

configmanagement/

cr/

dotnet/

fasttrack/

isos/

nfv/

opstools/

paas/

rt/

sclo/

storage/

virt/

debug/

drpms/

2.使用reposync来同步仓库(操作简单,对网络要求高)

优点非常明显,但是也是有弊端的,一些rpm因为网络延迟或者过大,同步不下来

yum install yum-utils createrepo yum-plugin-priorities -y #安装包 

yum repolist   #查看repoid

reposync base/7/x86_64 -p /data/yum #直接同步你仓库里面有的(比如阿里云的base仓库)


3.自写脚本来实现wget 拉取网上的rpm包

优点:不会遗漏包,更全,可以下载任何网上的任何包

缺点:需要写脚本,一些包下不下来,需要多次运行脚本

简单的脚本

#base源
~ ]# cat base.sh 
#!/bin/bash
curl https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ >os.bak
curl https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/ >extras.bak
curl https://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/ >updates.bak
awk -F‘"‘ /rpm/‘{print $2}‘ os.bak >os
awk -F‘"‘ /rpm/‘{print $2}‘ extras.bak >extras
awk -F‘"‘ /rpm/‘{print $2}‘ updates.bak >updates
for i in `cat os`;
do
        timeout 100 wget  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/$i
        if [ $? -ne 0 ];then
                echo "error https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/$i" >>/mnt/yum.log
                rm -rf /data/yum/base/packages/$i
        fi
done

for i in `cat extras`;
do
        timeout 100 wget  https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/$i                             
        if [ $? -ne 0 ];then
                echo "error https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/$i" >>/mnt/yum.log
                rm -rf /data/yum/base/packages/$i
        fi
done



for i in `cat updates`;
do
        timeout 100 wget  https://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/$i                             
        if [ $? -ne 0 ];then
                echo "error https://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/$i" >>/mnt/yum.log
                rm -rf /data/yum/base/packages/$i
        fi
done

#epel源
~]# cat epel.sh 
#!/bin/bash

for i in {a..z};
do
	curl https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/ > ${i}.txt
	awk -F‘"‘ /rpm/‘{print $2}‘ ${i}.txt >>${i}_rpm
	for y in `cat ${i}_rpm` ;
	do
       timeout 60 wget -O /data/yum/epel/packages/$i https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/$y
	if [ $? -ne 0  ];then
		echo "error https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/$y" >> /var/yum.log
		rm -rf /data/yum/epel/packages/$y
	fi
	sleep 0.1
	done

sleep 2
done
for i in  {0,2,3,4,9};
do
	curl https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/ > ${i}.txt
	awk -F‘"‘ /rpm/‘{print $2}‘ ${i}.txt >>${i}_rpm
	for y in `cat ${i}_rpm` ;
	do
       timeout 60 wget -O /data/yum/epel/packages/$i https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/$y
	if [ $? -ne 0  ];then
		echo "error https://mirrors.aliyun.com/epel/7/x86_64/Packages/$i/$y" >> /var/yum.log
		rm -rf /data/yum/epel/packages/$y
	fi
	sleep 0.1
	done

sleep 2
done
#其他的源只要更换地址即可


创建repodir

createrepo /var/ftp/location/ 

配置nginx,生成本地远程yum源

yum install nginx -y



~]# cat /etc/nginx/conf.d/yum.conf 
server {
        listen 80;
        server_name 10.100.15.30;
        location / {
                root /data/yum;
                autoindex on;
        }
}

systemctl start nginx 

生成yum.repo

~]# cat local.repo 
[BASE]
name = Local Base Repository
baseurl = http://10.100.15.30/base/
enable = 1
gpgcheck = 0

[epel]
name = Local epel Repository
baseurl = http://10.100.15.30/epel/
enable = 1
gpgcheck = 0

[extends]
name = Local extends Repository
baseurl = http://10.100.15.30/extends/
enable = 1
gpgcheck = 0


下面我们就可以执行下面的命令来安装yun源啦(只要是可以访问yum服务器地址的即可)

gzip /etc/yum.repos.d/*.repo && curl -o /etc/yum.repos.d/local.repo http://10.100.15.30/local.repo && yum makecache

以上是关于创建本地yum仓库的主要内容,如果未能解决你的问题,请参考以下文章

创建本地yum源仓库

创建yum本地仓库,将阿里仓库同步到本地,并定时更新

centos 创建本地yum源搭建本地yum仓库 亲测可用

创建本地yum仓库

RHEL关于本地yum仓库的问题

通过ftp创建本地yum仓库