CentOS7 本地私有YUM源配置简录

  • 1,部署私有YUM源
# 依据《CentOS7实验机模板搭建部署》克隆实验主机,进行部署
HOSTNAME=localrepository
hostnamectl set-hostname "$HOSTNAME"
echo "$HOSTNAME">/etc/hostname
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ip a|grep "inet "|grep -v 127|awk -F'[ /]' '{print $6}') $HOSTNAME">>/etc/hosts

# 安装软件
yum -y install createrepo

# 上传需要共享的rpm包到共享目录
mkdir /YumRepository
cd /YumRepository
# scp USER@IP:/PATH /YumRepository

# 创建yum仓库的repodata目录和repomd.xml文件,repomd.xml是核心的配置文件
# 该文件指明了仓库中拥有的rpm包,当该文件不存在时,目录不能被识别成yum仓库
createrepo -pdo /YumRepository /YumRepository
# 当仓库中的rpm包有更新时,升级该文件
createrepo --update /YumRepository
  • 2,部署nginx做局域网共享
# 使用nginx做局域网共享
yum -y install epel-release
yum -y install nginx
sed -i 's|/usr/share/nginx/html|/YumRepository|g' /etc/nginx/nginx.conf
systemctl enable nginx
systemctl restart nginx

# 测试
cd /tmp/
wget http://$(hostname -i)/kubectl-1.12.1-2.x86_64.rpm
  • 3,客户端指向nginx共享的YUM源测试
# 客户端配置,在想要从该yum仓库中下载安装rpm包的机器上配置
echo '192.168.77.90 LocalRepository'>>/etc/hosts
cd /etc/yum.repos.d
cat >LocalRepository.repo<<EOF
[LocalRepository]
name=LocalRepository
baseurl=http://LocalRepository
enable=1
gpgcheck=0
EOF
yum clean all
yum makecache faster
# 安装yumdownloader命令
yum -y install yum-utils
cd /tmp/
yumdownloader kubectl
ls -l kubectl*.rpm
  • 4,定制简单脚本,持续更新rpm包
# 根据网络yum源持续更新rpm包
cat >/root/checkOS/yumRepoRefresh.sh<<EOF
cd /YumRepository
rm -rf index.html
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
for rpm in \$(cat index.html |awk -F'"' '{if(\$2~/.*.rpm/) print \$2}')
do
  wget -nc https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/\${rpm}
  # 使用 -nc 参数,忽略已经存在的包
done
# 更新仓库,否则新下载的rpm包不会被识别
createrepo --update /YumRepository
EOF
chmod +x /root/checkOS/yumRepoRefresh.sh
# 添加自动任务
crontab -l>/tmp/crontab.tmp
echo -e '\n# Yum Repo Daily Refresh '>>/tmp/crontab.tmp
echo '0 0 * * * /bin/bash /root/checkOS/yumRepoRefresh.sh'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp
  • 5,关闭yum的ssl证书验证
    • 注意,如果nginx使用自签证书通过https协议对公网的客户端共享YUM仓库,则需要在客户端配置关闭对证书的验证:
        echo 'sslverify=false'>>/etc/yum.conf
  • 6,CentOS6已经停止更新,阿里云镜像源已经下线,包括CentOS6的epel源,解决办法
    • 下载CentOS6.10的两个ISO镜像,将RPM包汇集到一起,使用本方案进行共享
    • 下载fedora的相关EPEL仓库,使用本方案进行共享
        mkdir /YumRepository/epel && cd /YumRepository/epel
        wget -m -c -N -np -nH --cut-dirs=1 --reject=html \
          'http://archives.fedoraproject.org/pub/archive/epel/6/x86_64/'
        mkdir centos
        mv archive/epel/6 centos/
        rm -rf archive
        # createrepo ...

[TOC]

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值