一、配置本地yum源
1.找到源⽂件
[root@localhost etc]# cd /etc.yum.repos.d/ 2.将所有的repo⽂件做成压缩包,命名为repo.tar.gz
[root@localhost yum.repos.d]# tar -zcvf repo.tar.gz ./*.repo
3.删除所有的repo⽂件 [root@localhost yum.repos.d]# rm -rf /etc/yum.repos.d/*.repo
4.使⽤光盘作为yum源仓库 (1) 在vmware中装载centos7.6光盘镜像
(2) 把光盘挂载到指定⽬录下
<1>删除/mnt⽬录下所有的⽂件 <2>lsblk <3>mount -o ro /dev/sr0 /mnt 挂载 选项 -o 表示挂载⽅式 ro=readonly rw=read and write
[root@localhost ~]# mount /dev/sr0 /mnt/ -o ro
[root@localhost ~]# 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
# 查看磁盘挂载情况
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
"#sda1 8:1 0 1G 0 part /boot
$#sda2 8:2 0 19G 0 part
"#centos-root 253:0 0 17G 0 lvm /
$#centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 8.8G 0 rom /mnt
<4>.解除挂载
[root@localhost ~]# umount /mnt
(3) 将挂载添加到开机启动⽂件中
chmod +x /etc/rc.local 添加权限
echo 'mount -o ro /dev/sr0 /mnt' >> /etc/rc.local 向⽂件中添加⼀⾏
5.编写本地repo⽂件
[root@localhost ~]# vim /etc/yum.repos.d/hh.repo
[local]
name=local0
baseurl=file:///mnt
gpgcheck=0
enable=1
6,清理缓存,查看源列表
# 清理缓存
[root@localhost ~]# yum clear all
[root@localhost ~]# yum makecache
# 查看源仓库列表
[root@localhost ~]# yum repolist
7.测试
[root@localhost ~]# yum -y install httpd
二、配置网络yum源
1.搜索镜像源知名站点
阿里云镜像站(阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com))
腾讯云镜像站(https://mirrors.cloud.tencent.com/)
2.根据官⽅提示配置yum源
# 复制阿⾥云提供的url,下载⽂件
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo
<https://mirrors.aliyun.com/repo/Centos-7.repo>
3.运⾏ yum makecache⽣成缓存 yum clear
4.查看源
[root@localhost yum.repos.d]# yum repolist all
....
repolist: 26,682
三、特定软件源配置
1.epel源配置
对官⽅和官⽹源的扩展,有些软件找不到
yum -y install epel-release
[root@localhost ~]# ls /etc/yum.repos.d/
20240714001.repo CentOS-Base.repo epel.repo epel-testing.repo
repo.tar.gz
# 安装⼩⽕⻋
[root@localhost ~]# yum -y install sl
[root@localhost ~]# sl
2.nginx源配置
百度搜索https://nginx.org/
[root@localhost ~]# 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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
# 创建缓存
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
# 安装并且检查
[root@localhost ~]# yum install nginx -y
# 启动服务
[root@localhost ~]# nginx
# 查看指令
[root@localhost ~]# whereis nginx
[root@localhost ~]# curl <http://localhost>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
...
# 停⽤nginx
[root@localhost ~]# nginx -s stop
四、自建yum仓库
1.缓存安装软件包
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releaserver # 定义软件包缓存路径
keepcache=1 #开启缓存
debuglevel=2
logfile=/var/log/yum.log
2.测试
yum -y. install tree
3.查找安装包
[root@localhost ~]# find /var/cache/ -name "*tree*" -type f
/var/cache/yum/x86_64/7/os/packages/tree-1.6.0-10.el7.x86_64.rpm
4.只下载不安装
[root@localhost ~]# yum install --downloadonly --downloaddir=./soft
samba
5.安装createrepo制作仓库的软件
[root@localhost ~]# yum -y install createrepo
6.把soft⽂件夹做成⼀个本地的⾃建仓库
[root@localhost ~]# createrepo soft/
7.在/etc/yum.repos.d/下创建soft.repo
vim /etc/yum.repos.d/soft.repo
[soft]
name=soft_local
gpgcheck=0
baseurl=file:///root/soft
enable=1
# 创建缓存
[root@localhost soft]# yum clean all
[root@localhost soft]#yum makecache
# 再次安装samba
[root@localhost soft]# yum -y install samba