【yum仓库配置】

yum包软件管理

  • yum网络仓库链接
    • 1.本地和清华网络仓库配置
    • 2.阿里云yum源网络配置
      • 增加yum软件仓库
    • 3.设置yum源优化
    • 4.yum软件仓库shell脚本

yum网络仓库链接

https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ 清华大学开源软件镜像站
https://developer.aliyun.com/mirror/阿里云官方镜像站(软件仓库)

1.本地和清华网络仓库配置

  • 挂载
#临时挂载,立刻生效
[root@student ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@student ~]# ls /mnt
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
#查看临时挂载文件类型iso9660
[root@student ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  471M     0  471M   0% /dev
tmpfs          tmpfs     487M     0  487M   0% /dev/shm
tmpfs          tmpfs     487M  8.4M  478M   2% /run
tmpfs          tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/sda3      xfs        18G  5.4G   13G  31% /
/dev/sda1      xfs       297M  151M  146M  51% /boot
tmpfs          tmpfs      98M  8.0K   98M   1% /run/user/42
tmpfs          tmpfs      98M     0   98M   0% /run/user/0
/dev/sr0       iso9660   4.4G  4.4G     0 100% /mnt
#用久挂载
[root@student ~]# vim /etc/fstab
/dev/cdrom /mnt iso9660 defaults        0 0
[root@student ~]# mount -a
[root@student ~]# ls /mnt/Packages/ |wc -l
4068


#修改yum仓库配置文件
[root@student ~]# vim /etc/yum.repos.d/local.repo	
[local] 				#[ ]内的是本地仓库的名字
name=local_centos
baseurl=file:///mnt/    #baseurl 仓库的位置,如果是本地配置为客户端,则要以"file://"开头,
enabled=1 				#enabled 是否启用这个仓库,1为起用,0为禁用
gpgcheck=0

[tuna.tsinghua.edu.cn]		#[ ]内的是网络仓库的名字
name=tuna.tsinghua.edu.cn
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ 		#baseurl 仓库的位置,清华大学开源软件镜像站
enabled=1				#enabled 是否启用这个仓库,1为起用,0为禁用
gpgcheck=0
#查询yum仓库软件包数量
[root@student ~]# yum repolist			
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
local                                                                            | 3.6 kB  00:00:00     
tuna.tsinghua.edu.cn                                                             | 3.6 kB  00:00:00     
(1/2): tuna.tsinghua.edu.cn/group_gz                                             | 153 kB  00:00:01     
(2/2): tuna.tsinghua.edu.cn/primary_db                                           | 6.1 MB  00:00:04     
repo id                                          repo name                                        status
local                                            local_centos                                      4,067
tuna.tsinghua.edu.cn                             tuna.tsinghua.edu.cn                             10,072
repolist: 14,139

2.阿里云yum源网络配置

[root@student ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo		#下载阿里yum: http://mirrors.aliyun.com/repo/Centos-7.repo 
--2022-09-27 23:54:17--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 202.104.186.229, 121.9.246.115, 121.9.246.110, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|202.104.186.229|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to:/etc/yum.repos.d/CentOS-Base.repo’

100%[==============================================================>] 2,523       --.-K/s   in 0s      

2022-09-27 23:54:17 (475 MB/s) -/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
[root@student ~]# yum clean all		#清理缓存
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
Other repos take up 55 M of disk space (use --verbose for details)
[root@student ~]# yum repolist		#查询yum包数量
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                              repo name                                                    status
base/7/x86_64                        CentOS-7 - Base - mirrors.aliyun.com                         10,072
extras/7/x86_64                      CentOS-7 - Extras - mirrors.aliyun.com                          516
!local                               local_centos                                                  4,067
updates/7/x86_64                     CentOS-7 - Updates - mirrors.aliyun.com                       4,244
repolist: 18,899



增加yum软件仓库

[root@student ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                              repo name                                                    status
base/7/x86_64                        CentOS-7 - Base - mirrors.aliyun.com                         10,072
extras/7/x86_64                      CentOS-7 - Extras - mirrors.aliyun.com                          515
updates/7/x86_64                     CentOS-7 - Updates - mirrors.aliyun.com                       4,300
repolist: 14,887
[root@student ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2022-10-16 01:15:33--  https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 106.227.23.224, 202.104.186.229, 202.104.186.225, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|106.227.23.224|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’

100%[==============================================================>] 664         --.-K/s   in 0s      

2022-10-16 01:15:33 (3.57 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]

[root@student ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
epel                                                                             | 4.7 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                      |  97 kB  00:00:01     
(2/3): epel/x86_64/updateinfo                                                    | 1.0 MB  00:00:09     
(3/3): epel/x86_64/primary_db                                                    | 7.0 MB  00:01:02     
repo id                           repo name                                                       status
base/7/x86_64                     CentOS-7 - Base - mirrors.aliyun.com                            10,072
epel/x86_64                       Extra Packages for Enterprise Linux 7 - x86_64                  13,735
extras/7/x86_64                   CentOS-7 - Extras - mirrors.aliyun.com                             515
updates/7/x86_64                  CentOS-7 - Updates - mirrors.aliyun.com                          4,300
repolist: 28,622

报错
已加载插件:fastestmirror, langpacks File contains no section headers. file: file:///etc/yum.repos.d/con,
解决办法:https://blog.csdn.net/liangkaiping0525/article/details/88875272

3.设置yum源优化

[root@student ~]# vim /etc/yum.repos.d/local.repo

[local]
name=local_centos
baseurl=file:///mnt/centos
enabled=1
gpgcheck=0
priority=1		#1-99,数字越小,优先级越高

4.yum软件仓库shell脚本

#!/bin/bash
#yum软件仓库自动安装shell脚本
echo "正在运行yum软件仓库shell脚本"
echo "初始话yum软件仓库,卸载挂载"
umount /mnt
rm -rf /mnt/*
rm -rf /etc/yum.repos.d/*
yum repolist |tail -1
mount /dev/cdrom /mnt &> /dev/null
#永久挂载
echo "/dev/cdrom /mnt iso9660 defaults        0 0"  >> /etc/fstab
mount -a &> /dev/null
echo "永久挂载成功"
df -hT |tail -1
#创建/etc/yum.repos.d/local.repo文件
touch /etc/yum.repos.d/local.repo
echo "[local] 
name=local_centos
baseurl=file:///mnt/
enabled=1
gpgcheck=0
priority=1
[tuna.tsinghua.edu.cn]  
name=tuna.tsinghua.edu.cn
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/                
enabled=1
gpgcheck=0
" > /etc/yum.repos.d/local.repo
echo "yum软件仓库配置完成"
echo "查看yum仓库包数量:" && yum repolist | tail -1
echo "正在添加epel包"
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo &> /dev/null
echo "查看yum仓库包数量:" && yum repolist | tail -1


#运行效果:
[root@test opt]# ./yum01.sh
正在运行yum软件仓库shell脚本
初始话yum软件仓库,卸载挂载
repolist: 0
永久挂载成功
/dev/sr0       iso9660   4.4G  4.4G     0 100% /mnt
yum软件仓库配置完成
查看yum仓库包数量:
repolist: 14,139
正在添加epel包
查看yum仓库包数量:
repolist: 27,874


你可能感兴趣的:(红帽rhcsa,linux,服务器,运维,1024程序员节)