Centos 6,7 YUM本地源和网络源配置

前言

YUM(全称为 Yellow dog Updater, Modified)是一个在Fedora中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载和安装。文章以RHEL(Red Hat Enterprise Linux)配置YUM源为例分享YUM常用命令技巧以及如何搭建ISO本地源和CentOS YUM源。

YUM是一个安装,卸载和搜索软件包的工具

YUM常用命令

列举平时做常用的几组YUM命令

1
2
3
4
5
6
7
8
9
10
11
12
13
#清除缓存目录
yum clean all
#更新缓存
yum makecache
#使用YUM查找软件包
yum search telnet
#用YUM安装软件包
yum install telnet
#用YUM删除软件包
yum remove telnet
#安装更新软件
yum update
yum update telnet

本地YUM源

无论直接加载ISO还是拷贝文件来搭建本地YUM源都是很简单的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#通过ISO镜像挂载或者复制文件
mount -o loop rhel-server-6.3-x86_64-dvd.iso /mnt
mkdir /tmp/repo
cp -r /mnt/* /tmp/repo

#编辑本地YUM源文件
cd /etc/yum.repos.d/
#清除老配置,rm -rf *
vi local.repo

[rhel6.3]
name=rhel6.3
baseurl=file:///tmp/repo
enabled=1
gpgcheck=0

#清除yum缓存并更新
yum clean all
yum makecache

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
rhel6.3                 | 4.0 kB     00:00 ...
rhel6.3/filelists_db    | 3.7 MB     00:00 ...
rhel6.3/primary_db      | 3.1 MB     00:00 ...
rhel6.3/other_db        | 1.6 MB     00:00 ...
rhel6.3/group_gz        | 204 kB     00:00 ...
Metadata Cache Created

搭建YUM服务器

选择ftp或http等方式多可以,偷懒必须要简单有效

YUM服务端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#安装apache
yum install httpd*

#编辑apache配置文件
cd /etc/httpd/conf
cp httpd.conf httpd.conf.bak

#删除测试启动服务
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

#拷贝文件到目录或者修改httpd.conf中的DocumentRoot
cp -r /tmp/repo /var/www/html
cd /var/www/html
chmod -R 755 repo/

#重启apache服务 并设置服务自启动
service httpd restart
chkconfig httpd on
chkconfig --list | grep httpd

httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off

YUM客户端

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /etc/yum.repos.d
#清除老配置,rm -rf *
vi http.repo

[rhel6.3]
name=rhel6.3
baseurl=http://172.28.70.160/repo
enabled=1
gpgcheck=0

#清除yum配置缓存并更新
yum clean all
yum makecache

CentOS 6.X YUM源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#导入GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

#修改repo文件添加CentOS 6.X的YUM源
cd /etc/yum.repos.d/
cp rhel-source.repo rhel-source.repo.bak
vi rhel-source.repo

[base]
name=CentOS-$releasever-Base
baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

[updates]
name=CentOS-$releasever-Updates
baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

[extras]
name=CentOS-$releasever-Extras
baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

[centosplus]
name=CentOS-$releasever-Plus
baseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/
gpgcheck=1

#清除缓存查看是否生效
yum clean all
yum makecache
yum repolist

#安装yum-plugin-downloadonly插件
yum install -y yum-plugin-downloadonly

#YUM只下载不安装
yum install --downloadonly --downloaddir=/tmp/puppet puppet

CentOS 7.X YUM源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#导入GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7

#修改repo文件添加CentOS 7.X的YUM源
cd /etc/yum.repos.d/
cp rhel-source.repo rhel-source.repo.bak
vi rhel-source.repo

[base]
name=CentOS-$releasever-Base
baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever-Updates
baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever-Extras
baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever-Plus
baseurl=http://centos.ustc.edu.cn/centos/7/os/x86_64/
gpgcheck=1

#清除缓存查看是否生效
yum clean all
yum makecache
yum repolist

#安装yum-plugin-downloadonly插件
yum install -y yum-plugin-downloadonly

#YUM只下载不安装
yum install --downloadonly --downloaddir=/tmp/pacemaker pacemaker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 配置CentOS 7的yum可以选择本地yum或者阿里云的网络yum。如果选择阿里云的yum,可以按照以下步骤进行配置。 首先,下载阿里云的yum文件。使用以下命令下载并保存到/etc/yum.repos.d/CentOS-Base.repo文件中: \[root@localhost yum.repos.d\]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 然后,使用以下命令查看CentOS的版本: cat /etc/redhat-release 接下来,使用以下命令显示所有仓库: \[root@localhost yum.repos.d\]# yum repolist all 如果需要清空原有的yum文件,可以使用以下命令: rm -f /etc/yum.repos.d/* 或 ls /etc/yum.repos.d/ 然后,创建一个新的目录用于备份原有的yum文件: mkdir /root/123 将原有的yum文件移动到新创建的目录中: mv -f /etc/yum.repos.d/* /root/123 这样就完成了CentOS 7配置阿里云yum的过程。 #### 引用[.reference_title] - *1* *2* [虚拟机给Centos7配置yum(本地yum网络yum)](https://blog.csdn.net/LShuo666/article/details/129021403)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [centos7如何搭建本地yum局域网yum以及网络yum](https://blog.csdn.net/qq_45861317/article/details/120054815)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值