美文网首页linux运维
搭建yum私有仓库

搭建yum私有仓库

作者: 唯爱熊 | 来源:发表于2019-10-30 08:11 被阅读0次

    为什么需要使用yum源私有仓库

    1.网络上有大量的yum源,但由于受到网络环境的限制,导致软件安装耗时过长甚至失败。
    2.网络资源需要有外网才能下载。
    3.有些软件base源和一些epel扩展源中没有,需要额外添加源才可以下载使用。

    环境准备

    说明:查看防火墙状态,如果是开启状态,需要关闭,以免影响后期测试和使用
    [root@m01 ~]# systemctl status firewalld.service
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:firewalld(1)
    [root@m01 ~]# getenforce
    Disabled
    这里是关闭状态无需其它额外操作。
    

    服务端配置

    说明:服务端是指配置本地仓库的服务器

    1.nginx官方源安装nginx

    1.使用vim /etc/yum.repos.d/nginx.repo创建nginx.repo源文件,按i输入如下内容:
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    
    [nginx-mainline]
    name=nginx mainline repo
    baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    按ESC键入:wq保存文件并退出。
    2.安装nginx
    [root@yum ~]# yum -y install nginx
    

    2.配置目录索引

    [root@yum ~]# cd /etc/nginx/conf.d/
    [root@yum /etc/nginx/conf.d]# vim yum.conf 
    server {
        listen 80;
        server_name yum.downloade.com;
        location / {
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        autoindex_format html;
        charset utf-8,gbk;
        root /yum/downloade;
       }
    }
    

    3.准备软件仓库目录

    说明:默认的可以使用站点目录或者使用其他的目录,这里直接sj-hiyong站点目录

    [root@yum ~]# mkdir /yum/downloade/ -p
    

    4.启动nginx

    [root@yum ~]# nginx -t
    [root@yum ~]# systemctl start nginx
    

    下载软件

    下载方式有两种:

    1.使用yum的只下载不安装的方式进行下载软件

    [root@yum ~]# yum -y install --downloadonly --downloaddir=/yum/downloade keepalived
    

    2.真实下载

    1.打开yum缓存  将/etc/yum.conf 文件中的keepcache=0修改为1
    [root@yum ~]# cat /etc/yum.conf 
    [main]
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=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
    2.清理yum缓存  
    [root@yum ~]# yum clean all
    3.下载软件
    [root@yum ~]# yum -y install keepalived
    4. 移动已经下载下来的rpm包到软件仓库目录
    [root@yum ~]# find /var/cache/yum/ -type f -name "*.rpm"|xargs mv -t  /yum/downloade
    

    下载creatrepo

    [root@yum ~]# yum -y install createrepo
    

    生成元数据

    [root@yum ~]# createrepo /yum/downloade/
    

    更新源数据

    说明:如果有新的软件包放入到软件仓库,这里就需要更新元数据。

    [root@yum ~]# createrepo --update /yum/downloade/
    

    服务端访问测试

    1.windows上添加hosts, 路径C:\Windows\System32\drivers\etc\hosts

    10.0.0.251   yum.downloade.com
    

    2.浏览器访问


    客户端配置

    说明:客户端是指需要安装软件包的服务器

    使用vim /etc/repos.d/local.repo创建本local.repo的本地源文件,按i输入如下内容:
    [local]
    name=local
    enable=1
    gpgcheck=0
    baseurl=http://172.16.1.251
    按ESC键入:wq 保存文件并退出。
    

    客户端测试

    #查看本地源文件
    [root@web02 /etc/yum.repos.d]# ls
    local.repo
    You have new mail in /var/spool/mail/root
    #获取元数据
    [root@web02 /etc/yum.repos.d]# yum makecache fast
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    local                                                                                   | 2.9 kB  00:00:00     
    local/primary_db                                                                        | 4.3 kB  00:00:00     
    Metadata Cache Created
    #本地yum安装
    [root@web02 /etc/yum.repos.d]# yum -y install keepalived
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package keepalived.x86_64 0:1.3.5-16.el7 will be installed
    --> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64
    --> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64
    --> Processing Dependency: libnetsnmp.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64
    --> Running transaction check
    ---> Package net-snmp-agent-libs.x86_64 1:5.7.2-43.el7 will be installed
    ---> Package net-snmp-libs.x86_64 1:5.7.2-43.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ===============================================================================================================
     Package                           Arch                 Version                      Repository           Size
    ===============================================================================================================
    Installing:
     keepalived                        x86_64               1.3.5-16.el7                 local               331 k
    Installing for dependencies:
     net-snmp-agent-libs               x86_64               1:5.7.2-43.el7               local               706 k
     net-snmp-libs                     x86_64               1:5.7.2-43.el7               local               750 k
    
    Transaction Summary
    ===============================================================================================================
    Install  1 Package (+2 Dependent packages)
    
    Total download size: 1.7 M
    Installed size: 6.0 M
    Downloading packages:
    (1/3): keepalived-1.3.5-16.el7.x86_64.rpm                                               | 331 kB  00:00:00     
    (2/3): net-snmp-libs-5.7.2-43.el7.x86_64.rpm                                            | 750 kB  00:00:00     
    (3/3): net-snmp-agent-libs-5.7.2-43.el7.x86_64.rpm                                      | 706 kB  00:00:00     
    ---------------------------------------------------------------------------------------------------------------
    Total                                                                           13 MB/s | 1.7 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 1:net-snmp-libs-5.7.2-43.el7.x86_64                                                         1/3 
      Installing : 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64                                                   2/3 
      Installing : keepalived-1.3.5-16.el7.x86_64                                                              3/3 
      Verifying  : keepalived-1.3.5-16.el7.x86_64                                                              1/3 
      Verifying  : 1:net-snmp-agent-libs-5.7.2-43.el7.x86_64                                                   2/3 
      Verifying  : 1:net-snmp-libs-5.7.2-43.el7.x86_64                                                         3/3 
    
    Installed:
      keepalived.x86_64 0:1.3.5-16.el7                                                                             
    
    Dependency Installed:
      net-snmp-agent-libs.x86_64 1:5.7.2-43.el7                 net-snmp-libs.x86_64 1:5.7.2-43.el7                
    
    Complete!
    

    相关文章

      网友评论

        本文标题:搭建yum私有仓库

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