建立本地yum源

使用环境
  • 服务器处于内网,需要更新
  • 网络资源紧张,节约带宽
建立yum目录
mkdir -p /opt/www/yum/{repo,script}
rsync服务器列表
同步脚本

/opt/www/yum/script/centos_sync.sh

#!/bin/bash
repo_root='/opt/www/yum/centos/'
sync_cmd='rsync -arv --delete --delete-excluded'
sync_srv='rsync://ftp.riken.jp/centos/'

[ -d $repo_root ] && mkdir -p $repo_root 
$sync_cmd --exclude 'isos/' --exclude 'i386/' --exclude 'drpms/' --exclude '[23457]*/' $sync_srv $repo_root &

/opt/www/yum/script/epel_sync.sh

#!/bin/bash
repo_root='/opt/www/yum/epel/'
sync_cmd='rsync -arv --delete --delete-excluded'
sync_srv='rsync://mirrors.ustc.edu.cn/fedora-epel/'

[ -d $repo_root ] && mkdir -p $repo_root 
$sync_cmd --exclude 'SRPMS/' --exclude 'i386/' --exclude 'ppc64/' --exclude 'testing/' --exclude '[457]*/' $sync_srv $repo_root &

/opt/www/yum/script/rpmforge_sync.sh

#!/bin/bash
repo_root='/opt/www/yum/rpmforge/'
sync_cmd='rsync -arv --delete --delete-excluded'
sync_srv='rsync://ftp.riken.jp/repoforge/redhat/'

[ -d $repo_root ] && mkdir -p $repo_root 
$sync_cmd --exclude 'i386/' --exclude 'ppc/' --exclude='source/' --exclude 'testing/' --exclude 'el[23457]*/' $sync_srv $repo_root &
计划任务

/etc/cron.d/sync-yum-repo

0 1 * * * root /bin/sh /opt/www/yum/script/centos_sync.sh
0 2 * * * root /bin/sh /opt/www/yum/script/epel_sync.sh
0 3 * * * root /bin/sh /opt/www/yum/script/rpmforge_sync.sh
repo文件

/opt/www/yum/repo/centos.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://yum.localhost.com/centos/$releasever/os/$basearch
gpgcheck=0
priority=1
 
[updates]
name=CentOS-$releasever - Updates
baseurl=http://yum.localhost.com/centos/$releasever/updates/$basearch/
gpgcheck=0
priority=1
 
[extras]
name=CentOS-$releasever - Extras
baseurl=http://yum.localhost.com/centos/$releasever/extras/$basearch/
gpgcheck=0
priority=1
 
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://yum.localhost.com/centos/$releasever/centosplus/$basearch/
gpgcheck=0
enabled=0
priority=2
 
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://yum.localhost.com/centos/$releasever/contrib/$basearch/
gpgcheck=0
enabled=0
priority=2

/opt/www/yum/repo/epel.repo

[epel]
name=Extra Packages for Enterprise Linux $releaserver - $basearch
baseurl=http://yum.localhost.com/epel/$releasever/$basearch/
gpgcheck=0
priority=21

/opt/www/yum/repo/rpmforge.repo

[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://yum.localhost.com/rpmforge/el$releasever/en/$basearch/rpmforge
gpgcheck = 0
priority=22

[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = http://yum.localhost.com/rpmforge/el$releasever/en/$basearch/extras
gpgcheck = 0
priority=22
自定义源
yum install createrepo
mkdir -p /opt/www/yum/custom/x86_64
copy *rpm /opt/www/yum/custom/x86_64
createrepo -p -d --update /opt/www/yum/custom/x86_64
nginx服务配置

/etc/nginx/conf.d/yum.conf

server {
    listen	80;
    server_name	yum.localhost.com;

    allow 10.0.1.0/24;
    deny all;

    charset utf-8;

    access_log  /var/log/nginx/$server_name.access.log  main;

    location / {
        root   /opt/www/yum;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

你可能感兴趣的:(yum)