搭建私有yum源仓库同步阿里云yum源到本地私有yum仓库

本地私有仓库搭建步骤:
1.安装nginx

2.在本机配置阿里云yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

##这里将阿里的第三方epel源一起进行配置

3.同步公网镜像到本地私有仓库
用repoync 命令,Reposync用于将远程yum存储库同步到本地存储库

reposync -np  /data/centos/7/base/     
##这里同步的源文件就是上一步配置的yum源,/data/centos/7/base/ 为生成的本地yum仓库文件即rpm包所在路径

reposync
-n:只下载最新的包
-p:下载包的路径:默认为当前目录

4.将yum仓库文件即rpm包所在路径设置为 nginx发布目录

server {
    listen       80;
    server_name  mirrors.aaaa.com;
    root         /data/centos/7/base/;   #这里是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;
    }   
}

5.设置定时同步任务
定时脚本:yum_update.sh

#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/aliyumrepo_$DATETIME.log
     reposync -np /data/centos/7/base
if [ $? -eq 0 ];then
      createrepo --update /data/centos/7/base/base
      createrepo --update /data/centos/7/base/extras
      createrepo --update /data/centos/7/base/updates
      createrepo --update /data/centos/7/base/epel
    echo "SUCESS: $DATETIME aliyum_yum update successful" >>/var/log/aliyumrepo_$DATETIME.log
  else
    echo "ERROR: $DATETIME aliyum_yum update failed" >> /var/log/aliyumrepo_$DATETIME.log
fi

添加定时任务:

0 3 * * 1  /bin/sh  /data/crond/yum_update.sh

##每周一凌晨三点执行

##参考:
https://blog.csdn.net/moyuanbomo/article/details/81667006
https://www.cnblogs.com/lldsn/p/10479493.html

  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
您好!要基于Nginx搭建私有yum源,可以按照以下步骤进行操作: 1. 首先,确保您的服务器上已经安装了Nginx。可以使用以下命令进行安装: ``` sudo apt-get update sudo apt-get install nginx ``` 2. 创建一个目录用于存放yum仓库的文件。可以使用以下命令创建目录: ``` sudo mkdir -p /var/www/html/yumrepo ``` 3. 将您的yum仓库文件复制到该目录下。您可以通过将本地的yum仓库文件上传到服务器,或者直接使用rsync等命令将其复制到目标目录。 4. 配置Nginx以提供访问私有yum源。打开Nginx的配置文件(通常位于/etc/nginx/nginx.conf)并进行相应的修改,添加以下配置: ``` server { listen 80; server_name localhost; location / { root /var/www/html/yumrepo; autoindex on; autoindex_exact_size off; autoindex_localtime on; } } ``` 5. 保存并关闭配置文件,然后重新启动Nginx服务: ``` sudo systemctl restart nginx ``` 6. 现在,您可以在客户端机器上通过访问服务器的IP地址或域名来使用私有yum源了。例如,可以使用以下命令添加私有yum源: ``` sudo vi /etc/yum.repos.d/private.repo ``` 在该文件中添加以下内容: ``` [private] name=Private Yum Repo baseurl=http://<nginx服务器的IP地址或域名>/ enabled=1 gpgcheck=0 ``` 保存并关闭该文件。 现在,您就成功地基于Nginx搭建私有yum源。您可以使用客户端机器上的yum命令来安装、更新或删除软件包了。 希望对您有帮助!如有任何疑问,请随时提问。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值