zoukankan      html  css  js  c++  java
  • 搭建本地yum源

    搭建本地yum仓库

    m01(yum仓库) web01(客户端)
    172.16.1.61 172.16.1.7

    安装createrepo软件

    yum(Yellow dog Updater,Modified)主要的功能是方便添加、删除和更新rpm软件包。可以解决软件包依存问题,更便于管理大量的系统更新问题。它可以同时配置多个仓库或叫资源库(repository),就是存放更新和依存的软件包的地方。

    createrepo 命令用于创建yum源(软件仓库),即为存放于本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据。

    [root@m01 base]# yum -y install createrepo
    -u  --baseurl <url>			指定Base URL的地址
    -o --outputdir <url>		指定元数据的输出位置
    -p --pretty					确保生成的所有xml都格式化了
    -x --excludes <packages> 	指定在形成元数据时需要排除的包
    -n --includepkg				通过命令行指定要纳入本地库中的包信息,需要提供URL或本地路径。
    -q --quiet					安静模式执行操作,不输出任何信息。
    -g --groupfile <groupfile>	指定本地软件仓库的组划分
    -v --verbose				输出详细信息。
    --update					如果元数据已经存在,且软件仓库中只有部分软件发生了改变或增减,则可用update参数直接对原有元数据进行升级,效率比重新分析rpm包依赖并生成新的元数据要高很多。
    -d --database				该选项指定使用SQLite来存储生成的元数据,默认项。
    

    createrepo初始化索引文件

    [root@m01 ~]# mkdir -p /html/yum
    [root@m01 ~]# createrepo -pdo /html/yum/ /html/yum/
    Saving Primary metadata
    Saving file lists metadata
    Saving other metadata
    Generating sqlite DBs
    Sqlite DBs complete
    [root@m01 ~]# 
    [root@m01 /]# cd /html/yum/
    [root@m01 yum]# ll
    total 4
    drwxr-xr-x 2 root root 4096 Aug  1 18:15 repodata
    [root@m01 yum]# tree 
    .
    └── repodata
        ├── 01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2
        ├── 401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz
        ├── 5dc1e6e73c84803f059bb3065e684e56adfc289a7e398946574d79dac6643945-primary.sqlite.bz2
        ├── 6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz
        ├── 7c36572015e075add2b38b900837bcdbb8a504130ddff49b2351a7fc0affa3d4-other.sqlite.bz2
        ├── dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz
        └── repomd.xml
    
    1 directory, 7 files
    [root@m01 yum]# 
    
    

    安装nginx使其提供web服务

    [root@m01 ~]# vim /etc/yum.repos.d/nginx.repo 
    [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
    [root@m01 ~]# yum -y install nginx
    [root@m01 yum]# vim /etc/nginx/conf.d/default.conf
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /html/yum;
            index  index.html index.htm;
        }
    }
    [root@m01 yum]# systemctl restart nginx
    

    增加新的rpm包

    [root@m01 yum]# pwd
    /html/yum
    [root@mo1 yum]# yum -y install yum-utils
    [root@mo1 ~]# yumdownloader nginx
    [root@m01 yum]# ls
    nginx-1.16.0-1.el7.ngx.x86_64.rpm
    [root@m01 yum]# 
    [root@m01 yum]# createrepo --update ./
    Spawning worker 0 with 1 pkgs
    Workers Finished
    Saving Primary metadata
    Saving file lists metadata
    Saving other metadata
    Generating sqlite DBs
    Sqlite DBs complete
    [root@m01 yum]# 
    

    客户端配置yum源地址

    [root@web01 yum.repos.d]# vim base.repo
    [base]
    name=base
    baseurl=http://172.16.1.61/
    gpgcheck=0
    enabled=1
    [root@web01 yum.repos.d]# yum repolist 
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                                                                 repo name                                                             status
    base                                                                    base                                                                  1
    repolist: 1
    [root@web01 yum.repos.d]# 
    

    同步阿里云镜像并搭建本地yum仓库

    更改yum源为阿里源

    [root@m01 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    [root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    

    安装相关软件

    [root@m01 ~]# yum -y install createrepo yum-utils
    [root@m01 ~]# reposync --help
    -c CONFIG, --config=CONFIG 		---要使用的配置文件(默认为/etc/yum.conf)
    --source					   ---源代码对源代码包进行操作
     -n --newest-only				---只下载最新的软件包
    -p							  ---将包下载到:默认为当前目录
    

    同步阿里源到本地目录

    #创建本地目录
    [root@m01 ~]# mkdir /mirrors/
    #同步阿里源到本地目录
    [root@m01 ~]# reposync -p /mirrors/
    #创建索引
    [root@m01 ~]# createrepo -pdov /mirrors/base/ /mirrors/base/
    [root@m01 ~]# createrepo -pdov /mirror/extras/ /mirror/extras/
    [root@m01 ~]# createrepo -pdov /mirror/updates/ /mirror/updates/
    [root@m01 ~]# createrepo -pdov /mirror/epel/ /mirror/epel/
    [root@m01 ~]# 
    

    配置nginx服务

    [root@m01 ~]# vim /etc/nginx/conf.d/default.conf
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /mirrors;
            index  index.html index.htm;
        }
    }
    
    

    客户端更改yum仓库

    [root@web01 yum.repos.d]# vim Centos-Base.repo 
    [base]
    name=base
    baseurl=http://172.16.1.61/base/
    path=/
    gpgcheck=0
    enabled=1
    
    [updates]
    name=updates
    baseurl=http://172.16.1.61/updates/
    path=/
    gpgcheck=0
    enabled=1
    
    [epel]
    name=epel
    baseurl=http://172.16.1.61/epel/
    path=/
    enabled=1
    gpgcheck=0
    
    [extras]
    name=extras
    baseurl=http://172.16.1.61/extras/
    enabled=1
    gpgcheck=0
    [root@web01 yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                                                                repo name                                                              status
    base                                                                   base                                                                   10,019
    epel                                                                   epel                                                                   13,329
    extras                                                                 extras                                                                    419
    updates                                                                updates                                                                 2,500
    repolist: 26,267
    [root@web01 yum.repos.d]# 
    
    
    

    更新阿里源仓库

    #更新新的rpm包
    [root@m01 ~]# reposync -np /mirror
    #更新源数据
    [root@m01 ~]# createrepo --update /mirrors/base/ 
    [root@m01 ~]# createrepo --update /mirrors/extras/
    [root@m01 ~]# createrepo --update /mirrors/updates/ 
    [root@m01 ~]# createrepo --update /mirrors/epel/ 
    
    
  • 相关阅读:
    Kubernetes学习之路(21)之网络模型和网络策略
    Kubernetes学习之路(16)之存储卷
    Kubernetes学习之路(18)之statefulset控制器
    Kubernetes学习之路(28)之镜像仓库Harbor部署
    Kubernetes学习之路(六)之创建K8S应用
    Kubernetes学习之路(十五)之Ingress和Ingress Controller
    nali一款linux下显示IP来源的小工具
    Redis 及RedisBloom 安装
    对java注解与反射的理解
    Java 8 stream的详细用法
  • 原文地址:https://www.cnblogs.com/opesn/p/11399433.html
Copyright © 2011-2022 走看看