内外yum源

内网yum源制作

系统环境

cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

修改yum源为阿里云源

备份系统自带的yum源

tar -zcvf CentOS-backup.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

安装yum相关软件

yum-utils: reposync同步工具

createrepo: 编辑yum库工具

plugin-priorities: 控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以在client端

# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

根据源标识同步源到本地目录

创建本地目录

mkdir /yum_centos7

同步到本地目录

# 不用创建相关目录,系统自动创建相关目录,并下载
# 只同步某个子目录(reposync -r base -p /yum_centos7),-p 指定下载路径
# 第一次执行以下命令
reposync -p  /yum_centos7

# 更新新的rpm包,-n 只下载最新的包,相同的跳过
# 第二次执行以下命令即可
reposync  -np /yum_centos7

创建元数据索引

# -o 指定元数据输出位置,  第一个路径为元数据位置, 第二个为rpm包位置
createrepo -po /yum_centos7/base/      /yum_centos7/base/
createrepo -po /yum_centos7/extras/    /yum_centos7/extras/
createrepo -po /yum_centos7/updates/   /yum_centos7/updates/
createrepo -po /yum_centos7/epel/      /yum_centos7/epel/

更新源数据

#   每次新添加rpm包需要更新元数据
#  --update 如果元数据已经存在,且软件仓库中只有部分软件发生了改变或增减,则可用update参数直接对原有元数据进行升级,效率比重新分析rpm包依赖并生成新的元数据要高很多
createrepo --update    /yum_centos7/base/
createrepo --update    /yum_centos7/extras/
createrepo --update    /yum_centos7/updates/
createrepo --update    /yum_centos7/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 /yum_centos7
if [ $? -eq 0 ];then
	createrepo --update    /yum_centos7/base/
	createrepo --update    /yum_centos7/extras/
	createrepo --update    /yum_centos7/updates/
	createrepo --update    /yum_centos7/epel/
  echo "SUCESS: $DATETIME aliyum_yum update successful"
else
  echo "ERROR: $DATETIME aliyum_yum update failed"
fi


#  crontab -l
# 每月第一个周6的13点更新yum源
00 13 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /mirror/script/centos_yum_update.sh

创建前端nginx

创建运行用户

groupadd nginx
useradd -r -g nginx -s /bin/false -M nginx
yum install nginx -y

修改配置文件

# 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         /yum_centos7 ;           # 这里是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;
        }
    }
}

客户端创建repo文件

# 配置yum源
# vim /etc/yum.repos.d/CentOS7.x-Base.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=http://192.168.1.10/base/
path=/
enabled=1
gpgcheck=0 

[updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=http://192.168.1.10/updates/
path=/
enabled=1
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=http://192.168.1.10/extras/
path=/
enabled=1
gpgcheck=0 

[epel]
name=CentOS-$releasever - epel - mirrors.template.com
baseurl=http://192.168.1.10/epel/
failovermethod=priority
enabled=1
gpgcheck=0


#  刷新缓存
yum clean all
yum makecache


# 查看仓库列表
yum repolist
posted @   itk  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示