Linux系统下yum镜像源环境部署记录

之前介绍了Linux环境下本地yum源配置方法,不过这个是最简单最基础的配置,在yum安装的时候可能有些软件包不够齐全,下面说下完整yun镜像源系统环境部署记录(yum源更新脚本下载地址:https://pan.baidu.com/s/1miMNPgc     提取密码:hq6u):

1)安装nginx,用于yum镜像源访问配置
[[email protected] ~]# yum -y install gcc pcre-devel zlib-devel openssl-devel
[[email protected] ~]# cd /data/software
[[email protected] software]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[[email protected] software]# tar -zvxf nginx-1.12.0.tar.gz
[[email protected] software]# cd nginx-1.12.0

添加www用户,其中-M参数表示不添加用户家目录,-s参数表示指定shell类型
[[email protected] nginx-1.12.0]# useradd www -M -s /sbin/nologin
[[email protected] nginx-1.12.0]# ./configure --prefix=/data/nginx --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
[[email protected] nginx-1.12.0]# make && make install

2)配置nginx
[[email protected] ~]# cat /data/nginx/conf/vhosts/mirrors.conf
server {
    listen 80;
    server_name yum.kevin.com mirrors.kevin.com localhost;
    index index.html index.php index.htm;

    access_log  /data/nginx/logs/access.log main;
    error_log  /data/nginx/logs/error.log;

    location / {
    root /data/mirrors;
    autoindex on;
    autoindex_exact_size  off;
    autoindex_localtime on;
    }

  }

[[email protected] ~]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful
[[email protected] ~]# /data/nginx/sbin/nginx
[[email protected] ~]# lsof -i:80
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   7741 root    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7769  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7770  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7771  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7772  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7773  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7774  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7775  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)
nginx   7776  www    6u  IPv4  28311      0t0  TCP *:http (LISTEN)

3)创建yum源数据目录
[[email protected] ~]# mkdir -p /data/mirrors
[[email protected] ~]# cd /data/mirrors/
[[email protected] mirrors]# mkdir centos  epel  etc  rpmforge
[[email protected] mirrors]# ls
centos  epel  etc  rpmforge  

4)编写yum源下载更新脚本(从mirrors.ustc.edu.cn镜像网站下载和更新)
[[email protected] ~]# cat /data/script/mirrors.sh
#!/bin/bash

#==========================================
# Program   : /bin/update_yum_source.sh
# Info      : 定期同步官方 yum 源到本地
# Version   : 2017.12.10 v1.0
# author    :kevin
# Usage     : 3 3 * * * /bin/bash /data/script/mirrors.sh
#==========================================

Date=`date +%Y%m%d`
LogFile="/data/logs/$Date.log"
ReceiveMail="[email protected]"

RsyncBin="/usr/bin/rsync"
RsyncPerm="-avrt --delete --exclude=debug/  --exclude=isos/ --exclude=SRPMS/ --exclude=ppc/ --delete-excluded"

#============ centos ==============
CentOS_Path="/data/mirrors/centos"
YumSiteList="rsync://mirrors.ustc.edu.cn/centos/"
centosparm="--exclude=2*/ --exclude=3*/ --exclude=4*/ --exclude=5*/"

#============ epel ==============
epelSite="rsync://mirrors.ustc.edu.cn/fedora-epel"
epelLocalPath="/data/mirrors/epel"
epelparm="--include=7/x86_64 --include=7Server/x86_64 --include=6/x86_64 --include=6Server/x86_64"

#============ rpmforge ==============
rpmforgeSite="rsync://apt.sw.be/pub/freshrpms/pub/dag/redhat/"
#rpmforgeSite="rsync://apt.sw.be/redhat/"
rpmforgeLocalPath="/data/mirrors/rpmforge/"
rpmforgeparm="--exclude=ppc/ --exclude=el2.1/ --exclude=el3/ --exclude=el4/ --exclude=el5/"

echo "---- $Date `date +%T` Begin ----" >>$LogFile

# centos
$RsyncBin $RsyncPerm  $centosparm $YumSiteList $CentOS_Path >> $LogFile

# epel
$RsyncBin $RsyncPerm  $epelparm  $epelSite $epelLocalPath >> $LogFile

# rpmforge
$RsyncBin $RsyncPerm  $rpmforgeparm $rpmforgeSite $rpmforgeLocalPath >> $LogFile

echo  "---- $Date `date +%T` End ----" >> $LogFile

#/bin/mail -s "opt001 - update yum source - $Date" $ReceiveMail<$LogFile

以上脚本中需要注意的几点:
--exclude   表示rsync同步的时候,需要排除的目录(具体表现:同步下来的目录里面为空,大小为0)
--include   表示rsync同步的时候,只想同步的目录

由于本案例是部署yum源,用于linux服务器上本地yum方案安装,不需要同步isos镜像(同时也可以节省机器空间资源),所以在同步的时候将isos镜像目录屏蔽

