手工构造清华大学的yum源

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim qinghua.repo[qinghua]name=qinghuabaseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/gpgcheck=1gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
构建好之后makecache一下
[root@localhost yum.repos.d]# yum makecache   --生成缓存,生成元数据,这条命令生成以下的数据,在/var/cache/yum/x86_64/7/下面
[root@localhost yum.repos.d]# cd /var/cache/yum/x86_64/7/
[root@localhost 7]# ls
base  epel  extras  qinghua  timedhosts  timedhosts.txt  updates[root@localhost 7]# cd qinghua/
[root@localhost qinghua]# ls
04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2      cachecookie
41232548001a78473ae0f2d4b92e1ec28f7a0593e0495056515887fe2a39b416-filelists.sqlite.bz2    gen
4af1fba0c1d6175b7e3c862b4bddfef93fffb84c37f7d5f18cfbff08abc47f8a-c7-x86_64-comps.xml.gz  packages
879e9b33c0ecf18a99bdac5b607b1ea65dc66423b99bdf4214129c5d5923e475-other.sqlite.bz2        repomd.xml
用repolist来查看
[root@localhost ~]# yum repolist  repo id                                  repo name                                                              statusbase/7/x86_64                            CentOS-7 - Base - mirrors.aliyun.com                                   10,097*epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64                         13,230extras/7/x86_64                          CentOS-7 - Extras - mirrors.aliyun.com                                    341qinghua                                  qinghua.repo                                                           10,097updates/7/x86_64                         CentOS-7 - Updates - mirrors.aliyun.com                                 1,787repolist: 35,552
 
yum-config-manager 造清华大学的yum源
[root@localhost ~]# yum -y install yum-utils    --安装yum的扩展包
[root@localhost yum.repos.d]# yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
-- yum-config-manager 自动配置网络上的清华大学yum仓库
Loaded plugins: fastestmirror, priorities
adding repo from: https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
 
[mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_]
name=added from: https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
enabled=1
--这里没有包含gpgcheck,需要要手工添加gpgcheck=1,配置一下gpgkey或者你可以设置为0(有1和0两个选择,分别代表是否是否进行gpg校验,如果没有这一项,默认是检查的)
enabled=[1 or 0]
--当某个软件仓库被配置成 enabled=0 时,yum 在安装或升级软件包时不会将该仓库做为软件包提供源。使用这个选项,可以启用或禁用软件仓库。
#通过 yum 的 --enablerepo=[repo_name] 和 --disablerepo=[repo_name] 选项,或者通过 PackageKit 的"添加/删除软件"工具,也能够方便地启用和禁用指定的软件仓库
可以看到这样一条命令就把上面一步一步配置的清华大学的源解决了,然后yum makecache生成缓存和yum repolist查看一下就可以了。
 
自动配置本地仓库:
yum-config-manager --add-repo=file:///mnt/cdrom
 
yum-config-manager禁用/启动仓库(实际上就是修改配置文件.repo的enable的值)如果是手动配置那么需要修改.repo文件,设置enabled=0,这样代表禁用了仓库,要查看仓库是否被禁用可以使用
[root@localhost yum.repos.d]# yum repolist all
什么时候禁用仓库,就是安装包的时候,多个仓库都含有这个包,但是你就是不想使用默认仓库提供的包,那么你可以临时禁用该仓库,禁用清华大学的仓库
[root@localhost yum.repos.d]# yum-config-manager --disable mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_   后面跟着的是仓库的id
查看仓库状态,可以看到清华大学的仓库被禁用了。
 
 
yum常用命令
yum repolist {all|enabled|disabled} 列出所有/已启用/已禁用的yum源
yum list {all|installed|avaliable} 列出所有/已安装/可安装的软件包
yum info package 显示某一个软件包的信息 --建议使用rpm -qi package_name,yum显示的比较慢,需要加载缓存
 
yum install package -y安装软件包
yum reinstall package 重新安装软件包
yum remove|earse package 卸载软件包
yum whatprovides|provides files 查询某个文件是哪个软件包生成的,files通常指命令,比如可以写nginx--这个命令比较实用
 
yum grouplist {all|installed|avaliable} 列出所有/已安装/可安装的软件包组  --用的不多,了解一下即可
yum groupinfo 显示某个软件包组的信息
yum groupinstall 安装某个软件包组
yum groupremove 删除某个软件包组
 
yum history 查看yum使用的历史
yum clean {all|packages|metadata} 清除所有/软件包/元数据
yum makecache 生成yum元数据
yum --nogpgcheck 不校验公钥文件
yum -y 自动进行操作
yum update 升级所有包,以及升级软件和系统内核,这就是一键升级  --
yum update package 更新指定程序包package --一般不要使用这条命令
 
yum --disablerepo=repo  --临时禁用某个repo源
yum  install nginx --disablerepo=nginx-stable  --临时禁用指定的repo,在其他的repo安装nginx包,这条命令比较实用
yum --enablerepo=
yum -C list nginx  --在缓存中查找包,速度更快
 
yum-fastestmirror
[root@node-2 ~]# yum install yum-fastestmirror -y  --自动搜索最快镜像插件并安装(yum多个mirror自动选择速度最快的mirror,yum-fastestmirror插件,它会自动选择最快的mirror)
 我们都知道,使用yum可以简化系统软件更新的工作。为了保证更新的持续进行,通常都会提供多个mirror(镜像)地址供下载使用,但由于存在地域问题,从不同的镜像下载速度差异很大。选择从适合的镜像下载软件包,会极大的影响更新速度。以CentOS为例,可使用一个叫fastestmirror的插件,让yum在更新时先根据ping值进行判断,然后从最快响应的地址下载。
首先,请配置好yum环境,然后,确认配置文件中,以及允许使用插件:
cat /etc/yum.conf |grep plugins
plugins=1

没有的该参数的,请加入该设定。此外,要使用fastestmirror插件,在.repo配置文件中必须使用镜像方式,也就是mirrorlist设定,而不是baseurl方式,例如:
# cat CentOS-Base.repo |grep -A3 addons
[addons]
name=CentOS-4 - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
enabled=1
————————————————
版权声明:本文为CSDN博主「此博主较懒不取名」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_34556414/java/article/details/105425688

猜你喜欢

转载自www.cnblogs.com/shenyuanhaojie/p/12682740.html
今日推荐