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

2023-10-27

说明:

操作系统:CentOS 6.7

Nginx版本:1.8.0

rsync版本:3.0.6

IP地址和端口:192.168.3.100:8080

目标:同步CentOS镜像站点的内容到此服务器,通过配置http服务器,提供yum服务

一、准备:

1).安装http服务器

使用Nginx服务器提供http服务

请参照Nginx 安装

2).Nginx配置


#vi/usr/local/nginx/conf/nginx.conf



      server {

        listen       8080;

        server_name  localhost;

        root /var/repos/;

        location / {

                autoindexon;

               autoindex_exact_size off;

               autoindex_localtime on;

                 }

                 }

 
#service nginx reload


3).系统目录规划

Centos的Base源目录: /var/repos/centos

Centos的Base源目录: /var/repos/extras

Centos的Base源目录: /var/repos/updates

Centos的epel源目录: /var/repos/epel

4).基础软件包安装

# yum -y install createrepo
# yum -y install rsync


二、安装:

1).创建镜像文件存放目录

  #mkdir -p /var/repos/centos
  #mkdir -p /var/repos/extras
  #mkdir -p /var/repos/updates
  #mkdir -p /var/repos/epel


2).确定以上yum源上游源同步镜像地址

  参考官方源:

  CentOS官方标准源:

      http://mirror.centos.org/centos/6.7/

  中科大yum源:

      rsync://mirrors.ustc.edu.cn/centos/6.7/os/x86_64/Packages/

      rsync://mirrors.ustc.edu.cn/centos/6.7/updates/

      rsync://mirrors.ustc.edu.cn/centos/6.7/extras/x86_64/Packages/

  epel源:

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

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

  中科大epel源:

      rsync://mirrors.ustc.edu.cn/epel/6/x86_64/

  备注:上游yum源必须要支持rsync协议,否则不能使用rsync进行同步(国内的源很多不支持,这里选用中科大yum源)。

列出各个源下面的软件包

# rsync --list-only rsync://rsync.mirrors.ustc.edu.cn/centos/6.7/os/x86_64/Packages/
# rsync --list-only rsync://rsync.mirrors.ustc.edu.cn/centos/6.7/updates/x86_64/Packages/
# rsync --list-only rsync://rsync.mirrors.ustc.edu.cn/centos/6.7/extras/x86_64/Packages/
# rsync --list-only rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64/


3).创建以上yum源同步脚本,并且设定脚本自动执行

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

 
 #cd /var/repos


上传同步脚本到该目录下

#chmod +x rsync_yum.sh

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

4).添加脚本定时执行任务

   #vi /etc/crontab


 #在最后一行添加以下代码

      0 1 * * * root /home/crontab/yum_rsync.sh

  #service crond restart


三、测试:

  

 wKioL1dRL3nS0DlrAAD3N2aM_H4766.png-wh_50

2).执行同步脚本

  #sh  /home/crontab/yum_rsync.sh


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

3).安装createrepo工具,创建yum源的repo配置文件

 

  #yum -y installcreaterepo
  #cd/etc/yum.repos.d/ #进入目录
  #mv /etc/yum.repos.d/CentOS-Base.repoCentOS-Base.repo-bak
  #vi/etc/yum.repos.d/CentOS-Base.repo


        [base]

        name=CentOS-Base(GDS)

        baseurl=http://192.168.3.100/centos

        path=/

        enabled=0

        gpgcheck=0

 

        [updates]

        name=CentOS-Updates(GDS)

        baseurl=http://192.168.3.100/updates

        path=/

        enabled=1

        gpgcheck=0

 

        [extras]

        name=CentOS-Extras(GDS)

        baseurl=http://192.168.3.100/extras

        path=/

        enabled=1

        gpgcheck=0

   

#vi /etc/yum.repos.d/epel.repo


        [epel]

        name=EPEL(GDS)

        baseurl=http://192.168.3.100/epel

        path=/

        enabled=1

        gpgcheck=0

4).测试yum源是否配置正确

a).清除当前yum缓存

   

 #yum clean all


    wKiom1dRLq7ikJkXAAAkhpJZxEk694.png

   列出yum源中可用的软件包

    #yum repolist


    wKioL1dRL8LhrfAdAABlyquCfMk868.png-wh_50

b).使用yum命令安装软件

  测试CentOS-Base源

#yum install php


wKioL1dRL9ri92IsAADH5v0wm00369.png-wh_50

wKiom1dRLufyH7YqAABaniZQPm4424.png-wh_50

  测试epel源

    #yum install nginx


    wKioL1dRMCXDgFibAAESF-WsYIA541.png-wh_50

    wKiom1dRLy-CSe6rAACELhnLcz8725.png-wh_50

至此,搭建CentOS在线yum源镜像服务器完成!


转载于:https://blog.51cto.com/309173854/1785826

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

搭建CentOS在线yum源镜像服务器 的相关文章