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

目录

一、配置本地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、测试安装软件包。

六、以上测试都没问题

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要在 Linux 上搭建测试环境,需要先安装必要的软件和工具,具体步骤如下: 1. 安装操作系统,可以选择 Ubuntu、CentOS 等发行版本。 2. 安装编程语言运行环境。例如,如果你要测试 Python 代码,需要安装 Python 以及相应的第三方库。 3. 安装数据库。如果你要测试数据库相关功能,需要安装 MySQL、PostgreSQL 等数据库系统。 4. 安装测试工具。可以使用常用的单元测试框架,如 Python 的 unittest,测试数据库相关功能可使用 Pytest-Django 5. 安装编辑器或 IDE。可以使用常用的编辑器,如 VSCode, PyCharm 等。 6. 配置环境变量。 7. 进行测试,通过测试结果来验证代码的正确性。 8. 记录测试结果,进行总结。 这些步骤可以帮助你在 Linux 上搭建一个稳定可靠的测试环境。但还有许多细节需要注意,具体的操作过程需要根据你的需求来定制。 ### 回答2: 搭建Linux测试环境是为了开发和测试软件的过程中,能够模拟真实的生产环境进行测试。下面是搭建Linux测试环境的步骤: 1. 选择合适的Linux发行版:根据需要选择合适的Linux发行版,如Ubuntu、CentOS等,根据自身熟悉程度和软件要求进行选择。 2. 准备物理或虚拟机:根据需要,可以选择物理服务器或虚拟机来运行Linux操作系统。物理服务器需要购买服务器硬件并进行安装,而虚拟机可以在已有的物理服务器上创建。 3. 安装Linux操作系统:根据所选择的Linux发行版,参考官方文档或网络上的教程,进行操作系统的安装。 4. 配置网络:根据需求,配置网络连接,包括静态IP或动态IP的设置,DNS服务器配置等。 5. 安装必要的软件:根据测试需要,安装必要的软件和依赖项。可以通过包管理器来安装软件包,如apt-get、yum等,也可以手动下载源代码编译安装。 6. 配置测试环境:根据具体的测试要求,配置相应的测试环境,如数据库、web服务器、应用程序等。可以参考软件官方文档或在线资源进行配置。 7. 设置权限和安全:为了保护测试环境的安全性,设定适当的权限和防火墙规则,以防止未经授权的访问和攻击。 8. 进行测试:测试人员可以根据需求使用相应的测试工具和方法对搭建好的测试环境进行测试。 9. 进行维护和更新:定期进行维护和更新操作系统和软件的版本,修复已知的漏洞和bug,以保持测试环境的稳定性和安全性。 通过以上步骤,就可以搭建一个Linux测试环境,用于模拟真实的生产环境进行软件开发和测试工作。 ### 回答3: Linux是一个开源的操作系统,可以用来搭建各种测试环境。下面是搭建Linux测试环境的步骤: 1. 选择适合的Linux发行版:有很多种Linux发行版可供选择,如Ubuntu、CentOS、Debian等。根据自己的需求和经验,选择一个合适的发行版。 2. 安装Linux系统:下载选定的发行版的安装镜像,通过制作启动盘或者虚拟机来安装Linux系统。 3. 更新系统:安装完成后,运行系统更新命令,更新系统软件包和内核版本,确保系统是最新的。 4. 安装测试工具:根据自己的测试需求,选择相应的测试工具进行安装,如Jenkins、Selenium、JMeter等。可以通过包管理器(如apt、yum)或者直接从官方网站下载安装包进行安装。 5. 配置网络:根据测试需求,配置适当的网络环境。可以通过配置网络接口、DNS、DHCP等来模拟不同的网络环境,以进行测试。 6. 配置测试环境:根据测试需求,配置各种测试环境。例如,如果需要测试Web应用程序,需要安装和配置Nginx、Apache等服务器软件;如果需要测试数据库,需要安装和配置MySQL、PostgreSQL等数据库软件。 7. 创建测试数据:根据需要,创建测试数据并导入到测试环境中。可以使用SQL脚本、CSV文件等方式来创建和导入测试数据。 8. 编写测试脚本:根据测试需求,编写测试脚本或者测试用例。可以使用各种编程语言和测试框架来编写测试脚本,如Python和JUnit。 9. 运行测试:使用编写好的测试脚本来运行测试。根据需要,可以执行自动化测试或者手动测试。 10. 分析测试结果:分析测试结果,查看测试覆盖率、错误率和性能数据等。根据测试结果,优化系统和测试环境。 通过以上步骤,可以在Linux系统上搭建一个稳定且可靠的测试环境,用于进行各种类型的软件测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萧天天天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值