Centos7下自建yum源并同步阿里云镜像的rpm包

一、安装相关软件
yum install -y wget make cmake gcc gcc-c++  &&\
yum install -y pcre-devel lib zlib-devel  \
    openssl openssl-devel createrepo yum-util
二、编译安装nginx
相关文章查看 Centos7下nginx-1.12.2编辑安装与脚本安装的记录
三、创建索引
mkdir /opt/yum/centos/7/os/x86_64/
createrepo /opt/yum/centos/7/os/x86_64/
四、配置nginx
server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /opt/yum/centos/7/os/x86_64/;  ##这里

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
               ##这里
               autoindex on;
               autoindex_exact_size off;
               autoindex_localtime on;
               index index.html;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
五、同步相关包
1、设置阿里云镜像为本地yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2、选择指定仓库标识作为本地yum源:
yum repolist查看yum仓库标识
3、将阿里云中的epel源同步到本地/opt/yum/centos/7/os/中;第一次同步是时间可能较长,我这里有9911个rpm包。
reposync -r base -p /opt/yum/centos/7/os/
脚本自动更新
vi /root/yum-update.sh
#!/bin/bash
datetime=`date +"%Y-%m-%d"`
exec > /var/log/centosrepo.log
reposync -d -r base -p /opt/yum/centos/7/os/
#同步镜像源
if [ $? -eq 0 ];then
    createrepo --update  /opt/yum/centos/7/os/x86_64
    #每次添加新的rpm时,必须更新索引信息
echo "SUCESS: $datetime epel update successful"
else
echo "ERROR: $datetime epel update failed"
fi

定时任务:每周二凌晨三点同步yum源
crontab -e
0 2 * * 3 /bin/bash /root/yum-update.sh
4、更新索引
createrepo --update /opt/yum/centos/7/os/x86_64/
5、清理缓存数据
yum clean all && yum makecache
6、编写repo文件
vim /etc/yum.repos.d/feiyu-7.repo内容如下
[feiyu]
name=centos-feiyu
baseurl=http://192.168.0.27/centos/releasever/os/basearch/
enabled=1
gpgcheck=0
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菲宇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值