CentOS7搭建本地YUM仓库,并定期同步阿里云源

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源

创建运行账户

groupadd nginx

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

# 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

 

转载于:https://www.cnblogs.com/lldsn/p/10479493.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装包 rpm -e 包 --nodeps 3.下载yum源包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum源包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet
### 回答1: 要配置yum阿里云,可以参考以下步骤:1.首先下载阿里云的rpm包,可以在阿里云官网上下载;2.使用rpm安装阿里云,使用命令:rpm -ivh 阿里云的rpm包;3.安装成功后,使用命令:yum clean all;4.最后使用命令:yum makecache,完成配置。 ### 回答2: CentOS 7是一种非常流行的Linux操作系统,通过配置Yum阿里云可以加快软件包的下载速度并提高系统性能。下面是配置Yum阿里云的步骤: 1. 使用root用户登录CentOS 7系统。 2. 打开终端并切换到root用户。 3. 首先备份原始的Yum仓库配置文件,以防止配置错误时可以还原。运行以下命令备份文件: ``` cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak ``` 4. 下载阿里云Yum仓库配置文件。使用以下命令下载文件: ``` wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 5. 清除本地Yum缓存,运行以下命令: ``` yum clean all ``` 6. 生成新的Yum缓存,以便使用阿里云的镜像,运行以下命令: ``` yum makecache ``` 7. 配置完成后,可以使用Yum命令安装软件包了。例如,要安装Apache HTTP Server,可以运行以下命令: ``` yum install httpd ``` Yum将自动从阿里云的镜像下载并安装所需的软件包。 通过以上步骤,您已经成功配置了CentOS 7的Yum阿里云。这将使您在安装和更新软件包时能够更快地下载所需的文件,并提高系统性能。 ### 回答3: 在CentOS 7上配置阿里云yum源是一种常见的操作,以下是详细步骤: 1. 在CentOS 7上打开终端并以root用户身份登录。 2. 备份现有的yum源配置文件,以防止配置过程中出现问题: `cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup` 3. 下载阿里云yum源的配置文件: `wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo` 4. 清除yum缓存: `yum clean all` 5. 更新yum源并安装yum工具: `yum makecache` 6. 完成后,您的CentOS 7系统将使用阿里云yum源进行软件包安装和更新。 注意事项: - 阿里云yum源阿里云为了提供更快速和稳定的软件包下载而提供的。您可以根据需要选择是否使用。 - 在配置yum源之前,确保您的网络连接正常,如果网络有问题,可能会导致下载失败或速度慢。 - 备份原有的yum配置文件是一种良好的习惯,以备不时之需。 希望这些步骤能够帮助您成功地在CentOS 7上配置阿里云yum源。如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值