linux 搭建局域网yum源

linux 更新yum源 改成阿里云源

第一步本地云换成阿里云源

1、备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/

CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

第二步:更新本地yum
#执行
yum clean all
yum makecache

#获取当前系统有效的repolist
yum repolist

第三步:下载阿里云源所有的包

#进入指定下载目录
reposync -n --repoid=extras --repoid=updates --repoid=base -p /opt/yum/6

安装createrepo软件,用于生成yum仓库的软件
yum install -y createrepo
cd /opt/yum
createrepo ./
或者
creatrepo /opt/yum/6 #将该目录制作成软件仓库

第四步:安装nginx

rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm

修改配置文件

vim /etc/nginx/con.d/default.conf

location /{

#指定实际目录绝对路径;
root /opt/repository;

#开启目录浏览功能;
autoindex on;

#关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_exact_size off;

#开启以服务器本地时区显示文件修改日期
autoindex_localtime on;
}

启动nginx
service nginx restart

第五步,制作epel.repo配置文件,供yum客户端使用。
cd /opt/yum
vim epel_6.repo

#############################

[rhel6]
name=rhel6
##上面挂载共享文件夹的路径
baseurl=http://211.67.XX.XX:81/6/
enabled=1
gpgcheck=0

#############################

客户端将epel_6文件放置在/etc/yum.repos.d/目录下。
wget http://211.67.xx.xx:81/epel_6.repo -O /etc/yum.repos.d/epel_6.repo

更新客户端yum执行
yum clean all
yum makecache
yum repolist

第六步:定时同步yum
设置每天定时更新脚本 update_yum.sh
#!/bin/bash
echo 开始同步centos6
reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 -p /opt/yum/6
echo centos6同步结束
echo 开始同步centos7
reposync -n --repoid=extras7 --repoid=updates7 --repoid=base7 -p /opt/yum/7
echo centos7同步结束
echo 更新元数据开始
createrepo --update /opt/yum/6/
createrepo --update /opt/yum/7/
echo 更新元数据结束

crontab -e 添加定时任务
0 6 * * * /opt/update_yum.sh
crontab -l 查看定时任务
0 6 * * * /opt/update_yum.sh

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

大虾别跑

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

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

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

打赏作者

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

抵扣说明:

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

余额充值