yum源仓库搭建
系统:centos7
一、安装nginx
yum install -y nginx
yum install -y createrepo 安装建yum源仓库的工具,可以用来建立yum仓库
yum install -y yum-plugin-priorities 安装控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。
二、配置nginx
/etc/nginx/nginx.conf
server{
listen ;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
默认index路径/usr/share/nginx/html
那么在html下面建立以下目录:
mkdir -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_6./64bit/
mkdir -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_7./64bit/
mkdir -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6./64bit/
mkdir -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7./64bit/
且不要忘记给目录增加可读和可执行权限,否则在web页面显示不出来。
chmod -R +x /usr/share/nginx/html/
在web的index.html首页里面添加指向文件目录的超链接:
<p style="font-weight:bolder;color:green;font-size:30px;">ALL of the packages in the below:</p>
<br/>
<a href="http://159.138.1.77/CentOS-YUM/Aliyun">Aliyun</a><br/>
These packagers from of CentOS ISO.<br/>
<a href="http://159.138.1.77/CentOS-YUM/CentOS">CentOS</a><br/>
These packagers from of "Internet service provider".<br/>
<p style="font-weight:bolder;color:red;font-size:18px;">Please replace the file and fill in the following content:</p>
<p style="font-weight:bolder;color:blue;font-size:15px;">Way: /etc/yum.repos.d/CentOS-Base.repo</p>
重启nginx
systemctl restart nginx
三、修改当前系统yum来源repo文件
1.首先对此文件进行备份
cp -p /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2.接下来去阿里云的官方网站下载阿里云的CentOS-Base.repo文件,如下所示:
mkdir -p /etc/yum.repos.d/Aliyun
wget -O /etc/yum.repos.d/Aliyun/CentOS-6.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/Aliyun/CentOS-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
四、进行同步脚本的创建并执行同步
vim /etc/yum.repos.d/yum.reposync.sh
#!/bin/bash
reposync -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_7./64bit/
/usr/bin/sed -i "s/7/6/g" `grep -rl /etc/yum.repos.d/CentOS-Base.repo`
reposync -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_6./64bit/
cat /etc/yum.repos.d/Aliyun/CentOS-.repo > /etc/yum.repos.d/CentOS-Base.repo
reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6./64bit/
/usr/bin/sed -i "s/6/7/g" `grep -rl /etc/yum.repos.d/CentOS-Base.repo`
reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7./64bit/
cat /etc/yum.repos.d/CentOS-Base.repo.bak > /etc/yum.repos.d/CentOS-Base.repo
chmod +x /etc/yum.repos.d/yum.reposync.sh
然后执行脚本
sh /etc/yum.repos.d/yum.reposync.sh
createrepo -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_6./64bit/base/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/CentOS/version_7./64bit/base/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6./64bit/base/Packages
createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7./64bit/base/Packages
当yum源仓库建立好以后,会在对应的目录下面出现“repodata”的目录。如下图所示:

五、客户端Client的yum配置:
1、安装优先级软件:
yum install -y yum-plugin-priorities
2.首先对client端的/etc/yum.repos.d/目录下的repo文件进行更改。
mkdir –p /etc/yum.repos.d/back
mv /etc/yum.repos.d/* /etc/yum.repos.d/back/
vim /etc/yum.repos.d/CentOS-Base.repo
[mylocal]
name=source_from_localserver #这里是整合到server端的centos6的光盘镜像yum源
baseurl=http://http://159.138.1.77/centos/6.6/x86_64/Packagers/
gpgcheck=
enable=
priority= #这里的priority就是上面安装的优先级工具,设定从小到大 [Aliyun_6.6_base]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/Aliyun/version_6.6/64bit/base/Packages
gpgcheck=
enable=
priority= [Centos_6.6_base]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/CentOS/version_6.6/64bit/base/Packages
gpgcheck=
enable=
priority= [Aliyun_6.6_extras]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/Aliyun/version_6.6/64bit/extras/Packages
gpgcheck=
enable=
priority= [Centos_6.6_extras]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/CentOS/version_6.6/64bit/extras/Packages
gpgcheck=
enable=
priority= [Aliyun_6.6_updates]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/Aliyun/version_6.6/64bit/updates/Packages
gpgcheck=
enable=
priority= [Centos_6.6_updates]
name=source_from_localserver
baseurl=http://159.138.1.77/CentOS-YUM/CentOS/version_6.6/64bit/updates/Packages
gpgcheck=
enable=
priority=
---------------------
3.然后进行本利的缓存的清理和建立
yum clean all
yum makecache
yum repolist
当缓存建立好以后,就可以在client端直接使用yum进行安装软件包了。而检索的顺序就是根据优先级来的。

六、配置server端的yum源自动更新机制
1.首先来写一个bash脚本在/home/crontab/下,这个脚本的作用说白了就是通过一条一条自动执行,最终达到,自动更新yum源的目的,代码如下:
vim /home/crontab/oderforrepo.sh
#!bin/bash
/usr/bin/reposync -np /usr/share/nginx/html/CentOS-YUM/CentOS/version_7./64bit/
/usr/bin/sed -i "s/7/6/g" `grep -rl /etc/yum.repos.d/CentOS-Base.repo`
/usr/bin/reposync -np /usr/share/nginx/html/CentOS-YUM/CentOS/version_6./64bit/
cat /etc/yum.repos.d/CentOS-Base.aliyun.repo.bak > /etc/yum.repos.d/CentOS-Base.repo
/usr/bin/reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6./64bit/
/usr/bin/sed -i "s/6/7/g" `grep -rl /etc/yum.repos.d/CentOS-Base.repo`
/usr/bin/reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7./64bit/
cat /etc/yum.repos.d/CentOS-Base.repo.bak > /etc/yum.repos.d/CentOS-Base.repo
“-np”的意思为仅仅更新新更新的软件到指定目录
其他的跟第四步的语句是一个意思。
2、然后再来添加定时计划:
vim /etc/crontab
* * rootrun-parts /home/crontab/oderforrepo.sh
这个定时任务表示:每周6的晚上凌晨2点开始执行oderforrepo.sh的脚本.
这样就可以自动更新yum源了。
最后记得查看本地系统的系统时间,如果觉得有必要可以将时间同步。
参考:https://blog.csdn.net/u012402276/article/details/53158682
yum源仓库搭建的更多相关文章
- yum源仓库的三种搭建方式
yum源的三种搭建方式 一. 本地yum仓库的搭建 1.1.获取软件包资源 将iso镜像挂载在本地目录中,此次挂载目录为/var/www/html/repo/,此目录本身不存在,需要创建.软件宝资源 ...
- 在linux上搭建本地yum源
准备yum仓库的光盘镜像IOS文件: 设置光驱加载本地磁盘的yum仓库的光盘镜像文件: 在linux的命令行输入setup命令打开设置窗口,选择"System Service": ...
- 【程序包管理】Linux程序包管理之yum源安装
yum源安装是我们工作中常用的一种方式,它是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RP ...
- 配置 EPEL yum 源
当我们在linux上, 使用yum 安装包时,报错如下: Loaded plugins: product-id, refresh-packagekit, security, subscription- ...
- (转载)centos yum源的配置和使用
原文地址:http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html 一.yum 简介 yum,是Yellow dog Updater, ...
- 阿里云yum源安装
1.先清理掉yum.repos.d下面的所有repo文件 [root@localhost yum.repos.d]# rm -rf * 2.下载repo文件 wget http://mirror ...
- centos本地yum源安装
1.为DVD或U盘创建一个用于挂载的目录 [root@localhost ~]# mkdir /media/CentOS/ 2.查看DVD或U盘所在的路径 [root@localhost ~]# fd ...
- CentOS yum 源的配置与使用
一.yum 简介 yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器.起初是由yellow dog 这一发行版的 ...
- Linux下更换默认yum源为网易yum源的操作记录
废话不多说,下面记录了centos下更换系统默认yum源为网易yum源的操作过程:1)备份原有的默认yum源[root@bastion-IDC ~]# cp /etc/yum.repos.d/Cent ...
随机推荐
- (zhuan) Building Convolutional Neural Networks with Tensorflow
Ahmet Taspinar Home About Contact Building Convolutional Neural Networks with Tensorflow Posted on a ...
- [POJ 3984] 迷宫问题(BFS最短路径的记录和打印问题)
题目链接:http://poj.org/problem?id=3984 宽度优先搜索最短路径的记录和打印问题 #include<iostream> #include<queue> ...
- Kylin简介
来源 Cube: 用空间换时间(类似:BI分析) 预计算把用户需要查询的维度以及他们所对应的考量的值,存储在多维空间里 当用户查询某几个维度的时候,通过这些维度条件去定位到预计算的向量空间,通过再聚合 ...
- 【译】第22节---Fluent API - EntityTypeConfiguration类
原文:http://www.entityframeworktutorial.net/code-first/entitytypeconfiguration-class.aspx 在我们开始使用Fluen ...
- Lintcode241-String to Integer - Naive
Given a string, convert it to an integer. You may assume the string is a valid integer number that c ...
- window7安装python的xgboost库方法
window7安装python的xgboost库方法 1.下载xgboost-master.zip文件,而不是xgboost-0.4a30.tar.gz,xgboost-0.4a30.tar.gz是更 ...
- spring读取bean有几种方式
bean加载到spring的方式: 第一种:xml 第二种:注释「一定要配合包扫描」: <context:component-scan base-package="Cristin.Co ...
- 理解 Redis(4) - 关于 string 的更多命令(SETEX, SETNX, INCR, DECR, MSET...)
上一节介绍了关于字符串值的一些基本命令, 这一节将介绍一些进阶命令: 清理终端: 127.0.0.1:6379> clear 设置一个键值对, 同时设置过期时间为10秒: 127.0.0.1:6 ...
- 【BZOJ】3143: [Hnoi2013]游走
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3143 显然如果一条边期望被走过的次数越多,我们就应该给它的编号越小. 所以问题变为如何求每 ...
- STL——map
看到map这里,都不知道它主要是干嘛的,你有没有这样的疑问. map的主要作用:提供对T类型的数据进行快速和高效的检索 .C++ STL中标准关联容器set, multiset, map, multi ...
