Linux软件管理day17

作者: 静如止水yw | 来源:发表于2019-08-15 20:36 被阅读0次

    yum指令
    yum本地仓库搭建


    一、yum指令


    1.与yum仓库相关指令

    # 1.列出yum源可用的软件仓库
    #列出yum源可用的软件仓库
    [root@wyw ~]# yum repolist         #查看已安装的yum源仓库
    #列出全部yum源可用和禁用的仓库
    [root@wyw ~]# yum repolist all     #查看所有的yum源仓库
    #查找某个命令或文件属于那个软件包(生产常用)
    [root@wyw ~]# yum provides /etc/my.conf
    [root@wyw ~]# yum provides cd
    

    2.与yum缓存相关指令

    #1.缓存rpm包方式一、修改yum全局配置文件
    [root@wyw ~]# vim /etc/yum.conf
    [main]
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=1     #启动缓存
    #2.缓存rpm包方式二,只下载不安装
    [root@wyw ~]# yum install -y yum-plugin-downloadonly #插件
    [root@wyw ~]# yum install httpd -y --downloadonly --downloaddir=/tmp
    #3.清除所有yum缓存的软件包以及元数据
    [root@wyw ~]# yum clean all
    #4.只清除缓存的软件包
    [root@wyw ~]# yum clean packages
    [root@wyw ~]# yum clean all            # 清除所有的缓存包
    

    3.组包相关指令

    [root@www.xuliangwei.com ~]# yum groups list
    #安装一整个组的软件
    [root@wyw ~]# yum groups install Development tools \
    Compatibility libraries \
    Base Debugging Tools
    #yum删除包组
    [root@wyw ~]# yum groups remove  -y Base
    

    二、搭建本地仓库


    在有些时候,Linux联网下载较慢或者在没有网络的情况下,使用yum下载时,就会出现下载不了的情况,这时候就需要搭建一个本地的yum仓库:

    #1.挂载镜像
    [root@wyw ~]# mount /dev/cdrom /mnt   
    #2.备份原有仓库
    [root@wyw ~]# gzip /etc/yum.repos.d/*
    #3.使用yum-config-manager命令添加本地仓库
    [root@wyw ~]# yum-config-manager --add-repo="file:///mnt"
    #4.或者使用手动添加repo文件
    [root@wyw ~]# vim /etc/yum.repos.d/cdrom.repo  
    [cdrom]      
    name=This is local cdrom
    baseurl=file:///mnt
    enabled=1
    gpgcheck=0
    [ 仓库名称 ]         
    name        仓库描述信息
    baseurl     #YUM源url地址 ,可以是file:// ftp:// http://
    enabled     #是否使用该YUM源(0代表禁用, 1代表激活)
    gpgcheck    #是否验证软件签名(0代表禁用, 1代表激活)
    #5.生成缓存
    [root@wyw ~]# yum makecache
    

    当有很多台主机联网下载文件时,使用光盘镜像满足不了的时候,就需要使用内网进行下载

    image.png
    1.环境准备
    系统 IP 角色
    centos7 10.0.0.200 yum仓库服务端
    centos7 10.0.0.199 yum仓库客户端

    2.服务端进行yum仓库的搭建准备工作

    #1.关闭防火墙、与selinux
    [root@yum_server ~]# systemctl stop firewalld
    [root@yum_server ~]# setenforce 0
    #2.安装ftp服务,启动并加入开机启动
    [root@yum_server ~]# yum -y install vsftpd 
    [root@yum_server ~]# systemctl start vsftpd 
    [root@yum_server ~]# systemctl enable vsftpd
    #3.开启yum缓存功能
    [root@yum_server ~]# vim /etc/yum.conf
    [main] cachedir=/var/cache/yum/$basearch/$releasever 
    keepcache=1
    [root@yum_server ~]# yum clean all
    #4.提供基础base软件包
    [root@yum_server ~]# mkdir /var/ftp/centos7
    [root@yum_server ~]# mount /dev/cdrom /mnt
    [root@yum_server ~]# cp -rp  /mnt/Packages/*.rpm /var/ftp/centos7/
    #5.提供第三方源
    [root@yum_server ~]# mkdir /var/ftp/ops
    [root@yum_server ~]# yum -y install nginx docker
    #6.复制已缓存的 Nginx docker 及依赖包 到自定义 YUM 仓库目录中
    [root@yum_server_69_112 ~]# find /var/cache/yum/x86_64/7/ \
    -iname "*.rpm" -exec cp -rf {} /var/ftp/ops \;
    #7.安装createrepo并创建 reopdata仓库
    [root@yum_server_ ~]# yum -y install createrepo
    [root@yum_server_ ~]# createrepo /var/ftp/ops
    # 注:如果此仓库每次新增软件则需要重新生成一次
    

    3.客户端配置yum源指向服务端

    #1.客户端配置并使用 base 基础源
    [root@yum_client ~]# gzip /etc/yum.repos.d/*
    [root@yum_client ~]# vim /etc/yum.repos.d/centos7.repo 
    [centos7]
    name=centos7_base
    baseurl=ftp://10.0.0.99/centos7
    gpgcheck=0
    #2.客户端配置并使用 ops 源
    [root@yum_client ~]# vim /etc/yum.repos.d/ops.repo 
    [ops]
    name=local ftpserver
    baseurl=ftp://10.0.0.99/ops
    gpgcheck=0
    

    相关文章

      网友评论

        本文标题:Linux软件管理day17

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