自建yum仓库(网络源和本地源)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自建yum仓库(网络源和本地源)相关的知识,希望对你有一定的参考价值。
YUM:Yellowdog Update Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具
yum repository:yum repo,存储了众多rpm包,以及包的相关的元数据文件,放置在特定的目录repodata下
yum客户端配置文件:
- /etc/yum.conf:为所有仓库提供公共配置
[root@Centos7 yum.repos.d]# cd [root@Centos7 ~]# grep -Ev ‘^#|^$‘ /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release
- /etc/yum.repos.d/*.repo:为仓库的指向提供配置
[repositoryID] name=Some name for this repository baseurl=url://path/to/repository enabled={1|0} gpgcheck={1|0} gpgkey=URL enablegroups={1|0} failovermethod={roundrobin|priority} roundrobin:意为随机挑选,默认值 priority:按顺序访问 cost= 默认为1000
- yum的repo配置文件中可用的变量:
$releasever:当前OS的发行版的主版本号
$arch:平台,如:i386,i486,i586,x86_64等
$basearch:基础平台;i386,x86_64
$YUM0-$YUM9:自定义变量
配置本地yum源
1、确保vmware里相应的虚拟机的光盘已经挂在了相应版本的系统光盘(以当前实验环境Centos7为例)
[root@Centos7 ~]# uname -r
3.10.0-693.el7.x86_64
2、确保centos7已挂载
[root@Centos7 ~]# df -Th /mnt
Filesystem Type Size Used Avail Use% Mounted on
/dev/sr0 iso9660 8.1G 8.1G 0 100% /mnt
3、配置本地源
#新装的系统里,在/etc/yum.repos.d目录下会生成很多yum源,都是国外的,本则不胡乱删文件的理念,把这些.repo源文件都移动到新建的Centos目录下
[root@Centos7 ~]# mkdir /etc/yum.repos.d/Centos
[root@Centos7 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/Centos/
[root@Centos7 ~]# cd /etc/yum.repos.d/
[root@Centos7 yum.repos.d]# ls
Centos
[root@Centos7 yum.repos.d]# cat > local.repo <<EOF
> [base]
> name=local repo
> baseurl=file:///mnt
> enabled=1
> gpgcheck=0
> EOF
[root@Centos7 yum.repos.d]# cat local.repo
[base]
name=local repo
baseurl=file:///mnt
enabled=1
gpgcheck=0
4、本地源已完成,使用yum repolist罗列出配置的仓库的软件包
[root@Centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
(1/2): base/group_gz | 156 kB 00:00:00
(2/2): base/primary_db | 5.7 MB 00:00:00
Loading mirror speeds from cached hostfile
repo id repo name status
base local repo 9,591
repolist: 9,591
配置网络源,经常使用的EPEL源(以阿里云为例)
[root@Centos7 yum.repos.d]# cat > epel.repo <<EOF
> [epel]
> name=aliyun epel
> baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
> enabled=1
> gpgcheck=0
> EOF
[root@Centos7 yum.repos.d]# cat epel.repo
[epel]
name=aliyun epel
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
[root@Centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
epel | 4.7 kB 00:00:00
(1/3): epel/group_gz | 95 kB 00:00:00
(2/3): epel/updateinfo | 1.0 MB 00:00:00
(3/3): epel/primary_db | 6.8 MB 00:00:00
Loading mirror speeds from cached hostfile
repo id repo name status
base local repo 9,591
epel aliyun epel 13,382
repolist: 22,973
技巧:
1、在配置阿里云的epel源的时候可以使用变量的方式,如下:
#通过变量的使用,如此更具备通用性
[root@Centos7 yum.repos.d]# vim epel.repo
[root@Centos7 yum.repos.d]# cat epel.repo
[epel]
name=aliyun epel
#baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
enabled=1
gpgcheck=0
[root@Centos7 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel
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
[root@Centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
(1/5): base/group_gz | 156 kB 00:00:00
(2/5): base/primary_db | 5.7 MB 00:00:00
(3/5): epel/7/x86_64/group_gz | 95 kB 00:00:00
(4/5): epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
(5/5): epel/7/x86_64/primary_db | 6.8 MB 00:00:00
Determining fastest mirrors
repo id repo name status
base local repo 9,591
epel/7/x86_64 aliyun epel 13,382
repolist: 22,973
2、定制别名,启动epel源
在配置epel源的时候有个配置项,enabled,默认情况下标识启动,如果平时不使用epel源,可将其设置为0(enabled=0),当需要使用的时候,使用别名epel,即可启动epel源
#先设定enabled=0
[root@Centos7 yum.repos.d]# vim epel.repo
[root@Centos7 yum.repos.d]# cat epel.repo
[epel]
name=aliyun epel
#baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
enabled=0
gpgcheck=0
#设定别名
[root@Centos7 yum.repos.d]# alias epel="sed -i ‘s@enabled=0@enabled=1@‘ /etc/yum.repos.d/epel.repo"
[root@Centos7 yum.repos.d]# vim ~root/.bashrc
[root@Centos7 yum.repos.d]# tail -1 ~root/.bashrc
alias epel=‘sed -i "s@enabled=0@enabled=1@" /etc/yum.repos.d/epel.repo‘
[root@Centos7 yum.repos.d]# vim /etc/yum.repos.d/epel.repo
[root@Centos7 yum.repos.d]# cat /etc/yum.repos.d/epel.repo
[epel]
name=aliyun epel
#baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
enabled=0
gpgcheck=0
[root@Centos7 yum.repos.d]# epel
[root@Centos7 yum.repos.d]# cat /etc/yum.repos.d/epel.repo
[epel]
name=aliyun epel
#baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
enabled=1
gpgcheck=0
[root@Centos7 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel
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
[root@Centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
epel | 4.7 kB 00:00
(1/5): base/group_gz | 156 kB 00:00
(2/5): base/primary_db | 5.7 MB 00:00
(3/5): epel/7/x86_64/group_gz | 95 kB 00:00
(4/5): epel/7/x86_64/updateinfo | 1.0 MB 00:00
(5/5): epel/7/x86_64/primary_db | 6.8 MB 00:00
Determining fastest mirrors
repo id repo name status
base local repo 9,591
epel/7/x86_64 aliyun epel 13,382
repolist: 22,973
以上是关于自建yum仓库(网络源和本地源)的主要内容,如果未能解决你的问题,请参考以下文章