针对CentOS7更改yum源与更新系统和centos7修改yum源这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS6修改YUM源方法、centos7yum源文件配置详解及163
针对CentOS 7更改yum源与更新系统和centos7修改yum源这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS 6修改YUM源方法、centos 7 yum源文件配置详解及163 yum源更换、CentOS 7搭建本地yum源和局域网yum源、CentOS 7更新YUM源步骤等相关知识,希望可以帮助到你。
本文目录一览:- CentOS 7更改yum源与更新系统(centos7修改yum源)
- CentOS 6修改YUM源方法
- centos 7 yum源文件配置详解及163 yum源更换
- CentOS 7搭建本地yum源和局域网yum源
- CentOS 7更新YUM源步骤
CentOS 7更改yum源与更新系统(centos7修改yum源)
0、开源镜像
网易开源镜像镜像
网易开源镜像使用帮助: http://mirrors.163.com/.help
阿里云开源镜像
https://mirrors.aliyun.com/repo/
1、备份
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 或者 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载CentOS-Base.repo 到/etc/yum.repos.d/
cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
3、生成缓存
yum clean all
yum makecache
4、更新系统
更新系统时间可能会比较久取决于服务器网速
yum -y update
CentOS 6修改YUM源方法
以163源为例 首先备份/etc/yum.repos.d/CentOS-Base.repo mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup #cd/etc/yum.repos.d #mvCentOS-Base.repoCentOS-Base.repo.backup #wget #mvCentOS6-Base-163.repoCentOS6-Base.repo 运行以下命令生成缓存 #yumcleanall #yummakecache
centos 7 yum源文件配置详解及163 yum源更换
备份原来的源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS7-Base-163.repo yum clean all yum makecache/etc/yum.conf 配置文件
[main] cachedir=/var/cache/yum #yum下载的RPM包的缓存目录 keepcache=0 #缓存是否保存,1保存,0不保存。 debuglevel=2 #调试级别(0-10),默认为2(具体调试级别的应用,我也不了解)。 logfile=/var/log/yum.log #yum的日志文件所在的位置 exactarch=1 #在更新的时候,是否允许更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。 obsoletes=1 #这是一个update的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。 gpgcheck=1 #是否检查GPG(GNU Private Guard),一种密钥方式签名。 plugins=1 #是否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件。 installonly_limit=3 #允许保留多少个内核包。 exclude=selinux* #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离。 # This is the default,if you make this bigger yum won't see if the Metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new Metadata and "pay" for it by yum not having correct # information. # It is esp. important,to have correct Metadata,for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage,it's much better to have something # manually check the Metadata once an hour (yum-updatesd will do this). # Metadata_expire=90m # PUT YOUR REPOS HERE or IN separate files named file.repo # in /etc/yum.repos.d
关于*.repo文件
[fedora] #方括号里面的是软件源的名称,将被yum取得并识别 name=Fedora $releasever - $basearch #这里也定义了软件 仓库的名称,通常是为了方便阅读配置文件,一般没什么作用,$releasever变量定义了发行版本,通常是8,9,10等数字,$basearch变 量定义了系统的架构,可以是i386、x86_64、ppc等值,这两个变量根据当前系统的版本架构不同而有不同的取值,这可以方便yum升级的时候选择 适合当前系统的软件包,以下同…… failovermethod=priority #failovermethod 有两个值可以选择,priority是默认值,表示从列出的baseurl中顺序选择镜像服务器地址,roundrobin表示在列出的服务器中随机选择 exclude=compiz* *compiz* fusion-icon* #exclude这个选项是后来我自己加上去的,用来禁止这个软件仓库中的某些软件包的安装和更新,可以使用通配符,并以空格分隔,可以视情况需要自行添加 #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/ #上面的一行baseurl第一个字符是'#'表示该行已经被注释,将不会被读取,这一行的意思是指定一个baseurl(源的镜像服务器地址) #mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch #上面的这一行是指定一个镜像服务器的地址列表,通常是开启的,本例中加了注释符号禁用了,我们可以试试,将$releasever和$basearch替换成自己对应的版本和架构,例如10和i386,在浏览器中打开,我们就能看到一长串镜可用的镜像服务器地址列表。 选择自己访问速度较快的镜像服务器地址复制并粘贴到repo文件中,我们就能获得较快的更新速度了,格式如下baseurl所示: baseurl= ftp://ftp.sfc.wide.ad.jp/pub/Linux/Fedora/releases/10/Everything/i386/os http://ftp.chg.ru/pub/Linux/fedora/linux/releases/10/Everything/i386/os http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/os http://mirror.nus.edu.sg/fedora/releases/10/Everything/i386/os http://mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/os http://ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/os http://ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/os enabled=1 #这个选项表示这个repo中定义的源是启用的,0为禁用 gpgcheck=1 #这个选项表示这个repo中下载的rpm将进行gpg的校验,已确定rpm包的来源是有效和安全的 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定义用于校验的gpg密钥 ##以下的软件仓库基本上用不到,选项含义同上 [fedora-debuginfo] name=Fedora $releasever - $basearch - Debug failovermethod=priority #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/ mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug-$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [fedora-source] name=Fedora $releasever - Source failovermethod=priority #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/ mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
CentOS 7搭建本地yum源和局域网yum源
这两天在部署公司的测试环境,在安装各种中间件的时候,发现各种依赖都没有;后来一检查,发现安装的操作系统是CentOS Mini版,好吧,我认了;为了完成测试环境的搭建,我就搭建了一个局域网的yum源。本来搭建本地的yum源也没有多大的难度,网上的文章一大把,而我这里写这篇文章主要是准备给组内的小伙伴做培训的,后来一想,索性就写一篇完成的,直接发布到博客吧,和网友一起分享一下。
大家在工作中肯定或多或少的会遇到使用yum源;在我们公司,服务器都在内网,所以就需要搭建局域网的yum源,说到yum源搭建,主要有以下两种方式:
- 搭建本地yum源
- 搭建局域网yum源
无非就这两种,下面就分别对这两种yum源的搭建方式进行总结。
搭建本地yum源
本地yum源,就意味着只有搭建该yum源的这台服务器能使用,其它的服务器都不能使用该yum源。搭建本地yum源的所有步骤如下:
# 在/mnt目录创建挂载镜像的文件夹
cd /mnt
mkdir iso
# 将iso镜像挂载到/mnt/iso目录
mount -o loop CentOS-7-x86_64-DVD-1810.iso /mnt/iso
# 挂载成功后可以使用df -h命令查看
[root@192.168.1.2 iso]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 29G 5.3G 23G 19% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 6.8M 489M 2% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/sda1 1014M 132M 883M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
tmpfs 100M 0 100M 0% /run/user/1000
/dev/loop0 4.3G 4.3G 0 100% /mnt/iso
# 修改yum配置文件
cd /etc/yum.repos.d
# 先备份配置文件
mkdir bak
mv *.repo ./bak
# 将备份的CentOS-Media.repo文件拷贝出来
cp ./bak/CentOS-Media.repo ./
# 修改CentOS-Media.repo配置文件,修改后内容如下:
[c7-media]
name=CentOS-$releasever - Media
#baseurl=file:///media/CentOS/
# file:///media/cdrom/
# file:///media/cdrecorder/
baseurl=file:///mnt/iso/
gpgcheck=1
enabled=1 # 设置为1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
至此搭建本地yum源的操作完成,接下来我们清除原有的yum信息:
yum clean all
这样,一个崭新的本地yum源就可以使用了。
搭建局域网yum源
除了可以搭建本地yum源外,我们还可以基于HTTP方式配置yum源,这样我们就可以配置一个局域网内都可以使用的yum源。
一般都是通过Nginx来搭建HTTP的yum源,首先搭建Nginx,这里就不细说如何搭建Nginx了。接下来将iso镜像文件解压缩到一个目录。现在,我们就可以配置Nginx配置文件了:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
autoindex on;
root /home/jelly/iso/; # (这里请换成你的实际目录路径)
}
}
}
最后,我们开始配置yum的配置文件,在/etc/yum.repos.d
新建一个名为Nginx-yum.repo
的配置文件,内容如下:
[Nginx-yum]
name=Nginx-yum
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://192.168.1.3:8080
enabled=1
gpgcheck=1
gpgkey=http://192.168.1.3:8080/RPM-GPG-KEY-CentOS-7
至此搭建局域网yum源的操作完成,接下来我们清除原有的yum信息:
yum clean all
这样,一个崭新的局域网yum源就可以使用了。
总结
这篇文章详细的总结了两种搭建yum源的方法,通过这篇文章中总结的方法,足以应对我们日常工作中的需要。好了,东西不多,但是非常实用,希望我这里总结的内容对大家有帮助,如果觉的还不错,可以点击下方的“打赏”哦。
CentOS 7更新YUM源步骤
国内小伙伴推荐使用阿里云的源
Step1 找到需要的源
阿里巴巴开源镜像站各种源应有尽有,老域名是https://mirrors.aliyun.com/
Step2 编辑CentOS7.repo文件
进入/etc/yum.repos.d
,发现我的源还是7.4.1708
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7.4.1708/os/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7.4.1708/updates/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7.4.1708/extras/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7.4.1708/centosplus/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7.4.1708/contrib/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
这个版本的源已经迁移到7.5.1804了,→地址,使用VIM将其替换
:%s/7.4.1708/7.7.1908/g
Step3 修复冲突报错
然后更新系统试试yum -y update
[root@liaogx ~]# yum -y update
Plugin "product-id" can''t be imported
Plugin "search-disabled-repos" can''t be imported
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package ModemManager.x86_64 0:1.6.0-2.el7 will be updated
......此处略......
---> Package yum-rhn-plugin.noarch 0:2.0.1-10.el7 will be installed
--> Running transaction check
---> Package libbytesize.x86_64 0:1.2-1.el7 will be installed
---> Package python2-pytoml.noarch 0:0.1.18-1.el7 will be installed
---> Package volume_key-libs.x86_64 0:0.3.9-8.el7 will be installed
--> Processing Conflict: initscripts-9.49.41-1.el7_5.1.x86_64 conflicts redhat-release < 7.5-0.11
--> Finished Dependency Resolution
Error: initscripts conflicts with redhat-release-server-7.4-18.el7.x86_64
You could try using --skip-broken to work around the problem
** Found 2 pre-existing rpmdb problem(s), ''yum check'' output follows:
PackageKit-1.1.5-1.el7.centos.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-17.el7.noarch has missing requires of yum-rhn-plugin >= (''0'', ''1.6.4'', ''1'')
[root@liaogx ~]#
如果报如下错误
Error: initscripts conflicts with redhat-release-server-7.4-18.el7.x86_64
这是更新软件包是与原版本冲突造成的,有两种解决办法
- 通过关键字initscritps排除冲突:
yum update --exclude=kernel* --exclude=centos-release* --exclude=initscripts*
- 删除冲突包:
rpm -e redhat-release-server-7.4-18.el7.x86_64 --nodeps
这里使用第二种方法,把冲突的包干掉
[root@liaogx ~]# rpm -e redhat-release-server-7.4-18.el7.x86_64 --nodeps
warning: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release: remove failed: No such file or directory
warning: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-legacy-rhx: remove failed: No such file or directory
warning: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-legacy-release: remove failed: No such file or directory
warning: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-legacy-former: remove failed: No such file or directory
warning: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta: remove failed: No such file or directory
[root@liaogx ~]#
Step4 更新系统
小白从入门到跑路必会,sudo yum -y update
,老鸟都懂。
[root@liaogx ~]# yum -y update
......此处省略10分钟......
Complete!
[root@liaogx ~]#
更新成功 ^_^
搜索关注微信公众号:寸土币争 ID: bbcoins
关于CentOS 7更改yum源与更新系统和centos7修改yum源的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于CentOS 6修改YUM源方法、centos 7 yum源文件配置详解及163 yum源更换、CentOS 7搭建本地yum源和局域网yum源、CentOS 7更新YUM源步骤等相关内容,可以在本站寻找。
本文标签: