LINUX环境下YUM的各种配置总结

  • Post author:
  • Post category:linux



目录


一、配置本地YUM源


1、创建目录/yum


2、挂载光盘到/yum目录


3、配置yum源文件


4、yum clean all清除YUM缓存


5、yum makecache 创建YUM缓存


二、配置远程yum源


1、使本地YUM源失效


2、创建YUM源文件


3、刷新YUM缓存


4、测试安装软件


三、其他命令和参数


四、自建网络YUM源


1、安装httpd


2、创建目录并挂载资源


3、创建YUM源文件


4、使原有YUM源失效


5、清除YUM缓存


6、创建YUM缓存


YUM源使用测试


五、创建自己的YUM源


1、安装创建YUM源的软件包


2、收集软件包


3、创建自己的YUM源文件


4、查看


5、更改YUM配置文件


6、测试安装软件包。


六、以上测试都没问题



测试环境:


VMware workstations 15 Pro+


CENTOS 7.9


一、配置本地YUM源


1、创建目录/yum


2、挂载光盘到/yum目录


3、配置yum源文件


首先禁用目录内其他


YUM



[root@centos7 yum.repos.d]# ls

CentOS-Base.repo.b       CentOS-Debuginfo.repo.b  CentOS-Sources.repo.b

CentOS-Base.repo.backup  CentOS-fasttrack.repo.b  CentOS-Vault.repo.b

CentOS-CR.repo.b         CentOS-Media.repo        CentOS-x86_64-kernel.repo.b

[root@centos7 yum.repos.d]# vi CentOS-Media.repo

[root@centos7 yum.repos.d]# cat CentOS-Media.repo

#  This repo can be used with mounted DVD media, verify the mount point for

#  CentOS-7.  You can use this repo and yum to install items directly off the

#  DVD ISO that we release.

#

# To use this repo, put in your DVD and use it with the other repos too:

#  yum –enablerepo=c7-media [command]

#

# or for ONLY the media repo, do this:

#

#  yum –disablerepo=\* –enablerepo=c7-media [command]

[c7-media]

name=CentOS-$releasever – Media

baseurl=file:///yum/     #这里的目录是光盘挂载的目录

【注意:如果是其他版本LINUX,需要注意这个目录内有repodata目录】

gpgcheck=1

enabled=1                        #启用此YUM源文件

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@centos7 yum.repos.d]#


4、yum clean all清除YUM缓存

