实训day7(7.16)

一、yum源

Yum 源安装软件包是在 Linux 系统中一种非常便捷和常用的软件安装方式

Yum(Yellowdog Updater, Modified)是一个在众多 Linux 发行版中广泛使用的软件包管理器。它通过预先配置好的软件源(Yum 源)来获取软件包的信息和进行安装。

Yum 源的作用:Yum 源就像是一个软件仓库,包含了各种各样的软件包及其相关的依赖信息。常见的 Yum 源有系统默认提供的官方源,也有第三方维护的源。

Yum 安装软件包的优点:安装一个软件包时,如果它依赖于其他的软件包,Yum 会自动安装这些依赖,无需您手动逐个查找和安装。

二、了解常见的网络yum源

华为云 yum 源:例如对于 centos7 系统,其.repo 文件内容如下:

#centos-base.repo

#

# the mirror system uses the connecting ip address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. you should use this for centos updates

# unless you are manually picking other mirrors.

#

# if the mirrorlist= does not work for you, as a fallback you can try the

# remarked out baseurl= line instead.

#

#

​

(base)

name=centos7

baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/

gpgcheck=0

​

# released updates

(updates)

name=centos-$releasever-updates-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7

​

# additional packages that may be useful

(extras)

name=centos-$releasever-extras-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7

​

# additional packages that extend functionality of existing packages

(centosplus)

name=centos-$releasever-plus-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

其中,$releasever表示系统版本,$basearch表示系统架构(如 x86_64)。

中国科技大学源:如http://centos.ustc.edu.cn/centos/。使用中科大源的方法之一是,先进入/etc/yum.repos.d/目录,重命名 centos 自带的 yum 源文件(如mv centos-base.repo centos-base.repo.save),然后执行wget http://mirrors.ustc.edu.cn/centos/centos-base.5.mirrors.repo -o /etc/yum.repos.d/centos-base.repo,最后运行yum makecache。

网易开源镜像:例如http://mirrors.163.com/centos/。使用网易源可参考如下步骤:进入/etc/yum.repos.d/目录,重命名 centos 自带的 yum 源文件(如mv centos-base.repo centos-base.repo.save),执行wget http://mirrors.sohu.com/help/centos-base-sohu.repo,再运行yum makecache。

阿里云镜像:http://mirrors.aliyun.com/repo/centos-7.repo(适用于 centos7 系统)。

配置网络 yum 源的具体步骤可能因 Linux 发行版和版本而有所不同。一般来说,需要将相应的.repo 文件下载或创建到/etc/yum.repos.d/目录下,然后运行相关命令更新 yum 缓存。

三、本地和网络yum源的配置

Yum(全称为 Yellowdog Updater, Modified)是一个在 Fedora、CentOS、BCLinux、RedHat 等 Linux 发行版中的软件包管理器。它基于 RPM 包管理,能够自动处理依赖性关系,一次安装所有依赖的软件包。配置 Yum 源可以让系统通过指定的服务器或本地镜像来获取软件包。以下是本地和网络

1.配置网络 Yum 源(以 CentOS 7 系统,使用华为云 yum 源为例)

查看本地操作系统版本,执行指令:cat /etc/redhat-release。

