• CentOS-7.x Yum Repo Mirror


    一. 环境

    1.1 主机信息

    主机 OS Storage 备注
    100.64.140.101 centos 7.6 /dev/sdb > 100GB 1.selinux disable; 2.放行tcp80端口

    1.2 挂载磁盘

    # 通过fdisk创建linux或linux lvm分区;
    # 格式化分区为ext4或xfs格式
    mkfs.ext4 /dev/sdb1
    
    # mount
    mkdir -p /repo
    echo "/dev/sdb1 /repo                    ext4    defaults        1 2" >> /etc/fstab
    mount -a
    

    二. 镜像Yum源

    # 使用rsync同步yum源,上游yum源需要支持rsync协议
    yum install rsync -y
    
    # 同步清华大学开源软件镜像站,实测阿里云镜像站不支持rsync协议
    # centos
    mkdir -p /repo/centos/7.6.1810/os/x86_64/
    rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/centos/7.6.1810/os/x86_64/ /repo/centos/7.6.1810/os/x86_64/
    rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /repo/centos/RPM-GPG-KEY-CentOS-7
    # 重要!建立/repo/centos/7.6.1810/目录的软链接
    ln -s /repo/centos/7.6.1810/ /repo/centos/7
    
    # epel
    mkdir -p /repo/epel/7/x86_64/
    rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ /repo/epel/7/x86_64/
    rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7 /repo/epel/RPM-GPG-KEY-EPEL-7
    

    三. Web服务器

    # 安装nginx
    yum install nginx -y
    
    # 编辑
    vim /etc/nginx/nginx.conf
        server {
            client_max_body_size 4G;
            listen       80 default_server;
            server_name  100.64.140.101;
            root         /mirror;
    
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
            location / {
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
            }
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
        
    # 测试
    nginx -t
    
    # 启动
    systemctl enable nginx
    systemctl restart nginx
    

    四. 客户端repo文件

    4.1 CentOS-Base.repo

    # 备份
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    
    # 生成repo
    cat << EOF >> /etc/yum.repos.d/CentOS-Base.repo
    # CentOS-Base.repo
    [base]
    name=CentOS-$releasever - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://100.64.140.101/centos/$releasever/os/$basearch/
            http://100.64.140.101/centos/$releasever/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=http://100.64.140.101/centos/RPM-GPG-KEY-CentOS-7
    EOF
    

    4.2 epel.repo

    # centos默认没有epel.repo
    cat << EOF >> /etc/yum.repos.d/epel.repo
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    baseurl=http://100.64.140.101/epel/7/$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=http://100.64.140.101/epel/RPM-GPG-KEY-EPEL-7
    EOF
    

    五. (option范例)初始化repodata索引

    # 如果通过rsync从公网同步镜像,repodata也会同步,可直接使用;
    # 如果不是从公网同步的镜像库,没有repodata索引文件,可通过createrepo生成
    # 安装createrepo
    yum install createrepo -y 
    
    # 在镜像源目录生成repodata索引文件
    createrepo -pdo /repo/centos/7.6.1810/os/x86_64/
    createrepo -pdo /repo/epel/7/x86_64/
    
  • 相关阅读:
    统一身份认证(CAS)客户端测试获取信息代码
    常用的java工具类
    windows 批处理(bat)中执行程序后不等待直接退出(cmd中新进程执行程序)
    持续交付的八条原则,你能做到几条?(转)
    灵动标签调用栏目导航技巧
    .net网络编程(2)网络适配器
    Property Value Inheritance Tip(1)
    排序算法补充
    编码参考(Encoding)
    .net网络编程(3)Socket基础
  • 原文地址:https://www.cnblogs.com/netonline/p/10611025.html
Copyright © 2020-2023  润新知