1.学习内容:
了解yum源安装软件包的有点
了解常见的网络yum源
掌握本地和网络yum源的配置
能够使用yum工具安装软件包
2.yum的优点:
rpm安装 需要我们自己解决依赖关系
源码安装 configure make make install
yum不仅执行安装还会自动处理依赖关系
3.分类:
本地yum源
yum仓库在本地,系统光盘/镜像文件
网络yum源
特定软件
nginx
mysql
Zabbix
4.配置本地yum源
(1)查看现有的yum仓库镜像
[root@diyi ~]# ls -l /etc/yum.repos.d/
显示现有镜像
[root@diyi ~]# yum repolist all
(2)对现有的镜像进行打包存放到/bbb.tar.gz中
[root@diyi ~]# tar -zcvf /etc/yum.repos.d/bbb.tar.gz /etc/yum.repos.d/*
(3)删除原有的镜像
[root@diyi ~]# rm -rf /etc/yum.repos.d/*.repo
//所有yum源都已经被删除
(4)使用光盘作为yum源仓库
(5)删除/mnt目录下的所有文件
[root@diyi ~]# rm -rf /mnt/*
(6)将光盘数据挂载到/mnt目录中,就可以在该目录中读取光盘的数据
选项 -o 表示挂载⽅式
[root@diyi ~]# mount -o ro /dev/sr0 /mnt/
[root@diyi ~]# ls /mnt/
(7)[root@diyi ~]# lsblk //查看磁盘挂载情况
(8)将挂载添加到开机启动⽂件中
开机自动挂载
[root@diyi ~]# echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local
[root@diyi ~]# vim /etc/rc.local
(9)编写本地repo⽂件
1)创建⼀个repo⽂件
2)编辑内容
yum 仓库的格式
[root@diyi ~]# vim /etc/yum.repos.d/local.repo
(10)[root@diyi ~]# yum clean all //清理缓存
(11)[root@diyi ~]# yum makecache //创建缓存
(12)[root@diyi ~]# yum repolist
- 配置网络源
在网站里直接下载
[root@diyi ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@diyi ~]# ls /etc/yum.repos.d/
[root@diyi ~]# yum makecache
[root@diyi ~]# yum repolist
[root@diyi ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
再次安装httpd
[root@diyi ~]# yum -y install httpd
Man 5 yum.conf填写配置文件的的帮助文件
epel源配置
[root@diyi ~]# cp /etc/yum.repos.d/CentOS-Base.repo.backup /etc/yum.repos.d/CentOS-Base.repo
[root@diyi ~]# yum makecache
[root@diyi ~]# yum -y install epel-release
[root@diyi ~]# yum -y install sl
[root@diyi ~]# sl
Nginx,python3已经在epel中安装
[root@diyi ~]# yum list|grep nginx
[root@diyi ~]# yum list|grep python3
[root@diyi ~]# yum -y install nginx.x86_64
[root@diyi ~]# nginx
[root@diyi ~]# curl http://diyi
[root@diyi ~]# nginx -s stop
[root@diyi ~]# curl http://diyi
[root@diyi ~]# yum -y remove nginx
移除elep
[root@diyi ~]# rm -rf /etc/yum.repos.d/epel*
[root@diyi ~]# yum clean all
[root@diyi ~]# yum makecache
安装稳定版本:
[root@diyi ~]# vim /etc/yum.repos.d/nginx.repo //编写repo文件
[root@diyi ~]# yum clean all
[root@diyi ~]# yum makecache //创建缓存
[root@diyi ~]# yum list|grep nginx
[root@diyi ~]# yum install nginx -y //检查并安装
[root@diyi ~]# nginx //启动nginx
[root@diyi ~]# whereis nginx //查看指令
[root@diyi ~]# curl http://localhost //访问服务器
[root@diyi ~]# nginx -s stop //停用nginx
[root@diyi ~]# curl http://localhost //访问测试
缓存某些软件到本地
[root@diyi ~]# vim /etc/yum.conf
卸载,然后安装nginx 查看缓存⽂件
[root@diyi ~]# yum -y remove nginx
安装
[root@diyi ~]# yum install nginx -y
查找安装包
[root@diyi ~]# find /var/cache/ -name "*tree*" -type f
[root@diyi ~]# find /var/cache/ -name "*nginx*" -type f
6.创建本地自创仓库
1)下载samba安装包
只是下载没有安装
[root@diyi ~]# yum install --downloadonly --downloaddir=./soft/ samba //下载samba安装包
[root@diyi ~]# yum -y install createrepo
查看rpm文件
[root@diyi ~]# ls soft/
2)使用createrepo指令
[root@diyi ~]# yum -y install createrepo
把soft文件夹做成一个本地自建仓库
[root@diyi ~]# createrepo soft/
3)在soft目录中发现repodata
4)在/etc/yum.repos.d/soft.repo下写入
5)建立缓存
yum clean all
yum makecache
6)yum -y install samba