zoukankan      html  css  js  c++  java
  • 创建本地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 -r base -p /data/yum #直接同步你仓库里面有的(比如阿里云的base仓库) 
    #-r  --repoid=repoid 
    事例:需要同步zabbix/x86_64 reposync -r zabbix -p /data/ 
    #注意:/后面的repoid可以省略
    
    

    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
    
    
  • 相关阅读:
    vue-webpack介绍
    vue-ES6模块化的导入和导出
    vue-前端模块化
    vue-插槽作用域的使用
    vue-具名插槽的使用
    vue-插槽的基本使用
    vue-父组件获取子组件对象实例
    IO(六)
    IO(五)
    关于overflow:hidden
  • 原文地址:https://www.cnblogs.com/dinghc/p/13161825.html
Copyright © 2011-2022 走看看