CentOS7同步远程yum源到本地

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7同步远程yum源到本地相关的知识,希望对你有一定的参考价值。

应用场景:

今天有朋友问我,说他搭建cloudstack测试环境,但是安装包不太好下,要一个个手动去wget,我就问他,几个包可以这么做,要很多包咋办,其实我们在同步远程一些安装包的时候,通常会用到reposync这个命令,本篇文章也是通过这条命令来下载cloudstack安装包:


1、配置selinux为disabled

[[email protected] ~]# cat /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted


2、配置yum的repo文件

[[email protected] ~]# yum -y createrepo yum-utils
[[email protected] ~]# cat /etc/yum.repos.d/cloudstack.repo 
[cloudstack]
name=cloudstack
baseurl=http://mirrors.cloudstack-china.com/mirror/centos7/4.9
gpgcheck=0
enable=1


3、同步cloudstack镜像

[[email protected] ~]# mkdir -p /mnt/yum
[[email protected] ~]# cd /mnt/yum
[[email protected] ~]# yum repolist
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
repo id                                                                                               repo name                                                                                             status
cloudstack                                                                                            cloudstack                                                                                            6
repolist: 6
[[email protected] yum]# reposync -r cloudstack
cloudstack-agent-4.9.0-1.el7.centos.x86_64.rpm                                                                                                                                             |  69 MB  00:01:21     
cloudstack-baremetal-agent-4.9.0-1.el7.centos.x86_64.rpm                                                                                                                                   | 5.2 kB  00:00:00     
cloudstack-cli-4.9.0-1.el7.centos.x86_64.rpm                                                                                                                                               |  37 kB  00:00:00     
cloudstack-common-4.9.0-1.el7.centos.x86_64.rpm                                                                                                                                            |  76 MB  00:00:44     
cloudstack-management-4.9.0-1.el7.centos.x86_64.rpm                                                                                                                                        | 101 MB  00:01:29     
cloudstack-usage-4.9.0-1.el7.centos.x86_64.rpm  
说明:reposync -r cloudstack,cloudstack是repo id                                                                                                                                           |  64 MB  00:16:57  
[[email protected] yum]# du -sh cloudstack
311Mcloudstack

4、如何添加下载的包到yum源

[[email protected] ~]# cd /mnt/yum/
[[email protected] yum]# createrepo cloudstack
Spawning worker 0 with 2 pkgs
Spawning worker 1 with 2 pkgs
Spawning worker 2 with 1 pkgs
Spawning worker 3 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] cloudstack]# ls
cloudstack-agent-4.9.0-1.el7.centos.x86_64.rpm            cloudstack-cli-4.9.0-1.el7.centos.x86_64.rpm     cloudstack-management-4.9.0-1.el7.centos.x86_64.rpm  repodata
cloudstack-baremetal-agent-4.9.0-1.el7.centos.x86_64.rpm  cloudstack-common-4.9.0-1.el7.centos.x86_64.rpm  cloudstack-usage-4.9.0-1.el7.centos.x86_64.rpm
说明:从上面的输出可以知道,生成了一个repodata的文件夹。
[[email protected] cloudstack]# yum clean all
Loaded plugins: fastestmirror, priorities
Cleaning repos: cloudstack
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[[email protected] cloudstack]# yum makecache
Loaded plugins: fastestmirror, priorities
cloudstack                                                                                                                                                                                 | 2.9 kB  00:00:00     
(1/3): cloudstack/filelists_db                                                                                                                                                             |  12 kB  00:00:00     
(2/3): cloudstack/other_db                                                                                                                                                                 | 1.7 kB  00:00:00     
(3/3): cloudstack/primary_db                                                                                                                                                               |  10 kB  00:00:00     
Determining fastest mirrors
Metadata Cache Created
[[email protected] cloudstack]# yum -y install cloudstack-management

到此,安装配置完成

以上是关于CentOS7同步远程yum源到本地的主要内容,如果未能解决你的问题,请参考以下文章

Centos7更改yum源和epel源到阿里云

CentOS7搭建本地YUM仓库,并定期同步阿里云源

添加yum源

ubuntu apt-mirror 同步源到本地

rsync+inotify实时数据同步

Linux系统部署YUM远程仓库及NFS共享服务