[root@centos7 yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, langpacks

Cleaning repos: c7-media

Cleaning up list of fastest mirrors


5、yum makecache 创建YUM缓存

[root@centos7 yum.repos.d]# yum makecache

Loaded plugins: fastestmirror, langpacks

Determining fastest mirrors

c7-media                                                 | 3.6 kB     00:00

(1/4): c7-media/group_gz                                   | 153 kB   00:00

(2/4): c7-media/primary_db                                 | 3.3 MB   00:00

(3/4): c7-media/filelists_db                               | 3.3 MB   00:00

(4/4): c7-media/other_db                                   | 1.3 MB   00:00

Metadata Cache Created

[root@centos7 yum.repos.d]#


二、配置远程yum源


1、使本地YUM源失效

[root@centos7 yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repo.b


2、创建YUM源文件

[root@centos7 yum.repos.d]# vi cenos7.repo

[root@centos7 yum.repos.d]# cat cenos7.repo

[base]

name=centos7-www

baseurl=http://centos.ustc.edu.cn/centos/7/os/$basearch/

gpgcheck=1

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@centos7 yum.repos.d]#


3、刷新YUM缓存

[root@centos7 yum.repos.d]# yum makecache

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

base                                                                                | 3.6 kB  00:00:00

(1/4): base/x86_64/group_gz                                                         | 153 kB  00:00:00

(2/4): base/x86_64/filelists_db                                                     | 7.2 MB  00:00:01

(3/4): base/x86_64/other_db                                                         | 2.6 MB  00:00:00

(4/4): base/x86_64/primary_db                                                       | 6.1 MB  00:00:01

Metadata Cache Created


4、测试安装软件

[root@centos7 yum.repos.d]# yum install vsftpd

vsftpd-sysvinit.x86_64  vsftpd.x86_64

[root@centos7 yum.repos.d]# yum install vsftpd.x86_64

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Resolving Dependencies

–> Running transaction check

—> Package vsftpd.x86_64 0:3.0.2-28.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================

Package                 Arch                    Version                       Repository             Size

===========================================================================================================

Installing:

vsftpd                  x86_64                  3.0.2-28.el7                  base                  172 k

Transaction Summary

===========================================================================================================

Install  1 Package

Total download size: 172 k

Installed size: 353 k

Is this ok [y/d/N]: y

Downloading packages:

vsftpd-3.0.2-28.el7.x86_64.rpm                                                      | 172 kB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : vsftpd-3.0.2-28.el7.x86_64                                                              1/1

Verifying  : vsftpd-3.0.2-28.el7.x86_64                                                              1/1

Installed:

vsftpd.x86_64 0:3.0.2-28.el7

Complete!

[root@centos7 yum.repos.d]# yum install vsftpd-sysvinit.x86_64

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Resolving Dependencies

–> Running transaction check

—> Package vsftpd-sysvinit.x86_64 0:3.0.2-28.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================

Package                       Arch                 Version                       Repository          Size

===========================================================================================================

Installing:

vsftpd-sysvinit               x86_64               3.0.2-28.el7                  base                24 k

Transaction Summary

===========================================================================================================

Install  1 Package

Total download size: 24 k

Installed size: 2.8 k

Is this ok [y/d/N]: y

Downloading packages:

vsftpd-sysvinit-3.0.2-28.el7.x86_64.rpm                                             |  24 kB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : vsftpd-sysvinit-3.0.2-28.el7.x86_64                                                     1/1

Verifying  : vsftpd-sysvinit-3.0.2-28.el7.x86_64                                                     1/1

Installed:

vsftpd-sysvinit.x86_64 0:3.0.2-28.el7

Complete!

[root@centos7 yum.repos.d]#


三、其他命令和参数

安装yum  install httpd

升级yum update httpd

检查需要升级的软件包yum check-update

YUM源可安装的软件包yum list

已经安装的软件包yum list installed

显示某个软件包的信息yum info httpd

移除软件包yum remove httpd

清除缓存yum clean all

-h 帮助参数

-y 确认参数

-q 默认安装参数


四、自建网络YUM源


1、安装httpd

[root@centos7 yum.repos.d]#

yum install httpd -y

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Resolving Dependencies

–> Running transaction check

—> Package httpd.x86_64 0:2.4.6-95.el7.centos will be installed

–> Processing Dependency: httpd-tools = 2.4.6-95.el7.centos for package: httpd-2.4.6-95.el7.centos.x86_64

–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-95.el7.centos.x86_64

–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-95.el7.centos.x86_64

–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-95.el7.centos.x86_64

–> Running transaction check

—> Package apr.x86_64 0:1.4.8-7.el7 will be installed

—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed

—> Package httpd-tools.x86_64 0:2.4.6-95.el7.centos will be installed

—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================

Package                   Arch                 Version                           Repository          Size

===========================================================================================================

Installing:

httpd                     x86_64               2.4.6-95.el7.centos               base               2.7 M

Installing for dependencies:

apr                       x86_64               1.4.8-7.el7                       base               104 k

apr-util                  x86_64               1.5.2-6.el7                       base                92 k

httpd-tools               x86_64               2.4.6-95.el7.centos               base                93 k

mailcap                   noarch               2.1.41-2.el7                      base                31 k

Transaction Summary

===========================================================================================================

Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M

Installed size: 10 M

Downloading packages:

(1/5): apr-1.4.8-7.el7.x86_64.rpm                                                   | 104 kB  00:00:00

(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                                              |  92 kB  00:00:00

(3/5): httpd-tools-2.4.6-95.el7.centos.x86_64.rpm                                   |  93 kB  00:00:00

(4/5): mailcap-2.1.41-2.el7.noarch.rpm                                              |  31 kB  00:00:00

(5/5): httpd-2.4.6-95.el7.centos.x86_64.rpm                                         | 2.7 MB  00:00:00

———————————————————————————————————–

Total                                                                      3.6 MB/s | 3.0 MB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : apr-1.4.8-7.el7.x86_64                                                                  1/5

Installing : apr-util-1.5.2-6.el7.x86_64                                                             2/5

Installing : httpd-tools-2.4.6-95.el7.centos.x86_64                                                  3/5

Installing : mailcap-2.1.41-2.el7.noarch                                                             4/5

Installing : httpd-2.4.6-95.el7.centos.x86_64                                                        5/5

Verifying  : httpd-tools-2.4.6-95.el7.centos.x86_64                                                  1/5

Verifying  : mailcap-2.1.41-2.el7.noarch                                                             2/5

Verifying  : apr-1.4.8-7.el7.x86_64                                                                  3/5

Verifying  : httpd-2.4.6-95.el7.centos.x86_64                                                        4/5

Verifying  : apr-util-1.5.2-6.el7.x86_64                                                             5/5

Installed:

httpd.x86_64 0:2.4.6-95.el7.centos

Dependency Installed:

apr.x86_64 0:1.4.8-7.el7       apr-util.x86_64 0:1.5.2-6.el7  httpd-tools.x86_64 0:2.4.6-95.el7.centos

mailcap.noarch 0:2.1.41-2.el7

Complete!

[root@centos7 yum.repos.d]#

systemctl start httpd

启动httpd服务

[root@centos7 yum.repos.d]#

systemctl enable httpd

设置开机启动httpd服务

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@centos7 yum.repos.d]#

客户端测试httpd服务,正常。


2、创建目录并挂载资源

mkdir /var/www/html/cent7

mount /dev/sr0  /var/www/html/cent7

[root@centos7 cent7]# pwd

/var/www/html/cent7

[root@centos7 cent7]# ls

CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7

EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7

EULA             isolinux  repodata  TRANS.TBL

[root@centos7 cent7]#


3、创建YUM源文件

[root@centos7 yum.repos.d]# vi centos7-http.repo

[root@centos7 yum.repos.d]# cat centos7-http.repo

[centos7-http]

name=centos7-http

baseurl=http://192.168.31.111/cent7/

gpgcheck=1

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@centos7 yum.repos.d]#


