本地yum源仓库同步阿里云源

    技术2022-07-11  103

    1.准备工作

    1.查看系统内核

    [root@Oracle ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core)

    2.查看内核版本

    [root@Oracle ~]# uname -rm 3.10.0-957.el7.x86_64 x86_64

    2.修改yum源以及备份

    1.备份系统自带的yum源

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

    2.下载阿里源repo

    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

    3.检验阿里云源是否正常

    [root@oracle ~]# yum repolist 已加载插件:fastestmirror, langpacks Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com ###源标识 源名称 状态 !base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070 !extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 397 !updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 760 repolist: 11,227 ###我这边只是下载了x86_64的32位的没有下载

    4.为了不报错先安装这些工具再说

    #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端。

    3. 开始同步数据到本地目录

    1.创建本地目录

    #mkdir /mirror

    2.同步到本地目录

    开始同步

    #reposync -p / mirror 注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间超长请耐心等待。。。。。 也可以用 repo -r --repoid=repoid指定要查询的repo id,可以指定多个(# reposync -r base -p /mirror #这里同步base目录到本地)

    更新新的rpm包

    # reposync -np /mirror 注:时间同样较长,请耐心等待。

    3.创建rpm包源索引

    # createrepo -po /mirror/base/ /mirror/base/ # createrepo -po /mirror/extras/ /mirror/extras/ # createrepo -po /mirror/updates/ /mirror/updates/ # createrepo -po /mirror/epel/ /mirror/epel/

    更新数据源

    # createrepo --update /mirror/base # createrepo --update /mirror/extras # createrepo --update /mirror/updates # createrepo --update /mirror/epel

    4.创建定时任务脚本

    #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/base createrepo --update /mirror/extras createrepo --update /mirror/updates createrepo --update /mirror/epel echo "SUCESS: $DATETIME aliyum_yum update successful" else echo "ERROR: $DATETIME aliyum_yum update failed" fi

    将脚本加入到定时任务中

    #crontab -e #Updating Aliyum Source 00 23 * * 6 [ $(date +%d) -eq $(cal | awk ‘NR==3{print $NF}’) ] && /bin/bash /mirror/script/centos_yum_update.sh 每月第一个周六的23点更新阿里云yum源

    4.开启web服务或者ftp服务开启

    1.这里安装的是fttp服务

    安装http服务

    #yum install httpd -y

    找到httpd配置文件,并修改httpd配置文件:

    #vim /etc/httpd/conf/httpd.conf

    DocumentRoot "/mirror/" # # Relax access to content within /var/www. # <Directory "/mirror/"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/mirror/">

    原有的欢迎页面移动或删除

    #cd /etc/httpd/conf.d #mv welcome.conf welcome.conf.bak

    5在client修改yum源,搭建的yum源主机

    修改repo文件

    #vim CentOS7.x-Base.repo

    [base] name=CentOS-$releasever - Base - mirror.template.com baseurl=http://192.168.137.145/base/ path=/ enabled=1 gpgcheck=0 [updates] name=CentOS-$releasever - Updates - mirror.template.com baseurl=http://192.168.137.145/updates/ path=/ enabled=1 gpgcheck=0 [extras] name=CentOS-$releasever - Extras - mirrors.template.com baseurl=http://192.168.137.145/extras/ path=/ enabled=1 gpgcheck=0 [repodata] name=CentOS-$releasever - epel - mirrors.template.com baseurl=http://192.168.137.145/epel/ failovermethod=priority enabled=1 gpgcheck=0

    随便测试yum install 安装成功 完事大吉

    Processed: 0.008, SQL: 9