打开华为云开源镜像站(https://mirrors.huaweicloud.com/home),找到对应的操作系统版本的.repo 文件链接(如:https://repo.huaweicloud.com/repository/conf/centos7.repo )。

进入服务器的 /etc/yum.repos.d/ 目录,可以执行以下命令下载并编辑.repo 文件:

cd /etc/yum.repos.d/

vi local.repo

按 i 键进入编辑模式,输入以下内容(注意将 $releasever 替换成实际的操作系统版本号):

#centos-base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fallback you can try the

# remarked out baseurl= line instead.

#

#

​

(base)

name=centos7

baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/

gpgcheck=0

# released updates

(updates)

name=centos-$releasever-updates-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7

# additional packages that may be useful

(extras)

name=centos-$releasever-extras-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7

# additional packages that extend functionality of existing packages

(centosplus)

name=centos-$releasever-plus-repo.huaweicloud.com

baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/

# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

编辑完成后,按 Esc 键,输入 :wq 保存并退出。

执行以下命令更新 Yum 源:

yum clean all:清除原有缓存。

yum makecache:构建新的缓存。

2.配置本地 Yum 源

挂载 ISO 镜像文件(假设镜像文件已上传至服务器):

创建挂载点:mkdir /opt/centos。

挂载镜像:mount /your_iso_file_path /opt/centos (将 /your_iso_file_path 替换为实际的镜像文件路径)。

进入 /etc/yum.repos.d/ 目录,备份原有的.repo 文件(以防需要恢复):mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old/ 。

创建并编辑本地 Yum 源配置文件:

vi /etc/yum.repos.d/local.repo

输入以下内容:

(centos)

name=centos # Yum 源的名称,可自定义

baseurl=file:///opt/centos # 本地 Yum 源的位置,指向挂载点目录

gpgcheck=0 # 不进行 GPG 签名检查

enabled=1 # 启用该 Yum 源

编辑完成后保存并退出。

执行 yum clean all 命令清空缓存。

执行 yum makecache 命令重建缓存。

配置完成后,就可以使用 Yum 命令来安装、更新软件包了。

3.配置局域网 Yum 源(需要至少两台服务器,一台作为源服务器,其他机器作为客户端):

配置局域网 Yum 源(服务器端)

按照上述本地 Yum 源的配置方法,在源服务器上完成本地 Yum 源的配置。

安装并启动 HTTP 服务(如 Apache HTTP Server 或 Nginx 等),将挂载的 ISO 镜像目录通过 HTTP 服务共享出去。

配置客户端机器的 Yum 源:

编辑 /etc/yum.repos.d/ 目录下的.repo 文件,添加类似以下内容:

(centos)

name=centos

baseurl=http://源服务器 IP/共享目录 # 替换为实际的源服务器 IP 和共享目录

gpgcheck=0

enabled=1

然后在客户端机器上执行 yum clean all 和 yum makecache 命令更新缓存。

常见的一些网络 Yum 源有阿里云、华为云、网易等提供的开源镜像站点。例如,阿里云的 CentOS 7 yum 源地址为:http://mirrors.aliyun.com/repo/centos-7.repo 。

配置本地yum源

rpm -ivh xxx //rpm需要手动添加依赖

能够使用yum工具安装软件包

yum不止执行安装,还可以自动处理依赖关系

yum是基于rpm的,相当于rpm升级版,自动解决依赖关系

ls -l /etc/yum.repos.d/ //查看现有的yum仓库镜像

(1)打包,做成一个tar压缩包

yum repolist all

tar -czvf /etc/yum.repos.d/bak.tar.gz /etc/yum.repos.d/*

rm -rf /etc/yum.repos.d/*.repo

ls -l /etc/yum.repos.d/

yum repolist all

yum clean all //清空缓存

yum makecache //生成缓存

(2)删除mnt目录下的所有文件

rm -rf /mnt/*

ls /mnt/

(3)将光盘数据挂载到/mnt目录中,就可以在该目录中读取光盘内容

lsblk //找到sr0

mount -o ro /dev/sr0 /mnt //以只读方式挂载光盘

(4)设置开机自挂载

echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local //开机自动挂载

(5)规定软件包查找位置

[root@1 ~]# vim /etc/yum.repos.d/hh.repo

[a]

name=a

baseurl=file:///mnt

gpgcheck=0

[root@1 ~]# yum clean all

已加载插件:fastestmirror

正在清理软件源: a

Cleaning up everything

Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

Cleaning up list of fastest mirrors

[root@1 ~]# yum makecache

已加载插件:fastestmirror

Determining fastest mirrors

a | 3.6 kB 00:00:00

(1/4): a/group_gz | 166 kB 00:00:00

(2/4): a/primary_db | 5.9 MB 00:00:00

(3/4): a/filelists_db | 6.9 MB 00:00:00

(4/4): a/other_db | 2.5 MB 00:00:00

(3)epel源配置

对官⽅和官⽹源的扩展,有些软件找不到

[root@1 ~]# yum -y install epel-release.noarch

[root@1 ~]# ls /etc/yum.repos.d/

CentOS-Base.repo epel.repo hh.repo.b

CentOS-Base.repo.backup epel-testing.repo

[root@1 ~]# yum -y install sl //安装小火车

[root@1 ~]# sl

 

(4)nginx源配置

(1)移除epel源

[root@1 ~]# rm -rf /etc/yum.repos.d/epel*

[root@1 ~]# ls /etc/yum.repos.d/

CentOS-Base.repo CentOS-Base.repo.backup hh.repo.b

[root@1 ~]# yum clean all

[root@1 ~]# yum makecache

(2)百度搜索nginx镜像

nginx news

 

[root@1 ~]# 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

module_hotfixes=true //启用模块热修复功能

[root@1 ~]# yum clean all

[root@1 ~]# yum makecache

[root@1 ~]# yum list | grep nginx

nginx.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx-stable

nginx-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-geoip.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-geoip-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-image-filter.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-image-filter-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-njs.x86_64 1:1.26.1+0.8.5-2.el7.ngx nginx-stable

nginx-module-njs-debuginfo.x86_64 1:1.26.1+0.8.5-2.el7.ngx nginx-stable

nginx-module-perl.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-perl-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-xslt.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-module-xslt-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable

nginx-nr-agent.noarch 2.0.0-12.el7.ngx nginx-stable

pcp-pmda-nginx.x86_64

[root@1 ~]# yum -y install nginx

[root@1 ~]# nginx //启动服务

[root@1 ~]# whereis nginx //查看指令

nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

[root@1 ~]# curl http://localhost //访问服务器

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

html { color-scheme: light dark; }

body { width: 35em; margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif; }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

​

<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>

​

<p><em>Thank you for using nginx.</em></p>

</body>

</html>

四、自建yum源仓库

[root@1 ~]# vim /etc/yum.conf

keepcache=1 //将0改为1 YUM 在下载软件包后保留其缓存

[root@1 ~]# yum remove -y nginx //卸载nginx

[root@1 ~]# yum -y install nginx //安装nginx

[root@1 ~]# find /var/cache/ -name "*nginx*" -type f //查看缓存文件

/var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.26.1-2.el7.ngx.x86_64.rpm

[root@1 ~]# yum install --downloadonly --downloaddir=./soft samba //只下载不安装

--downloadonly 选项表示只进行下载操作,不进行安装。

--downloaddir=./soft 则指定了下载的软件包保存的目录为当前目录下的 soft 文件夹。

......

总计 1.2 MB/s | 9.0 MB 00:00:07

exiting because "Download Only" specified

[root@1 ~]# ls soft/

avahi-libs-0.6.31-20.el7.x86_64.rpm pytalloc-2.1.16-1.el7.x86_64.rpm

cups-libs-1.6.3-52.el7_9.x86_64.rpm python-tdb-1.3.18-1.el7.x86_64.rpm

gnutls-3.3.29-9.el7_6.x86_64.rpm samba-4.10.16-25.el7_9.x86_64.rpm

libldb-1.5.4-2.el7.x86_64.rpm samba-client-libs-4.10.16-25.el7_9.x86_64.rpm

libtalloc-2.1.16-1.el7.x86_64.rpm samba-common-4.10.16-25.el7_9.noarch.rpm

libtdb-1.3.18-1.el7.x86_64.rpm samba-common-libs-4.10.16-25.el7_9.x86_64.rpm

libtevent-0.9.39-1.el7.x86_64.rpm samba-common-tools-4.10.16-25.el7_9.x86_64.rpm

libwbclient-4.10.16-25.el7_9.x86_64.rpm samba-libs-4.10.16-25.el7_9.x86_64.rpm

nettle-2.7.1-9.el7_9.x86_64.rpm trousers-0.3.14-2.el7.x86_64.rpm

pyldb-1.5.4-2.el7.x86_64.rpm

安装createrepo

createrepo 是一个用于创建 YUM 软件仓库的命令行工具。

它的主要作用是根据指定目录中的 RPM 软件包生成元数据,包括软件包的依赖关系、版本信息等,以便 YUM 客户端能够正确地解析和安装所需的软件。

以下是一个使用 createrepo 的示例:

假设您有一个目录 /opt/packages ,其中包含了一些 RPM 软件包。您可以在该目录下运行以下命令来创建软件仓库:

createrepo /opt/packages

执行完该命令后,createrepo 会在 /opt/packages 目录下生成一些元数据文件,如 repodata 目录,其中包含了 repomd.xml 等重要的配置和描述文件。

这样,您就可以将这个目录配置为 YUM 源,让客户端能够从这里获取和安装软件包。

[root@1 ~]# yum -y install createrepo

[root@1 ~]# createrepo soft/ //把soft⽂件夹做成⼀个本地的⾃建仓库

Spawning worker 0 with 19 pkgs

Workers Finished

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

[root@1 ~]# ls

soft

[root@1 ~]# cd soft/

[root@1 soft]# ls

avahi-libs-0.6.31-20.el7.x86_64.rpm pytalloc-2.1.16-1.el7.x86_64.rpm

cups-libs-1.6.3-52.el7_9.x86_64.rpm python-tdb-1.3.18-1.el7.x86_64.rpm

gnutls-3.3.29-9.el7_6.x86_64.rpm repodata

libldb-1.5.4-2.el7.x86_64.rpm samba-4.10.16-25.el7_9.x86_64.rpm

libtalloc-2.1.16-1.el7.x86_64.rpm samba-client-libs-4.10.16-25.el7_9.x86_64.rpm

libtdb-1.3.18-1.el7.x86_64.rpm samba-common-4.10.16-25.el7_9.noarch.rpm

libtevent-0.9.39-1.el7.x86_64.rpm samba-common-libs-4.10.16-25.el7_9.x86_64.rpm

libwbclient-4.10.16-25.el7_9.x86_64.rpm samba-common-tools-4.10.16-25.el7_9.x86_64.rpm

nettle-2.7.1-9.el7_9.x86_64.rpm samba-libs-4.10.16-25.el7_9.x86_64.rpm

pyldb-1.5.4-2.el7.x86_64.rpm trousers-0.3.14-2.el7.x86_64.rpm

[root@1 soft]# vim /etc/yum.repos.d/soft.repo

[soft]

name=soft

baseurl=file:///root/soft

gpgcheck=0

enable=1

[root@1 soft]# yum clean all

已加载插件:fastestmirror

正在清理软件源: extras nginx-stable os soft updates

Cleaning up everything

Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

Cleaning up list of fastest mirrors

[root@1 soft]# yum makecache

[root@1 soft]# yum -y install samba //全程直接下载,使用我们自己创建的yum仓库

  • 14
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值