7.16 yum源学习

1.yum源安装

1. 将原有的yum备份或改名

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# ls

dvd.repo

[root@localhost yum.repos.d]# mv dvd.repo dvd.repo.b

[root@localhost yum.repos.d]# ls

dvd.repo.q

[root@localhost yum.repos.d]# yum repolist

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

repolist: 0     //yum已全部被清除

2. 把光盘挂载到指定⽬录下

[root@localhost ~]# rm -rf /mnt/*

[root@localhost ~]# mount -o ro /dev/sr0 /mnt                     //-o表示挂载方式,ro表示readonly

将光盘数据挂载到/mnt目录中,就可以在该目录中读取光盘的数据

[root@localhost ~]# df -h

3. 将挂载添加到开机启动⽂件中

[root@localhost ~]# vim /etc/rc.local                  //开机自动执行挂载

mount -o ro /dev/sr0 /mnt

或[root@localhost ~]# vim /etc/fstab                       //也是开机自动挂载

/dev/cdrom  /mnt    iso9660     defaults 0 0

4. 编写本地repo⽂件

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

[local]

name=local

baseurl=file:///mnt

gpgcheck=0

enable=1

5. 清理缓存,查看源列表

[root@localhost ~]# yum clean all               //清除缓存

[root@localhost ~]# yum makecache        //生成缓存

6. 测试yum

[root@localhost ~]# yum -y remove httpd

[root@localhost ~]# yum -y install httpd

2.配置网络源

1.阿里云

1.1 搜索阿⾥镜像源
1.2.根据官⽅提示配置yum源

centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站 (aliyun.com)
https://developer.aliyun.com/mirror/centos
1.3 复制阿⾥云提供的url,下载⽂件

[root@mm ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 

[root@mm ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

[root@tdr~]#wget -O /etc/ yum.repos.d/ CentOS-Base.repo https://mirrors.aliyun.com/repo/ Centos-7.repo

[root@tdr ~]# yum clean all

[root@tdr ~]# yum makecache

[root@tdr ~]# 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

安装稳定版本

[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,不用再次下载

  • 10
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值