一、本地yum源备份
1.yum优点
Rpm安装(下载软件,单独安装,需要解决依赖关系)
源码安装 confgure make make install
yum基于rpm,相当于rpm升级版,⾃动解决依赖关系
4.分类
(1)本地yum源
yum仓库在本地,系统光盘/镜像⽂件
(2)⽹络yum源
aliyun 163源 sohu源 清华源 centos源 redhat源 epel源
(3)特定软件
nginx mysql zabbi
2.找到源⽂件
3.将所有的repo⽂件做成压缩包,命名为repo.tar.gz
# 当前在etc⽬录,跳转到yum.repos.d⽬录
[root@localhost etc]# cd yum.repos.d/
#查看默认的源⽂件
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
mysql-community.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community[1]debuginfo.repo
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# tar -zcvf repo.tar.gz ./*.repo
./CentOS-Base.repo
./CentOS-CR.repo
./CentOS-Debuginfo.repo
./CentOS-fasttrack.repo
./CentOS-Media.repo
./CentOS-Sources.repo
./CentOS-Vault.repo
./CentOS-x86_64-kernel.repo
./mysql-community-debuginfo.repo
./mysql-community.repo
./mysql-community-source.repo
您在 /var/spool/mail/root 中有新邮件
# 查看⽂件信息
[root@localhost yum.repos.d]# ls
3.删除所有的repo⽂件
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
mysql-community.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community[1]debuginfo.repo repo.tar.gz
[root@localhost yum.repos.d]# rm -rf ./*.repo
您在 /var/spool/mail/root 中有新邮件
[root@localhost yum.repos.d]# ls
repo.tar.gz
[root@localhost yum.repos.d]#
二、本地yum源的配置
1.查看本地源
Loading mirror speeds from cached hostfile
repolist: 0
# 所有的yum都已经被删除了
2.使⽤光盘作为yum源仓库 1.在vmware中装载centos7.6光盘镜像
3.把光盘挂载到指定⽬录下
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
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM[1]GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7
TRANS.TBL
4.查看磁盘挂载情况
[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
您在 /var/spool/mail/root 中有新邮件
5.将挂载添加到开机启动⽂件中
root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# echo 'mount -o or /dev/sr0 /mnt' >> /etc/rc.local
[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# ls -l /etc/rc.local
lrwxrwxrwx. 1 root root 13 6⽉ 16 20:18 /etc/rc.local -> rc.d/rc.local
或者:
[root@localhost ~]# echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local
[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
6.将原有的yum备份或改名
[root@hjm ~]# cd /etc/yum.repos.d/
[root@tdr yum.repos.d]# ls
haha.repo
[root@hjm yum.repos.d]# mv haha.repo haha.repo.q
[root@tdr yum.repos.d]# ls
haha.repo.q
[root@hjm yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0 //yum已全部被清除
(1)把光盘挂载到指定⽬录下
[root@hjm ~]# rm -rf /mnt/*
[root@tdr ~]# mount -o ro /dev/sr0 /mnt //-o表示挂载方式,ro表示readonly
将光盘数据挂载到/mnt目录中,就可以在该目录中读取光盘的数据
[root@hjm ~]# df -h
(2)将挂载添加到开机启动⽂件中
[root@hjm ~]# vim /etc/rc.local //开机自动执行挂载
mount -o ro /dev/sr0 /mnt
或[root@tdr ~]# vim /etc/fstab //也是开机自动挂载
/dev/cdrom /mnt iso9660 defaults 0 0
(3)编写本地repo⽂件
[root@hjm ~]# vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enable=1
(4)清理缓存,查看源列表
[root@hjm ~]# yum clean all //清除缓存
[root@hjm ~]# yum makecache //生成缓存
(5)测试yum
[root@hjm ~]# yum -y remove httpd
[root@hjm ~]# yum -y install httpd
4.配置网络源
1.阿里云
[root@hjm ~]# w3get -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@hjm ~]# yum clean all
[root@hjm ~]# yum makecache
[root@hjm ~]# yum list | grep python3
2.腾讯云
[root@localhost yum.repos.d]# rm -rf /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.cloud.tencent.com/repo/centos7_base.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
3.epel源配置
对官⽅和官⽹源的扩展,有些软件找不到
[root@localhost ~]# yum -y install epel-release
安装⼩⽕⻋
[root@localhost ~]# yum -y install sl
移除epel源,如果不⾏就全清空
[root@localhost ~]# rm -rf /etc/yum.repos.d/epel.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
4.安装特定软件源配置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
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# nginx //启动服务
[root@localhost ~]# whereis nginx //查看指令
浏览器访问本机IP
[root@localhost ~]# nginx -s stop //停⽤nginx
5.自建yum源仓库
[root@localhost ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever //定义软件包缓存路径
keepcache=1 //修改为1,开启缓存
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?
project_id=23&ref=http://bugs.centos.org/bug_report_page.php?
category=yum
distroverpkg=centos-release
卸载,然后安装nginx 查看缓存⽂件
[root@localhost ~]# yum -y remove nginx.x86_64 //卸载
[root@localhost ~]# yum install nginx -y //安装
[root@localhost ~]# find /var/cache/ -name "*nginx*" -type f //查找安装包
/var/cache/yum/x86_64/7/os/packages/tree-1.6.0-10.el7.x86_64.rpm
只下载不安装
[root@localhost ~]# yum install --downloadonly --downloaddir=./soft samba
[root@localhost ~]# ls soft/ //安装包的位置
(1)安装createrepo制作仓库的软件
[root@localhost ~]# yum -y install createrepo
(2)把soft⽂件夹做成⼀个本地的⾃建仓库
[root@localhost ~]# createrepo soft/
[root@localhost ~]# cd soft/
[root@localhost soft]# ls
(3)在/etc/yum.repos.d/下创建soft.repo
[root@localhost soft]# rm -rf /etc/yum.repos.d/*.repo //删除其他仓库⽂件
[root@localhost soft]# 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
[root@localhost soft]# yum -y install samba //再次安装samba,不用再次下载
5.缓存某些软件到本地:
1.缓存安装软件包
下⼀次还⽤
国外源
2.如何缓存
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releaserver # 定义软件包缓存路径
keepcache=1 #开启缓存
debuglevel=2
logfile=/var/log/yum.log
1.vim /etc/yum.cong
2.keepcache=1
3.测试 yum -y. install tree
4./var/cache/yum/x66_32/7/base/packages/treeexxxxxx.rpm
[root@hjm ~]# vim /etc/yum.conf
3.卸载,然后安装nginx 查看缓存⽂件
[root@hjm ~]# yum -y remove nginx.x86_64
# 安装
[root@hjm ~]# yum install nginx -y
# 查找安装包
[root@hjm ~]# find /var/cache/ -name "*tree*" -type f
/var/cache/yum/x86_64/7/os/packages/tree-1.6.0-10.el7.x86_64.rpm
您在 /var/spool/mail/root 中有新邮件
[root@hjm ~]# 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@hjm ~]#
4.只下载不安装
[root@hjm ~]# yum install --downloadonly --downloaddir=./soft/ samba
6.自建yum仓库:
1.安装createrepo制作仓库的软件
[root@hjm ~]# yum -y install createrepo
2.把soft⽂件夹做成⼀个本地的⾃建仓库
[root@hjm ~]# createrepo soft/
[root@hjm ~]# cd soft/
[root@mm 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
3.在/etc/yum.repos.d/下创建 soft.repo
vim /etc/yum.repos.d/soft.repo
[soft]
name=soft
baseurl=file:///root/soft/
gpgcheck=0
enable=1
yum clean all
yum makecache
4.再次安装samba
[root@hjm soft]# yum -y install samba