一、yum源配置
1.将yum.repos.d中的 .repo文件删除
rm -rf /etc/yum.repos.d/*.repo
2.配置编辑本地镜像文件
3.实现自动挂载
二、配置华为云镜像
1.打开华为云开源镜像站(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>
(5)自建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
yum -y install createrepo
createrepo soft/
vi /etc/yum.repos.d/soft.repo
[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仓库