搭建CentOS在线yum源镜像服务器

本文详细介绍了如何在CentOS系统上搭建Nginx服务器,提供yum服务。首先安装Nginx并配置目录浏览功能,然后创建不同yum源的镜像文件目录,如CentOS官方、rpmforge和epel。接着通过rsync同步上游源,并创建定时任务自动执行同步。最后,根据不同的CentOS版本创建相应的repo配置文件,测试yum源是否配置正确,完成服务器搭建。
摘要由CSDN通过智能技术生成

并且通过配置http服务器,能够向外提供yum服务

准备篇:

一、安装http服务器

这里使用Nginx服务器提供http服务

关于Nginx服务器搭建,参考:CentOS安装配置LNMP服务器(Nginx+PHP+MySQL)

http://www.osyunwei.com/archives/5910.html

二、系统约定

Nginx站点根目录:/usr/local/nginx/html

服务器执行脚本文件存放目录:/home/crontab

三、开始Nginx目录浏览功能

vi /usr/local/nginx/conf/nginx.conf #编辑配置文件,在http {下面添加以下内容:

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

autoindex_exact_size off; #文件大小从KB开始显示

autoindex_localtime on; #显示文件修改时间为服务器本地时间

:wq! #保存,退出

service nginx reload #重新加载配置

参考:Nginx开启目录浏览功能

http://www.osyunwei.com/archives/5051.html

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链

安装篇:

一、创建镜像文件存放目录

mkdir -p /usr/local/nginx/html/centos #CentOS官方标准源

mkdir -p /usr/local/nginx/html/repoforge #第三方rpmforge源

mkdir -p /usr/local/nginx/html/epel #第三方epel源

说明:这里创建三个文件夹,分别存放CentOS官方标准源、第三方的rpmforge源和epel

二、确定以上三个yum源上游源的同步镜像地址

1、CentOS官方标准源:rsync://mirrors.ustc.edu.cn/centos/

2、rpmforge源:rsync://mirrors.ispros.com.bd/repoforge/

3、epel源:rsync://mirrors.ustc.edu.cn/epel/

备注:上游yum源必须要支持rsync协议,否则不能使用rsync进行同步。

参考:

CentOS官方标准源:

rsync://mirrors.kernel.org/centos

rpmforge源:

http://apt.sw.be/

rsync://ftp-stud.fht-esslingen.de/dag

epel源:

http://mirrors.fedoraproject.org/publiclist/EPEL/

rsync://mirrors.kernel.org/fedora-epel

三、创建以上三个yum源同步脚本,并且设定脚本自动执行

mkdir -p /home/crontab #创建目录

vi /home/crontab/yum_rsync.sh #添加以下代码

#!/bin/sh

/usr/bin/rsync -avrt rsync://mirrors.ustc.edu.cn/centos/ --exclude-from=/usr/local/nginx/html/exclude_centos.list /usr/local/nginx/html/centos/

/usr/bin/rsync -avrt rsync://mirrors.ispros.com.bd/repoforge/ --exclude-from=/usr/local/nginx/html/exclude_repoforge.list /usr/local/nginx/html/repoforge/

/usr/bin/rsync -avrt rsync://mirrors.ustc.edu.cn/epel/ --exclude-from=/usr/local/nginx/html/exclude_epel.list /usr/local/nginx/html/epel/

:wq! #保存退出

chmod +x /home/crontab/yum_rsync.sh #添加脚本执行权限

备注:运行此脚本前,先要创建好同步目录及不需要同步的目录列表文件

cd /usr/local/nginx/html/   #进入目录

touch exclude_centos.list   #创建文件

touch exclude_repoforge.list   #创建文件

touch exclude_epel.list   #创建文件

把不需要同步的目录写到上面对应的文件中,每行一个目录

例如:

vi exclude_epel.list

4/

4AS/

4ES/

4WS/

:wq! #保存退出

四、添加脚本定时执行任务

vi /etc/crontab  #在最后一行添加以下代码

0 1 * * * root /home/crontab/yum_rsync.sh #设置每天凌晨1点整开始执行脚本

:wq! #保存退出

service crond restart #重启

测试篇:

一、安装rsync同步软件

yum install rsync xinetd #安装

vi /etc/xinetd.d/rsync #编辑配置文件,设置开机启动rsync

disable = no #修改为

/etc/init.d/xinetd start #启动(CentOS中是以xinetd 来管理Rsync服务的)

:wq! #保存退出

二、执行同步脚本

sh /home/crontab/yum_rsync.sh

注意:等待脚本执行完毕,首次同步,耗费的时间比较长!

三、根据不同版本创建三个yum源的repo配置文件

cd /etc/yum.repos.d/ #进入目录

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

1、CentOS官方标准源:

CentOS 5.x系列:

vi /etc/yum.repos.d/CentOS-Base.repo #添加以下代码

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值