7 月 012015
 

同步系统源的脚本。

参考url:http://www.nowo.com/create_private_yum_repo/

推荐使用科大的源

同步脚本在后面,

1:同步源到本地机器

2:安装软件

yum install createrepo
yum install http

3:创建私有源

在 web 目录下创建相应的路径,并且将 rpm 包置入其中,并创建源的 rpm 包索引信息。需要注意的是,每次增加新的 rpm 包,都需要使用 createrepo 命令来更新一次索引信息。

mkdir -p centos/6/x86_64

cp ~/*.rpm centos/6/x86_64/

createrepo -p -d -o centos/6/x86_64 centos/6/x86_64

从科大copy过来的很多索引信息都有了,直接可以用,如果以后没有这个,或者自建的话 就需要创建索引信息。

4:设置客户端

 

[root@localhost 6]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever – Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever – Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

 

然后就享受内网的更新,速度与激情吧!!!

 

同步脚本如下:

 

[root@localhost 6]# cat /root/shell/rsync.sh
#!/bin/bash

# base value
# 要同步的源
YUM_SITE=”rsync://mirrors.ustc.edu.cn/centos/”
YUM_SITE2=”rsync://mirrors.ustc.edu.cn/epel/”
# 本地存放目录
LOCAL_PATH=”/home/share/yum/centos/”
LOCAL_PATH2=”/home/share/yum/epel/”
# 需要同步的版本,我只需要5和6版本还有7的,总共在120G左右,不包括iso会少点
LOCAL_VER=”5 5* 6 6*”
# 同步时要限制的带宽
BW_limit=20480
# 记录本脚本进程号
LOCK_FILE=”/var/log/yum_server.pid”
# 同步日志文件
LogFile=/root/rsyumlog/`date +”%Y-%m-%d”`.log
# 如用系统默认rsync工具为空即可。
# 如用自己安装的rsync工具直接填写完整路径
RSYNC_PATH=”/usr/bin/rsync”
# check update yum server  pid
MY_PID=$$
if [ -f $LOCK_FILE ]; then
    get_pid=`/bin/cat $LOCK_FILE`
    get_system_pid=`/bin/ps -ef|grep -v grep|grep $get_pid|wc -l`
    if [ $get_system_pid -eq 0 ] ; then
        echo $MY_PID>$LOCK_FILE
    else
        echo “Have update yum server now!”
        exit 1
    fi
else
    echo $MY_PID>$LOCK_FILE
fi
# check rsync tool
if [ -z $RSYNC_PATH ]; then
    RSYNC_PATH=`/usr/bin/whereis rsync|awk ‘ ”{print $2}’`
    if [ -z $RSYNC_PATH ]; then
        echo ‘Not find rsync tool.’
        echo ‘use comm: yum install -y rsync’
    fi
fi
# sync yum source
echo “rsync start at $(date +”%Y-%m-%d %H:%M:%S”)” >$LogFile
echo “————————————————–” >>$LogFile
for VER in $LOCAL_VER;
do
    # Check whether there are local directory
    if [ ! -d “$LOCAL_PATH$VER” ] ; then
        echo “Create dir $LOCAL_PATH$VER”
        `/bin/mkdir -p $LOCAL_PATH$VER`
    fi
  if [ ! -d “$LOCAL_PATH2$VER” ] ; then
        echo “Create dir $LOCAL_PATH2$VER”
        `/bin/mkdir -p $LOCAL_PATH2$VER`
    fi
    # sync yum source
     echo “Start sync $LOCAL_PATH$VER”  >>$LogFile
     echo “————————————————–” >>$LogFile
    $RSYNC_PATH -avrtH –exclude-from=/root/shell/exclude.list –delete –bwlimit=$BW_limit  $YUM_SITE$VER $LOCAL_PATH  >>$LogFile
    $RSYNC_PATH -avrtH –exclude-from=/root/shell/exclude.list –delete –bwlimit=$BW_limit  $YUM_SITE2$VER $LOCAL_PATH2  >>$LogFile
done
echo “rsync end at $(date +”%Y-%m-%d %H:%M:%S”)” >>$LogFile
echo “————————————————–” >>$LogFile
done
# clean lock file
`/bin/rm -rf $LOCK_FILE`
echo ‘sync end.’
exit 1

 

#########

后续添加gitlab-ce的私有源的做法

同步脚本:

[root@localhost el]# cat /root/shell/get_gitlab.sh
version=$(yum provides gitlab-ce | tail -n 10 | grep omnibus | awk ‘{print $1}’)
version_old=$(cat /root/shell/old.txt)
if [ $version != $version_old ]
then
cd /home/share/yum/gitlab-ce/el/6/x86_64

wget -O $version.rpm https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/$version.rpm/download
echo $version > /root/shell/old.txt
createrepo -p -d ./
fi

源的写法:

[root@imooc yum.repos.d]# cat gitlab_gitlab-ce.repo
[gitlab_gitlab-ce]
name=gitlab_gitlab-ce
baseurl=http://192.168.9.171:10086/yum/gitlab-ce/el/6/$basearch

repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

红色字体必须添加,否则会验证无法安装,类似校验是否官网的rpm包。

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny