CentOS7给内网机器做yum源头(同步阿里云镜像)

CentOS7同步阿里云镜像rpm包并自建本地yum仓库 系统环境 # cat /etc/centos-releaseCentOS Linux release 7.6.1810 (Core)# uname -r3.10.0-957.el7.x86_64# ip a |awk 'NR==9{print $2}'|awk...

系统环境

# cat /etc/centos-release

CentOS Linux release 7.6.1810 (Core)

# uname -r

3.10.0-957.el7.x86_64

# ip a |awk 'NR==9{print $2}'|awk -F '/' '{print $1}'

10.0.0.100

修改yum源为阿里云源

备份系统自带的yum源

# tar -zcvf CentOS-bk.tar.gz /etc/yum.repos.d/CentOS-*

修改yum源

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

或者

# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

 

检验阿里云源是否正常

# yum repolist

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

#仓库标识仓库名称状态

repo id                                                                     repo name                                                                                                status

!base/7/x86_64                                                              CentOS-7 - Base - mirrors.aliyun.com                                                                     10,019

!epel/x86_64                                                                Extra Packages for Enterprise Linux 7 - x86_64                                                           12,902

!extras/7/x86_64                                                            CentOS-7 - Extras - mirrors.aliyun.com                                                                      371

!updates/7/x86_64                                                           CentOS-7 - Updates - mirrors.aliyun.com                                                                   1,103

repolist: 24,395

安装相关软件

# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

 

yum-utils:reposync同步工具

createrepo:编辑yum库工具

plugin-priorities:控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。

注:由于很多人喜欢最小化安装,上边软件是一些常用环境。

根据源标识同步源到本地目录

创建本地目录

#mkdir /mirror/REPO

同步到本地目录

# reposync -p /mirror/REPO

注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。

可以用  repo -r --repoid=repoid指定要查询的repo id,可以指定多个(# reposync -r base -p /mirror     #这里同步base目录到本地)

更新新的rpm包

# reposync -np /mirror/REOP

注:时间同样较长,请耐心等待。

创建索引

# createrepo -po /mirror/REPO/base/ /mirror/REPO/base/

# createrepo -po /mirror/REPO/extras/ /mirror/REOP/extras/

# createrepo -po /mirror/REPO/updates/ /mirror/REOP/updates/

# createrepo -po /mirror/REPO/epel/ /mirror/REPO/epel/

 

更新源数据

# createrepo --update /mirror/REPO/base

# createrepo --update /mirror/REPO/extras

# createrepo --update /mirror/REPO/updates

# createrepo --update /mirror/REPO/epel

 

创建定时任务脚本

#vim /mirror/script/centos_yum_update.sh

#!/bin/bash

echo 'Updating Aliyum Source'

DATETIME=`date +%F_%T`

exec > /var/log/aliyumrepo_$DATETIME.log

     reposync -np /mirror

if [ $? -eq 0 ];then

      createrepo --update /mirror/REPO/base

      createrepo --update /mirror/REPO/extras

      createrepo --update /mirror/REPO/updates

      createrepo --update /mirror/REPO/epel

    echo "SUCESS: $DATETIME aliyum_yum update successful"

  else

    echo "ERROR: $DATETIME aliyum_yum update failed"

fi

 

将脚本加入到定时任务中

# crontab -e

# Updating Aliyum Source

00 13 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /mirror/script/centos_yum_update.sh

每月第一个周六的13点更新阿里云yum源

 

安装nginx开启目录权限保证本地机器可以直接本地yum源

创建运行账户

groupadd www

useradd -r -g nginx -s /bin/false -M www

# yum install nginx -y


server {

        listen       80;

        server_name  localhost;

        root /mirror/REPO;

            autoindex on;

            autoindex_exact_size off;

            autoindex_localtime on;

            charset utf-8,gbk;

            index index.html;

}

 

在客户端修改yum源,并指向本地搭建的yum源主机

注:搭建好后yum安装速度并没有想象中的那么快,安装时解决依赖速度也很慢。

 

# vim CentOS7-internal.repo

[base]

name=CentOS-$releasever - Base - mirror.template.com

baseurl=http://192.168.1.22/base/

path=/

enabled=1

gpgcheck=0


[updates]

name=CentOS-$releasever - Updates - mirror.template.com

baseurl=http://192.168.1.22/updates/

path=/

enabled=1

gpgcheck=0


[extras]

name=CentOS-$releasever - Extras - mirrors.template.com

baseurl=http://192.168.1.22/extras/

path=/

enabled=1

gpgcheck=0


[epel]

name=CentOS-$releasever - epel - mirrors.template.com

baseurl=http://192.168.1.22/epel/

failovermethod=priority

enabled=1

gpgcheck=0

  • 发表于 2020-01-30 01:05
  • 阅读 ( 47 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
石天
石天

437 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章