执行同步脚本。这个过程比较长,大概要下载将近180G的内容。需要耐心等待~~
[[email protected] ~]# sh -x /data/script/mirrors.sh 

[[email protected] ~]# du -sh /data/mirrors/*
93G   /data/mirrors/centos
80G   /data/mirrors/epel
4.0K  /data/mirrors/etc
4.0K  /data/mirrors/rpmforge
410M  /data/mirrors/software

[[email protected] ~]# ls /data/mirrors/centos/
2    3.6  6.0  6.6       7.1.1503   dostools          RPM-GPG-KEY-CentOS-3  RPM-GPG-KEY-CentOS-Debug-6     timestamp.txt
3    3.7  6.1  6.7       7.2.1511   filelist.gz       RPM-GPG-KEY-centos4   RPM-GPG-KEY-CentOS-Debug-7
3.1  3.8  6.2  6.8       7.3.1611   graphics          RPM-GPG-KEY-CentOS-4  RPM-GPG-KEY-CentOS-Security-6
3.3  4    6.3  6.9       7.4.1708   HEADER.html       RPM-GPG-KEY-CentOS-5  RPM-GPG-KEY-CentOS-Testing-6
3.4  5    6.4  7         build      HEADER.images     RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Testing-7
3.5  6    6.5  7.0.1406  dir_sizes  RPM-GPG-KEY-beta  RPM-GPG-KEY-CentOS-7  TIME
[[email protected] ~]# ls /data/mirrors/epel/
4    5Client  7Server                           fullfilelist.KDUVzc9WPK           RPM-GPG-KEY-EPEL-4        RPM-GPG-KEY-EPEL-7Server
4AS  5Server  epel-release-latest-6.noarch.rpm  fullfiletimelist-epel             RPM-GPG-KEY-EPEL-5        testing
4ES  6        epel-release-latest-7.noarch.rpm  fullfiletimelist-epel.WaO7KUHvYz  RPM-GPG-KEY-EPEL-6
4WS  6Server  fullfilelist                      imagelist-epel                    RPM-GPG-KEY-EPEL-6Server
5    7        fullfilelist.AwiES3LjSB           RPM-GPG-KEY-EPEL                  RPM-GPG-KEY-EPEL-7

5)替换linux本机的yum源地址
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Vault.repo
[[email protected] yum.repos.d]# mkdir bak
[[email protected] yum.repos.d]# mv *.repo bak/
[[email protected] yum.repos.d]# ls
bak

编写yum源文件
[[email protected] yum.repos.d]# cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirrors system uses the connecting IP address of the client and the
# update status of each mirrors to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrorss.
#
# If the mirrorslist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-CentOS-$releasever - Base
#mirrorslist=http://mirrorlist.centos.org/?release=CentOS-$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirrors.kevin.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

#released updates
[updates]
name=CentOS-CentOS-$releasever - Updates
#mirrorslist=http://mirrorlist.centos.org/?release=CentOS-$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://mirrors.kevin.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

#additional packages that may be useful
[extras]
name=CentOS-CentOS-$releasever - Extras
#mirrorslist=http://mirrorlist.centos.org/?release=CentOS-$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://mirrors.kevin.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-CentOS-$releasever - Plus
#mirrorslist=http://mirrorlist.centos.org/?release=CentOS-$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://mirrors.kevin.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

#contrib - packages by Centos Users
[contrib]
name=CentOS-CentOS-$releasever - Contrib
#mirrorslist=http://mirrorlist.centos.org/?release=CentOS-$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=http://mirrors.kevin.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

