用rsync同步公網centos yum源做本地yum原始伺服器

來源:互聯網
上載者:User

標籤:rsync   yum   centos   

用rsync同步公網centos yum源做本地yum原始伺服器


1,安裝httpd,rsync,vsftpd

yum -y install httpd rsync vsftpd


mkdir /var/www/html/centos


#由於vsftpd不支援軟串連改變目錄,所以下面操作效果一樣

mount --bind /var/www/html/centos /var/ftp/pub


chkconfig httpd on

chkconfig vsftpd on

service httpd start

service vsftpd start


2,rsync同步指令碼如下

#!/bin/bash

# base value

# 要同步的源

YUM_SITE="rsync://mirrors.kernel.org/centos/"

# 本地存放目錄

LOCAL_PATH="/u01/mirrors/centos/"

# 需要同步的版本,我只需要5和6還有7版本的總共大概120G左右,去掉iso後會少點

LOCAL_VER="5 5* 6 6* 7 7*"

# 同步時要限制的頻寬

BW_limit=512

# 記錄本指令碼進程號

LOCK_FILE="/var/log/yum_server.pid"

# 如用系統預設rsync工具為空白即可。

# 如用自己安裝的rsync工具直接填寫完整路徑

RSYNC_PATH=""

 

# 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

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

    # sync yum source

    echo "Start sync $LOCAL_PATH$VER"

    $RSYNC_PATH -avrtH --delete --bwlimit=$BW_limit --exclude "isos" $YUM_SITE$VER $LOCAL_PATH

done

 

# clean lock file

`/bin/rm -rf $LOCK_FILE`

 

echo ‘sync end.‘

exit 1


3,計劃任務

每天淩晨更新

23 59 * * *  /root/yumrsync


4,用戶端配置

編輯/etc/yum.repos.d/CentOS-Base.repo

find /etc/yum.repos.d/  -type f  -name "*.repo"  -exec cp {} {}.bak \;

find /etc/yum.repos.d/  -name "*.repo" | xargs sed -i ‘s/#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/192.168.0.100/g‘

可用上面命令修改,得到結果如下:


#base

[base]

name=CentOS-$releasever – Base

baseurl=http://192.168.0.100/centos/$releasever/os/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


#released updates

[updates]

name=CentOS-$releasever – Updates

baseurl=http://192.168.0.100/centos/$releasever/updates/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


#additional packages that may be useful

[extras]

name=CentOS-$releasever – Extras

baseurl=http://192.168.0.100/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

baseurl=http://192.168.0.100/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

baseurl=http://192.168.0.100/centos/$releasever/contrib/$basearch/

gpgcheck=1

enabled=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


本文出自 “jerrymin” 部落格,請務必保留此出處http://jerrymin.blog.51cto.com/3002256/1537141

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.