centos7内网源站建设

centos7内网源站建设

1、部署环境:

系统:Centos7 x86_64

应用服务:nginx、createrepo、reposync

镜像源:https://mirrors.aliyun.com/repo/epel-7.repo

2、现在阿里云镜像源repo文件到本地:

[root@localhost ~] wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

3、安装nginx服务,用于提供存放yum源:

[root@localhost ~] yum -y install nginx

4、安装yum-utilscreaterepo提供reporsync服务和创建repo索引目录功能:

[root@localhost ~] yum -y install yum-utils createrepo

5、同步源

[root@localhost ~]# reposync -r epel -p /software/centos7yum/epel

(base,extra,updates同理)

6createrepo 命令创对/software/centos7yum/epel下的 rpm 创建为本地的 YUM 仓库,目的是为生成repodata目录并自动创建索引信息

[root@localhost ~]# createrepo -pdo /software/centos7yum/epel /software/centos7yum/epel  #第一个目录是repodata存放目录,第二个目录是需要生成索引信息yum源仓库目录

(base,extra,updates同理)

7、验证本地yum源是否能正常使用:

vim /etc/yum.repos.d/epel-7.repo内容如下

[epel]

name=local epel

baseurl=http://yum源服务器IP/epel

enabled=1

gpgcheck=0

备份其他repo文件至/etc/yum.repos.d/repobak目录下,以防影响测试:

8、执行yum clean allyum makecache

9、为保证本地yum源能和阿里云镜像源同步,可以通过脚本定时任务实现(如果跳板机子可以出外网的话,不行的话就没法子了):

vim /root/yum-update.sh

  1. #!/bin/bash
  2.  
  3. datetime=`date +"%Y-%m-%d"`
  4. exec > /var/log/epel.log  #同步日志输出
  5. reposync -d -r epel -p /var/www/html/    #同步镜像源
  6. if [ $? -eq 0 ];then
  7.     createrepo --update  /var/www/html/epel   #每次添加新的rpm时,必须更新epel索引信息
  8.     echo "SUCESS: $datetime epel update successful"else
  9.     echo "ERROR: $datetime epel update failed"fi

10.#定时任务:每周六凌晨三点同步yum源

11.crontab -e

12.3 * * 6 /bin/bash /root/yum-update.sh

猜你喜欢

转载自www.cnblogs.com/fatyao/p/10206822.html
今日推荐