[[email protected] yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://mirrors.kevin.com/epel/$releasever/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://mirrors.kevin.com/epel/$releasever/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://mirrors.kevin.com/epel/$releasever/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=http://mirrors.kevin.com/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1

[[email protected] yum.repos.d]# yum clean all
[[email protected] yum.repos.d]# yum makecache

其他服务器要是想用本yum源,就按照上面操作,将/etc/yum.repos.d目录下的repo文件都移除,然后将上面编写的两个文件放进去,执行yum clean all和yum makecache即可!

============================================================================
温馨提示:以上的yum源配置及两个yum文件在centos6和centos7系统下都适用!已经验证!!

============================================================================
更新以上yum源的脚本:
可以将上面两个文件放到http://mirrors.kevin.com/software里面,用于脚本中下载
[[email protected] ~]# cd /data/mirrors/software/
[[email protected] software]# ls
yum_reset.sh        CentOS-Base.repo            epel.repo                       

[[email protected] software]# cat yum_reset.sh
#!/bin/bash
cd /etc/yum.repos.d/
/bin/mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
wget http://mirrors.kevin.com/software/CentOS-Base.repo
wget http://mirrors.kevin.com/software/epel.repo
/usr/bin/yum clean all
/usr/bin/yum makecache

只需要将上面的yum_reset.sh脚本下载到目标服务器上,然后执行,就可以将目标服务器的yum源更新了。
# wget http://mirrors.kevin.com/software/yum_reset.sh
# sh -x yum_reset.sh

可以定期更新以上的yum源同步脚本(mirros.sh),比如每月更新一次

[[email protected] ~]# crontab -e
#每个月1号的23:00点同步一次yum源
0 23 1 * * /bin/bash -x /data/script/mirrors.sh > /dev/null 2>&1

时间: 12-12

Linux系统下yum镜像源环境部署记录的相关文章

linux系统下的web项目的部署

本文所用到的所有软件都已传至百度云盘,需要用的可自行下载安装.链接:https://pan.baidu.com/s/1dplyekS1ZExzvaHHdiOX0Q 密码:fo4q 在这里作者演示的是使用虚拟机上安装的linux系统的项目部署,云服务器上的web项目部署类似 前期准备: 首先,在自己电脑上装虚拟机软件,我使用的是VMware Workstation,然后在虚拟机上安装linux系统,我使用的是Cent OS, 安装完linux系统后配置其ip地址,这里介绍两种配置linux系统下配

linux系统下yum源的搭建

1.建立挂载点 系统默认在 /mnt目录 1>创建挂载点 mkdir -p /mnt/cdrom   参数-p是需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理 2>查看光盘完整路径名.ls -l /dev|grep cdrom 3>挂载mount /dev/cdrom /mnt/cdrom  这个挂载不具有永久性,但是是常用的方法. 永久性挂载: vi /etc/fstab           加入  /dev/sdb/ /mnt/cdrom ext3  defaul

Linux系统下安装jdk及环境配置(两种方法)

在windows系统安装jdk以及环境配置,相信大家都会,这里就不做赘述了,本人菜鸟一枚,今天复习了在linux下安装jdk后,特此做了个总结,这里主要分享下linux下的jdk安装以及环境配置. 下面是linux下安装jdk的两种方式: 第一种属于傻瓜式安装,一键安装即可(yum安装): 第二种手动安装,需要自己去Oracle官网下载需要的jdk版本, https://www.oracle.com/java/technologies/javase-jsp-downloads.html 然后解压

linux系统下yum仓库的建立与目录共享的建立(脚本文件)

vim yum.sh                                                                     ##建立脚本文件 *!/bin/bash#################creat local yum source############mkdir  /westos                                                                 ##建立挂载点mount /iso/rhe

windows系统下,gpu开发环境部署

1,安装python,使用anaconda或者直接用python.exe安装都可以.我用的是python3.6版的 对于相关的程序包,比如tensorflow或者opencv等,anaconda可以在管理页面自己下载安装,二自己安装python的,需要自己用pip安装 2,安装cuda,使用版本是9.2 双击下载的exe安装包.https://developer.nvidia.com/cuda-downloads链接 选择自定义安装,然后把Visual Studio选项去掉, 然后一通操作,就安

linux系统下安装Python环境

如何在Linux系统下搭建Python开发环境(http://www.maiziedu.com/course/python/)?Python在Linux系统中安装方法在Windows下是有很大的区别的,今天就具体记录一下关于 Python 环境软件包在Linux系统下的一些安装步骤 1.升级 Python 到 2.7.10( 默认 2.6.6 ) shell > yum -y install epel-release shell > yum -y install gcc wget readli

VMware(一):Windows系统给虚拟机系统共享文件、虚拟机里Linux系统挂载共享文件镜像做yum源

一.Windows系统给虚拟机系统共享文件 目标: 环境:PC机为Windows系统,安装了虚拟机VMware12版本,在虚拟机里安装Linux系统Redhat7.2. 目的:实现Windows系统里面的文件可共享给虚拟机里面Linux操作系统的目标 方案: 1> 在Windows系统里面选择一个将要作为共享的磁盘位置 2> 在该磁盘里创建一个提供共享的文件目录 3> 设定该目录共享以及共享权限 4> 虚拟机里设定是共享目录总是可见 步骤: 一.物理机上面的共享操作的设置 1. 在

Linux系统下Jsp环境部署

-------本文大纲 简介 Jsp环境部署 Tomcat目录结构 SHOP++网上商城系统安装 --------------- 一.简介 JSP JSP(Java Server Pages)是由Sun Microsystems公司倡导.许多公司参与一起建立的一种动态网页技术标准.在传统的网页HTML文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件(*.jsp).简单地说,jsp就是可能包含了java程序段的html文件(由ja

linux系统下部署TOMCAT异常:java.net.UnknownHostException

原文出自:http://www.myexception.cn/operating-system/444024.html linux系统下部署TOMCAT错误:java.net.UnknownHostException今天在修改linux环境中 /etc/hosts文件时候,保存之后,访问页面的时候突然这个错,后来网上查了下,解决了java.net.UnknownHostException: vps**: vps**        at java.net.InetAddress.getLocalH