ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

本地YUM仓库搭建

2020-12-26 21:31:35  阅读:207  来源: 互联网

标签:CentOS 仓库 createrepo update repo -- YUM yum 搭建


1、环境准备

①CentOS Linux release 7.8 1台

②各系统根目录要至少100G存储空间

③确保可以连接外网

2、修改本地YUM源

①备份本地YUM源:

tar -zcvf /etc/yum.repos.d//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

③检查阿里YUM源是否正常

yum repolist

④安装相关软件

 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、根据源标识同步源到本地目录

①创建本地同步目录

mkdir /repo

②将阿里YUM的Package同步到本地目录

reposync -p /repo

③创建索引

createrepo -po /repo/base/ /repo/base/

createrepo -po /repo/extras/ /repo/extras/

createrepo -po /repo/updates/ /repo/updates/

createrepo -po /repo/epel/ /repo/epel/

④更新数据源

createrepo --update /repo/base

createrepo --update /repo/extras

createrepo --update /repo/updates

createrepo --update /repo/epel

4、创建定时任务

#vi /repo/script/centos_yum_update.sh

#!/bin/bash

echo 'Updating Aliyum Source'

DATETIME=`date +%F_%T`

exec > /repo/scripts/aliyumrepo_$DATETIME.log

     reposync -np /repo

if [ $? -eq 0 ];then

      createrepo --update /repo/base

      createrepo --update /repo/extras

      createrepo --update /repo/updates

      createrepo --update /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 /repo/script/centos_yum_update.sh

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

5、配置Nginx访问服务

①创建运行账户

groupadd nginx

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

yum install nginx -y

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

# vi 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         /repo ;   #这里是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源主机

# vi CentOS7.x-Base.repo

[base]

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

baseurl=http://192.168.230.44/base/

path=/

enabled=1

gpgcheck=0

 

[updates]

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

baseurl=http://192.168.230.44/updates/

path=/

enabled=1

gpgcheck=0

 

[extras]

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

baseurl=http://192.168.230.44/extras/

path=/

enabled=1

gpgcheck=0

 

[epel]

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

baseurl=http://192.168.230.44/epel/

failovermethod=priority

enabled=1

gpgcheck=0

标签:CentOS,仓库,createrepo,update,repo,--,YUM,yum,搭建
来源: https://blog.csdn.net/weixin_33669839/article/details/111769231

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有