• 07-服务管理-03-自建yum仓库(手把手教你搭建内网yum源)


    1 环境

    1.1 相关依赖

    yum install -y wget make cmake gcc gcc-c++  
    yum install -y pcre-devel lib zlib-devel  
    
    • 1
    • 2

    1.2 yum 用到的工具

    yum install yum-plugin-downloadonly
    yum -y install createrepo
    yum install yum-utils
    
    • 1
    • 2
    • 3

    2 安装nginx

    我们用容器启动,流程如下:

    • docker-compose.yml文件
    version: "3"
    services:
      nginx-02:
        image: "nginx"
        restart: on-failure
        ports:
          - 80:80
        volumes:
          - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
          - /data/yum/centos/7/os:/usr/share/nginx/html
        restart: always
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • nginx.conf
    # gzip设置
    gzip on;
    gzip_vary on;
    
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    
    gzip_min_length 1000;
    gzip_proxied any;
    gzip_disable "msie6";
    #gzip_http_version 1.0;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    
    server {
        listen       80;
        server_name  web80;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            add_header Cache-Control no-store;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    3. 同步外网源数据

    以同步epel源为例

    • 将repo文件全部清除(非必要,不冲突即可)

    • 安装epel源(如果有可以忽略)

    wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -ivh epel-release-latest-7.noarch.rpm
    
    • 1
    • 2

    打开生成的epel.repo文件,我们可以看见它默认使用的库是epel库,我们下边同步这个库

    • 同步epel源的 epel
    reposync -r epel -p /data/yum/centos/7/os/
    
    • 1

    需要等一段时间,毕竟有十多个G的数据

    • 我们可看到/data/yum/centos/7/os/ 下多了 epel 这个目录

    4. 初始化

    createrepo /data/yum/centos/7/os
    
    • 1

    5. 使用

    [liubei_epel]
    name=liubei_epel
    baseurl=http://liubei.xxx.com/
    enabled=1
    gpgcheck=0
    
    • 1
    • 2
    • 3
    • 4
    • 5

    6. 定时同步

    6.1 同步脚本

    创建定义脚本如下 /data/script/yum-update.sh

    #!/bin/bash
    datetime=`date +"%Y-%m-%d"`
    exec > /var/log/yum-update.log
    reposync -d -r base -p /data/yum/centos/7/os/
    ###########同步镜像源########################
    if [ $? -eq 0 ];then
      createrepo --update  /opt/yum/centos/7/os
      echo "SUCESS: $datetime epel update successful"
    else
      echo "ERROR: $datetime epel update failed"
    fi
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    6.2 定时任务

    说明:每周日凌晨两点更新。

    # crontab -e
    
    • 1

    定时任务如下:

    0 2 * * 7 /bin/bash /data/script/yum-update.sh
    
    • 1

    8. 模拟后期添加新源

    k8s源为例

    • 添加yum源
    # cat> /etc/yum.repos.d/kubernetes.repo <
    [kubernetes] 
    name=Kubernetes 
    baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 
    enabled=1 
    gpgcheck=0 
    repo_gpgcheck=0 
    gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 
     http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 
    EOF
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 同步数据
    reposync -r kubernetes  -p /data/yum/centos/7/os/
    
    • 1
    • 更新yum源仓库
      createrepo --update  /opt/yum/centos/7/os
    
    • 1
  • 相关阅读:
    Oracle-使用XTTS方式迁移11G到PDB数据库
    火遍国内外IT技术圈,豆瓣 9.7!这本技术书籍直接封神了
    day02 真正的高并发还得看IO多路复用
    06 OpenCV增加图像的对比度
    2022.10.9-10.16 AI行业周刊(第119期):相信坚持的力量
    反转问题(字符串和链表)
    大数据-之LibrA数据库系统告警处理(ALM-12049 网络读吞吐率超过阈值)
    防御式编程介绍
    【目标跟踪】|SiamFC
    Qt疑难杂症篇8:Quazi的编译及使用,保姆级教程
  • 原文地址:https://blog.csdn.net/xingzuo_1840/article/details/127407459