美文网首页
自建yum仓库

自建yum仓库

作者: 早_wsm | 来源:发表于2020-03-15 23:41 被阅读0次

前言

节省时间就是抢救生命!在工作中我们总会去重复做一件事,比如下载,有些东西总是要用到要下载,受外界因素影响每次下载都会耗费大量时间,为节省时间何不在自己家建个小仓库,把之前用到下载过的东西都整理放好,用的时候直接拿过来就好!

一、创建yum仓库目录

mkdir /yum/

先把常用的rpm包和命令下载到我们刚刚创建的本地yum仓库中

yum install  --downloadonly --downloaddir=/yum/ mlocate lrzsz tree vim nc nmap lrzsz wget bash-completion bash-completion-extras cowsay sl htop iotop iftop lsof net-tools sysstat unzip bc psmisc ntpdate wc telnet-server bind-utils gcc gcc-c++ autoconf pcre pcre-devel make automake httpd-tools 

--downloadonly 只下载不安装
--downloaddir 指定rpm包的下载路径

二、修改yum配置文件,打开本地缓存

[root@m01 ~]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1  ###此处修改为1
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

keepcache=1 #1为开启,0为不开启

三、安装createrepo,并生成索引文件

yum install createrepo -y
createrepo /yum/

四、提供yum服务

可以用Apache或nginx、python提供web服务,这里使用nginx

先安装nginx

yum install -y nginx

修改配置文件,使用http协议访问

vim /etc/nginx/conf.d/yum_ck.conf

server {
    listen 8888;
    server_name 10.0.0.61; #你的yum服务器地址
    root /yum;
    index index.html;
    location / {
      root /yum; #仓库目录
      autoindex on;
    }
}

配置文件写入完成使用nginx -t检查语法,如果之前已启动过nginx 就重启nginx -s reload,如果没有就启动nginx,systemctl start nginx

五、创建本地源

cd /etc/yum.repos.d

[root@m01]# vim /etc/yum.repos.d/yum-Media.repo
[yum_ck] #本地仓库名
name=yum_ck 
baseurl=http://10.0.0.61:8888/  #http协议,rpm包存放路径
gpgcheck=0  #关闭安全验证
enabled=1   #启用本仓库
priority=1  #优先级为1,最高

清除yum缓存

yum clean all

六、优先级设置

因为我们服务器上还存在其他源,很难保证我们每次下载自动先从我们自建的yum仓库内下载,所以需要做一下优先级设置

  • 1.下载一个第三方插件
yum install yum-plugin-priorities.noarch
  • 2.检查是否启动服务(默认是开启的)
cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
  • 3.修改源的优先级
    在每个[模块]底部增加priority=2,这样就降低了他们的优先级,本地仓库在刚配置时就已设置为1了,所以,yum仓库优先于其他源
[root@m01 ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
priority=2  #添加优先级为2
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
priority=2  #添加优先级为2
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
priority=2  #添加优先级为2
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
priority=2  #添加优先级为2
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
priority=2  #添加优先级为2

七、测试

每次新加入rpm包后都要对本地仓库进行更新

 createrepo --update /yum/

查看软件包总数

yum repoinfo yum_ck | grep pkgs

bc命令加入到yum仓库中

yum install  --downloadonly --downloaddir=/yum/ bc

再次查看软件包总数

yum repoinfo yum_ck | grep pkgs

无变化
更新本地仓库

createrepo --update /yum/

清除所有缓存

yum clean all

查看新的软件包总数

yum repoinfo yum_ck | grep pkgs

如果软件包的数量增加,说明仓库更新成功。
此时使用yum install -y bc,下载后使用yum provides bc可以看到:

[root@m01 ~]# yum provides bc
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
224 packages excluded due to repository priority protections
bc-1.06.95-13.el7.x86_64 : GNU's bc (a numeric processing language) and dc (a calculator)
Repo        : yum_ck
bc-1.06.95-13.el7.x86_64 : GNU's bc (a numeric processing language) and dc (a calculator)
Repo        : @yum_ck

至此,我们便获得了一个可爱的本地yum仓库,以后每次下载之前仓库内存在的镜像或者包都会优先在yum仓库内直接下载,大大提高了效率节省了时间

相关文章

  • 自建yum仓库

    前言 节省时间就是抢救生命!在工作中我们总会去重复做一件事,比如下载,有些东西总是要用到要下载,受外界因素影响每次...

  • Linux第六周作业20191231

    1、自建yum仓库,分别为网络源和本地源。 本地源: cp /etc/yum.repos.d/CentOS-Bas...

  • 程序包安装和磁盘文件系统

    1、自建yum仓库,分别为网络源和本地源 备份原有repo文件 创建新的repo文件 验证yum源 2.安装htt...

  • Linux基础及总结6之软件包及磁盘管理

    1、自建yum仓库,分别为网络源和本地源 网络源,这里直接下载使用阿里云的提供的yum源,以Centos为例将...

  • 第四周作业

    1、自建yum仓库,分别为网络源和本地源网络源repo配置(centos7): 本地源repo配置(centos7...

  • Day-16yum的使用

    1.yum仓库查询 仓库的查询yum repolist 查询的是开启的yum仓库yum repolist al...

  • day17-软件管理

    一.yum仓库相关的指令 1.列出yum源可用的软件仓库yum repolist (查看仓库)yum rep...

  • 内网服务自建yum源(不需要网络)

    内网服务器自建yum源仓库 - - - 外网也可以用、也可以定时更新同步 - - - 由于内网没有互联网络,没...

  • 第六周技术作业

    1、自建yum仓库,分别为网络源和本地源 2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。 ...

  • linux作业6

    1、自建yum仓库,分别为网络源和本地源本地源: 网络源实验环境:ip1:192.168.80.10——做服务端i...

网友评论

      本文标题:自建yum仓库

      本文链接:https://www.haomeiwen.com/subject/qdpiehtx.html