4、使原有YUM源失效

[root@centos7 yum.repos.d]# mv cenos7.repo cenos7.repo.b


5、清除YUM缓存

[root@centos7 yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, langpacks

Cleaning repos: centos7-http

Cleaning up list of fastest mirrors

Other repos take up 164 M of disk space (use –verbose for details)


6、创建YUM缓存

[root@centos7 yum.repos.d]# yum makecache

Loaded plugins: fastestmirror, langpacks

Determining fastest mirrors

centos7-http                                             | 3.6 kB     00:00

(1/4): centos7-http/group_gz                               | 153 kB   00:00

(2/4): centos7-http/filelists_db                           | 3.3 MB   00:00

(3/4): centos7-http/primary_db                             | 3.3 MB   00:00

(4/4): centos7-http/other_db                               | 1.3 MB   00:00

Metadata Cache Created


YUM源使用测试

[root@centos7 yum.repos.d]# yum remove vsftpd.x86_64 -y                 删除软件包

[root@centos7 yum.repos.d]# yum install vsftpd.x86_64  -y                        安装软件包

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Resolving Dependencies

–> Running transaction check

—> Package vsftpd.x86_64 0:3.0.2-28.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package        Arch           Version               Repository            Size

================================================================================

Installing:

vsftpd         x86_64         3.0.2-28.el7          centos7-http         172 k

Transaction Summary

================================================================================

Install  1 Package

Total download size: 172 k

Installed size: 353 k

Is this ok [y/d/N]: y

Downloading packages:

vsftpd-3.0.2-28.el7.x86_64.rpm                             | 172 kB   00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : vsftpd-3.0.2-28.el7.x86_64                                   1/1

Verifying  : vsftpd-3.0.2-28.el7.x86_64                                   1/1

Installed:

vsftpd.x86_64 0:3.0.2-28.el7

Complete!

[root@centos7 yum.repos.d]#


五、创建自己的YUM源

当安装一些固定的软件包变成常态,我们可以把这些软件包进行收集,然后创建自己的YUM源信息和文件,可以方便统一安装部署。


1、安装创建YUM源的软件包

createrepo

deltarpm   (RHEL8之后版本没有这个软件)

python-deltarpm    (RHEL8之后版本没有这个软件)


2、收集软件包

比喻说,把安装zabbix所需的软件包放入/test目录下


3、创建自己的YUM源文件

#createrepo /test


4、查看

[root@orl8301 repodata]# pwd

/test/repodata

[root@orl8301 repodata]# ls

0ba2158a9753a65236a78bb3700fe4d0f92083c389b8940c2a32817466ea2609-filelists.sqlite.bz2

27965b828603d3bf0bb98e816879ff9645877ac54235633708aa2e602843f9bb-primary.xml.gz

506f22a60d7d164459354719a1057f41c8e5469556b2d31c597a38e53f375d85-other.xml.gz

96bca63e88ab286c735a172566c679655628aa78310884a97ba56bc831ad5a0d-primary.sqlite.bz2

cdd96dc02085e2f75b2b7564145b71fc057b3819bc0388c5fc843e9ab6af15cf-other.sqlite.bz2

db0fda0dc24f0d05aa780179b09dc78a021c8d8f3924f73b54aaa1fc619ed897-filelists.xml.gz

repomd.xml

[root@orl8301 repodata]#


5、更改YUM配置文件


6、测试安装软件包。


六、以上测试都没问题



版权声明:本文为xaosky原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。