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