如何同步openstack RDO源至本地进行离线安装

同步本地源可以采用两种方法:
1.rsync
2.reposync


第一种方案参考如下段程序:
#!/bin/bash
#Script name:rsync_yumrepo.sh
RsyncBin="/usr/bin/rsync"
RsyncPerm='-avrt --delete --no-iconv --bwlimit=1000'


Centos_7_epel='/data/yum_repo/Centos-7/epel/'


LogFile='/data/yum_repo/rsync_yum_log'
Date=`date +%Y-%m-%d`
#check
function check {
if [ $? -eq 0 ];then
    echo -e "\033[1;32mRsync is success!\033[0m" >>$LogFile/$Date.log
else
    echo -e "\033[1;31mRsync is fail!\033[0m" >>$LogFile/$Date.log
fi
}
if [ ! -d "$LogFile" ];then
    mkdir $LogFile
fi
#rsync centos 5 base
#echo 'Now start to rsync centos 5 base!' >>$LogFile/$Date.log
#$RsyncBin $RsyncPerm rsync://mirrors.yun-idc.com/centos/5/os/ $Centos_5_base >>$LogFile/$Date.log
#check
#rsync centos 5 epel
echo 'Now start to rsync centos 5 epel!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm --exclude=SRPMS/ --exclude=ppc64/ rsync://dl.fedoraproject.org/pub/epel/7/x86_64 $Centos_7_epel >>$LogFile/$Date.log
check




语法为:rsync  [option] resource destination


rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.


rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.


Usage: rsync [OPTION]... SRC [SRC]... DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]
  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]
  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name.


rsync将会把resource中的RPM包下载到指定的目录中。




2.reposync
reposync比价简单,其简单用法为rsync -repoid repository-id


可以用yum repolist查看repo的ID
yum repolist 
[root@kilo openstack-common]# yum repolist
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                         repo name                                                                                         status
centos-iso                                                      CentOS-ISO                                                                                        3576
epel                                                            Extra Packages for Enterprise Linux 7 - x86_64                                                    8327
epel-debuginfo                                                  Extra Packages for Enterprise Linux 7 - x86_64 - Debug                                            1919
openstack-kilo                                                  OpenStack Kilo Repository                                                                          280
openstack-kilo-common                                           openstack kilo common                                                                              493
repolist: 14595


如上,同步epel到本地当前目录:
reposync -repoid=epel


reposync的前提是先在系统里面安装repository库,然后到远程repository去下载rpm包。例如可以先安装rdo的openstack-kilo库:
yum insatll  http://rdo.fedorapeople.org/openstack-kilo/rdo-release-kilo.rpm
安装完成之后将会在/etc/yum.repos.d目录下生成openstack-kilo.repo的文件,此时即可yum repolist 查看到。




3.制作本地yum源


简单创建repository的命令如下:
createrepo -update --baseurl=packages_dir packages_dir #packages_dir是包含所有rpm包的绝对路径


此命令将会把package_dir目录下的包生成repository,在该目录下会生成repodata子目录,然后在/etc/yum.repos.d目录下编辑.repo文件
[openstack-kilo]
name=OpenStack Kilo Repository
#baseurl=http://repos.fedorapeople.org/repos/openstack/openstack-kilo/el7/
baseurl=file:///data/yum_repo/rdo-openstack-kilo/openstack-kilo
skip_if_unavailable=0
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RDO-kilo


然后刷新:yum clean all;yum makecache即可。

你可能感兴趣的:(云计算&python,云计算&openstack,Linux)