我是靠谱客的博主 无情芒果,最近开发中收集的这篇文章主要介绍CentOS内网yum源构建&使用最佳实践一、yum源构建(base源、updates源、epel源)二、yum源使用,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

一、yum源构建(base源、updates源、epel源)

1. 找一台能连互联网的centos服务器,虚拟机也行。

2. 备份已有yum repo文件

cd /etc/yum.repo.d
mkdir bak
mv *.repo bak

3. 导入华为云yum repo

#导入华为yum源配置
cat > /etc/yum.repos.d/CentOS-Base.repo <<EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.
You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - repo.huaweicloud.com
baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - repo.huaweicloud.com
baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - repo.huaweicloud.com
baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - repo.huaweicloud.com
baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
EOF
cat > /etc/yum.repos.d/epel.repo <<EOF
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://repo.huaweicloud.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://repo.huaweicloud.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://repo.huaweicloud.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
EOF
#清理yum缓存
yum clean all
#重新构建yum缓存
yum makecache

4. 安装yum源同步工具

yum -y install yum-utils createrepo

5. 同步yum源到本地

#yum源同步 ${downloadPath} 下载路径
reposync -r base -r updates -r epel -d -n -m -g -p ${downloadPath}

6. 创建repodata索引

createrepo -g
${downloadPath}/epel/comps.xml ${downloadPath}/epel/
createrepo -g
${downloadPath}/base/comps.xml ${downloadPath}/base/
createrepo ${downloadPath}/updates/

7. 打包离线源

tar -zcvf base.tar.gz ${downloadPath}/base/
tar -zcvf updates.tar.gz ${downloadPath}/updates/
tar -zcvf epel.tar.gz ${downloadPath}/epel/

二、yum源使用

1. 上传tar包到内网服务器

2. 解压文件

#创建解压路径
mkdir -p /var/www/html/centos7/
#解压 ${uploadPath}上传路径
tar -zxvf ${uploadPath}/base.tar.gz -C /var/www/html/centos7/
tar -zxvf ${uploadPath}/updates.tar.gz -C /var/www/html/centos7/
tar -zxvf ${uploadPath}/epel.tar.gz -C /var/www/html/centos7/

3. 备份已有repo

cd /etc/yum.repo.d
mkdir bak
mv *.repo bak

4. 配置本地源

#配置本地源
cat > /etc/yum.repo.d/local.repo <<EOF
[base]
name=CentOS-7-base
baseurl=file:///var/www/html/centos7/base
gpgcheck=0
enabled=1
priority=1
EOF
#本地源生效
yum clean all
yum makecache

5. 安装httpd服务

#从本地yum源安装
yum -y httpd
​#启动httpd服务
systemctl start httpd
#开机自启httpd服务
systemctl enable httpd

6. 配置内网源

#删除本地源配置
rm -rf /etc/yum.repos.d/local.repo
#配置内网源
#${localIP} 本地ip地址
cat > /etc/yum.repos.d/intranet_os.repo <<EOF
[base]
name=CentOS-7-base
baseurl=http://${localIP}/centos7/base/
gpgcheck=0
enabled=1
priority=1
[updates]
name=CentOS-7-updates
baseurl=http://${localIP}/centos7/updates/
gpgcheck=0
enabled=1
priority=1
[epel]
name=CentOS-7-epel
baseurl=http://${localIP}/centos7/epel/
gpgcheck=0
enabled=1
priority=1
EOF
#内网源生效
yum clean all
yum makecache

最后

以上就是无情芒果为你收集整理的CentOS内网yum源构建&使用最佳实践一、yum源构建(base源、updates源、epel源)二、yum源使用的全部内容,希望文章能够帮你解决CentOS内网yum源构建&使用最佳实践一、yum源构建(base源、updates源、epel源)二、yum源使用所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部