CentOS7同步阿里云镜像rpm包并自建本地yum仓库

系统环境

# 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

同步到本地目录

# reposync -p / mirror

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

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

更新新的rpm包

# reposync -np /mirror

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

创建索引

# 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

创建定时任务脚本

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

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

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

# yum install nginx -y

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

# vim nginx.conf

worker_processes  1;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  localhost;

root         /mirror ;   #这里是yum源存放目录

location / {

autoindex on;        #打开目录浏览功能

autoindex_exact_size off;  # off:以可读的方式显示文件大小

autoindex_localtime on; # on、off:是否以服务器的文件时间作为显示的时间

charset utf-8,gbk; #展示中文文件名

index index.html;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

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

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

# vim CentOS7.x-Base.repo

[base]

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

baseurl=http://10.0.0.100/base/

path=/

enabled=1

gpgcheck=0

[updates]

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

baseurl=http://10.0.0.100/updates/

path=/

enabled=1

gpgcheck=0

[extras]

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

baseurl=http://10.0.0.100/extras/

path=/

enabled=1

gpgcheck=0

[epel]

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

baseurl=http://10.0.0.100/epel/

failovermethod=priority

enabled=1

gpgcheck=0

CentOS7搭建本地YUM仓库,并定期同步阿里云源的更多相关文章

  1. CentOS 7 搭建本地YUM仓库,并定期同步阿里云源

    目录导航: 1. 系统环境 2. 修改yum 源为阿里云源 3. 安装yum相关的软件 4. 根据源标识同步源到本地目录 5. 安装nginx开启目录权限保证本地机器可以直接本地yum源 6. 客户端 ...

  2. 如何手工搭建本地Yum仓库

    如何手工搭建本地Yum仓库(重点推荐)  https://www.linuxidc.com/Linux/2016-09/135480.htm CentOS7.2 创建本地YUM源和局域网YUM源: h ...

  3. 其他综合-搭建本地yum仓库及自制rpm包

    搭建本地yum仓库及自制rpm包 实验目的 为方便本地 yum 的管理,建本地 yum 仓库,实现局域网内部快速安装常用软件 实验环境 VMware:12版本 系统版本:CentOS Linux re ...

  4. 搭建本地YUM仓库

    YUM介绍 yum(yellow dog updater modified)为多个Linux发行版的软件包管理工具,Redhat RHEL CentOS Fedora YUM主要用于自动安装,升级rp ...

  5. 使用3种协议搭建本地yum仓库

    关闭防火墙和selinux [root@qls yum.repos.d]# systemctl stop firewalld (stop,start,disable,enable) [root@qls ...

  6. rsync同步公网yum源搭建本地yum仓库

    镜像同步公网yum源上游yum源必须要支持rsync协议,否则不能使用rsync进行同步. centos源:rsync://rsync.mirrors.ustc.edu.cn/centos/ epel ...

  7. linux通过挂载系统光盘搭建本地yum仓库的方法

    1.挂载光盘 [root@localhost ~]# mount /dev/cdrom /media/cdrom/ mount: /dev/sr0 写保护,将以只读方式挂载 /media下的cdrom ...

  8. 在VMware下通过挂载系统光盘搭建本地yum仓库的方法

    一.虚拟机的安装 首先你要有一个VMware虚拟机,没有软件的朋友可以看我的前几篇博客 安装VMware虚拟机 二.进入虚拟机(在这里我们进入一个Linux虚拟机下的CentOS操作系统进行演示) 首 ...

  9. 通过挂载系统光盘搭建本地yum仓库

    1,配置本地yum源: 把系统光盘挂载到文件夹aaa(aaa为自己创建的文件夹). [root@localhost /]# mount dev/cdrom /aaa 2,修改yum配置文件: yum的 ...

随机推荐

  1. Open Source BI Platform List

    资源入口: awesome-business-intelligence https://github.com/thenaturalist/awesome-business-intelligence h ...

  2. 简单剖析Node中的事件监听机制(一)

    使用js的class类简单的实现一个事件监听机制,不同于浏览器中的时间绑定与监听,类似于node中的时间监听,并且会在接下来的文章中去根据自己的理解去写一下Event模块中的原理. Node.js使用 ...

  3. Codable实现json转Model,是时候干掉HandyJSON了!

    自从开始使用Swift做项目,一直都在使用HandyJSON,不可否认,HandyJSON在Swift4.0是个好东西,也尝试过其它json转mode的工具,最终发现还是HandyJSON最好用. 去 ...

  4. error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug

    属性1. 在工程上右键->属性->c/c++->代码生成->运行库 四个选项及含义分别如下: 1.1 /MDd:MD_DynamicDebug,我理解是 "共享DLL ...

  5. python中@classmethod @staticmethod区别

    Python中3种方式定义类方法, 常规方式, @classmethod修饰方式, @staticmethod修饰方式. class A(object): def foo(self, x): prin ...

  6. jQuery事件处理了解一下

    >>> JQuery 事件处理 一.事件绑定方式 1.事件绑定的快捷方式: 缺点:绑定的事件,无法取消 $("button:eq(0)").dblclick(fu ...

  7. Linux之SSH密钥认证

    1.SSH协议的认识 SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定:SSH 为建立在应用层基础上的安全协议.SSH 是目前 ...

  8. 微信小程序-统一下单、微信支付(Java后台)

    1.首先分享 微信统一下单接口: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1   微信接口 签名 对比网址: https: ...

  9. C# 使用 SmtpClient.SendAsync 方法发送邮件失败,总是返回 Cancelled

    问题: 调用 SmtpClient.SendAsync,在 SendCompleted 的回调函数里面总是获取到 e.Cancelled 为 true. 后来测试了一下,相同的代码,只是把 SmtpC ...

  10. rsyslog & syslog详解

    前言: rsyslog 是一个 syslogd 的多线程增强版.syslog是Linux系统默认的日志守护进程.默认的syslog配置文件是/etc/syslog.conf文件.程序,守护进程和内核提 ...